Skip to content

fix(eval): return BLEU-n instead of BLEU-1 in BleuSampleEvaluator - #567

Open
raams95 wants to merge 1 commit into
OpenDCAI:mainfrom
raams95:fix/bleu-sample-evaluator-ngram-order
Open

raams95 wants to merge 1 commit into
OpenDCAI:mainfrom
raams95:fix/bleu-sample-evaluator-ngram-order

Conversation

@raams95

@raams95 raams95 commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Summary

BleuSampleEvaluator returned bleu_score[0] from Bleu.compute_score(). That list holds the cumulative scores [BLEU-1, ..., BLEU-n], so BleuScore was always unigram precision and n did nothing. With the default n=4, "mat the on sat cat the" scored 1.0 against "the cat sat on the mat".

Two smaller problems in the same path:

  • eff="longest" is documented and accepted by the constructor, but Bleu._single_reflen() had no branch for it, so it raised AssertionError: unsupported reflen option longest.
  • Bleu.cook_append() built the n-gram counts with the default n=4 instead of self.n, so n > 4 raised IndexError.

Fix

  • bleu_sample_evaluator.py: return bleu_score[self.n - 1].
  • bleu/bleu.py: pass n=self.n to cook_refs / cook_test, and add a longest branch (max(reflens)) to _single_reflen.

Spot check against a hand calculation: "the cat sat on a mat" vs "the cat sat on the mat" now gives 0.5373 for n=4, which is (5/6 · 3/5 · 2/4 · 1/3)^(1/4).

Tests

I added test/cpu_only/test_bleu_sample_evaluator.py:

  • default run() gives 1.0 for an identical sentence and ~0 for a shuffled one

  • n=1 still ignores word order (unigram precision)

  • identical text scores 1.0 for n = 1, 2, 4 and 6

  • every documented eff option (shortest, average, longest) works

  • Before the fix: 3 failed, 6 passed (shuffled sentence scored 1.0, n=6 IndexError, eff="longest" AssertionError)

  • After the fix: 9 passed

pytest -m "cpu or api" test/cpu_only/test_bleu_sample_evaluator.py -q
9 passed

Fixes #566

compute_score() returns the cumulative scores [BLEU-1, ..., BLEU-n], but
the evaluator always took index 0, so BleuScore was unigram precision and
the n argument had no effect. Take the BLEU-n entry, build the n-gram
counts with the requested n instead of a hardcoded 4, and accept the
documented eff="longest" option instead of failing an assertion.

Fixes OpenDCAI#566

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BleuSampleEvaluator returns BLEU-1 for every n, and eff="longest" raises AssertionError

1 participant