Fix chrF dropping the reference n-grams of a zero-scoring sentence - #3481
Open
Kayvan-Zahiri wants to merge 1 commit into
Open
Fix chrF dropping the reference n-grams of a zero-scoring sentence#3481Kayvan-Zahiri wants to merge 1 commit into
Kayvan-Zahiri wants to merge 1 commit into
Conversation
`_calculate_sentence_level_chrf_score` starts `best_f_score` at 0.0 and only records a reference under `if f_score > best_f_score`. A hypothesis that shares no character or word n-gram with any of its references scores exactly 0.0, so the guard never fires and the function returns the zero-filled defaults. `_chrf_score_update` then adds those zeros to the corpus reference totals while still adding the hypothesis n-grams, so the sentence drops out of the corpus recall denominator and the corpus score is inflated. Keep the first reference unconditionally, which is what sacrebleu does with its `best_f_score = -1.0` sentinel.
Kayvan-Zahiri
requested review from
SkafteNicki and
justusschock
as code owners
August 28, 2026 18:15
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.
What does this PR do?
Fixes #3480
_calculate_sentence_level_chrf_scorestartsbest_f_scoreattensor(0.0)and only records a reference underif f_score > best_f_score. A hypothesis that shares no character or word n-gram with any of its references scores exactly0.0, so the guard never fires and the function returns its zero-filled defaults._chrf_score_updatethen adds those zeros to the corpus reference totals while still adding the hypothesis n-grams, so the sentence drops out of the recall denominator and the corpus score is inflated. On the example in the issue that is 0.7080 against sacrebleu's 0.4217, and it makes the metric non-monotonic: garbage can outscore a partly correct translation.The fix keeps the first reference unconditionally, which is what sacrebleu does with its
best_f_score = -1.0sentinel. A better-scoring later reference still wins, so multi-reference behavior is unchanged.Two tests, both verified to fail on
master: one checks the corpus score against_reference_sacrebleu_chrf, the other checks that degrading a hypothesis cannot raise the score.Before submitting
PR review
Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.
Did you have fun?
Chasing a metric that rewards worse translations was a good one, yes.