fix: transpose references before passing to sacrebleu in CorpusLevelTranslationMetric#1234
Open
jaydenC88 wants to merge 1 commit into
Open
Conversation
…ranslationMetric sacrebleu expects references in [ref_id][sent_id] shape, but compute_corpus() was collecting golds as [sent_id][ref_id]. This caused sacrebleu's internal zip(*references) to transpose the already-per-sample list, resulting in only the first hypothesis being scored against a pooled set of all references. Fixed by transposing golds with zip_longest(*golds) before calling corpus_score(), so each inner list is one reference stream across all hypotheses. Also removes the special-case BLEU branch (gold[0]-only), allowing BLEU to benefit from multi-reference inputs the same way. Updated chrf, chrf++, and TER test fixtures to reflect the now-correct scores. Fixes huggingface#1112 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1112
CorpusLevelTranslationMetric.compute_corpus()was passingreferencesto sacrebleu in the wrong shape. References were collected as[sent_id][ref_id], but sacrebleu'scorpus_scoreexpects[ref_id][sent_id]. Because sacrebleu internally doeszip(*references)to transpose the streams, the wrong orientation meant only the first hypothesis was ever scored — matched against all references from all sentences pooled together — causing inflated scores (e.g.100.0for a half-correct corpus).Changes:
src/lighteval/metrics/metrics_corpus.py: addfrom itertools import zip_longestand replace the per-metric special-case logic with a singlezip_longest(*golds)transpose applied uniformly beforecorpus_score(). This fixes chrF, chrF++, and TER, and also lets BLEU use all available references instead of silently dropping togold[0].tests/unit/metrics/test_cases/chrf.json,chrf_plus.json,ter.json: update expected values that were computed with the buggy code.Reproducer (from issue)
Test plan
len(stats) == len(hypotheses)after fixpytest tests/unit/metrics/test_automated_metrics_pytest.py -k "chrf or ter or bleu")