From 741addd6fae16907a10434a6dc06534dd3b7f8e3 Mon Sep 17 00:00:00 2001 From: "S.P. Mohanty" <spmohanty91@gmail.com> Date: Mon, 18 Mar 2024 03:11:41 +0000 Subject: [PATCH] Load sacrebleu on first use --- metrics.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/metrics.py b/metrics.py index a2f24c9..df402c3 100644 --- a/metrics.py +++ b/metrics.py @@ -5,8 +5,7 @@ import evaluate from typing import List -print("\nsacrebleu loading...") -sacrebleu = evaluate.load("sacrebleu") +sacrebleu = None def accuracy(prediction: int, truth: int): @@ -107,6 +106,11 @@ def ndcg_eval(relevance_scores: List[float], truth: List[float]): def bleu(generation, truth, jp=False): + global sacrebleu + if sacrebleu is None: + print("\nsacrebleu loading...") + sacrebleu = evaluate.load("sacrebleu") + generation = generation.lstrip("\n").rstrip("\n").split("\n")[0] candidate = [generation] reference = [[truth]] -- GitLab