Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, metric: str,
return_score: bool = False) -> None:
if metric == C.RERANK_BLEU:
self.scoring_function = sacrebleu.sentence_bleu
elif metric == C.RERANK_CHRF:
self.scoring_function = sacrebleu.sentence_chrf
else:
raise utils.SockeyeError("Scoring metric '%s' unknown. Choices are: %s" % (metric, C.RERANK_METRICS))
self.return_score = return_score
def score_sentence(self, hyp, ref, lang=None):
return sacrebleu.sentence_chrf(hyp, ref)
def _get_sent_chrf(
hypothesis: List[str], references: List[List[str]],
extra_args: Optional[Dict[str, str]] = None
):
return [
sb.sentence_chrf(h, r).score for h, r in zip(hypothesis, references[0])
]