Repository navigation
Conversation
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
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
BleuSampleEvaluatorreturnedbleu_score[0]fromBleu.compute_score(). That list holds the cumulative scores[BLEU-1, ..., BLEU-n], soBleuScorewas always unigram precision andndid nothing. With the defaultn=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, butBleu._single_reflen()had no branch for it, so it raisedAssertionError: unsupported reflen option longest.Bleu.cook_append()built the n-gram counts with the defaultn=4instead ofself.n, son > 4raisedIndexError.Fix
bleu_sample_evaluator.py: returnbleu_score[self.n - 1].bleu/bleu.py: passn=self.ntocook_refs/cook_test, and add alongestbranch (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 onen=1still ignores word order (unigram precision)identical text scores 1.0 for
n= 1, 2, 4 and 6every documented
effoption (shortest,average,longest) worksBefore the fix: 3 failed, 6 passed (shuffled sentence scored 1.0,
n=6IndexError,eff="longest"AssertionError)After the fix: 9 passed
Fixes #566