Repository navigation
Fix BLEU brevity penalty with multiple references (use the closest reference length) - #892
0xrichardlu wants to merge 2 commits into
Conversation
compute_bleu from tensorflow/nmt uses the shortest reference as the effective reference length. BLEU (Papineni et al., 2002), multi-bleu.perl, sacrebleu and NLTK use the reference closest in length to the prediction. Recompute the reference length, ratio, brevity penalty and score with the closest-length rule and update the README examples that showed the old behaviour.
atishay-kasliwal
left a comment
There was a problem hiding this comment.
Compared BLEU with sacrebleu.corpus_bleu (13a tokenizer) on 6 cases with several references of different lengths. Here the score, brevity penalty and reference length match sacrebleu in all 6. Main picked the wrong reference length in two (3 instead of 10, and 3 instead of 6), which gave 100 instead of 65.144 in the first.
|
Thanks for cross-checking against sacrebleu! |
|
The closest-reference calculation matches SacreBLEU on a real multi-reference corpus. I also found a case that still fails before the new calculation runs on metric.compute(
predictions=["a valid four word answer"],
references=[["a valid four word answer", ""]],
)The HF metric raises For a corpus check I used the 1,997 aligned German WMT19 reference translations, with Computing the clipped n-gram precisions independently of the old brevity-penalty division would allow this case to reach the new closest-length rule. The one-sentence example would make a compact regression test. |
…e no longer crashes
|
Thanks @kiroqian, that was a real gap. The TF Checks:
|
|
I reran the 1,997-segment WMT19 case against |
Fixes #891.
What does this PR do?
compute_bleufrom tensorflow/nmt takes the effective reference length to be the shortest reference. BLEU as defined in Papineni et al. (2002),multi-bleu.perl, sacrebleu and NLTK all use the reference whose length is closest to the prediction, with ties going to the shorter one. tensorflow/nmt is archived, so this PR keepscompute_bleufor the n-gram precisions. InBleu._computeit then recomputes the reference length, length ratio, brevity penalty and score with the closest-length rule. Single-reference results are unchanged.The README examples documented the old behaviour. A prediction identical to one of its references showed
length_ratio: 1.1666666666666667andreference_length: 6; these are now1.0and7. I also added a docstring example with references of different lengths as a regression test, sincetests/test_metric_common.pydoctests every metric.Testing
sacrebleu.corpus_bleu(..., smooth_method="none", tokenize="13a").reference_lengthnow match sacrebleu in 500/500.reference_lengthdiffered in 253/500 and the score differed whenever the brevity penalty was active.pytest tests/test_metric_common.py -k "bleu and not bleurt and not google"passes. With the old computation and the new docstring example, the test fails.black --line-length 119,isortandflake8pass onmetrics/bleu/bleu.py.