All problems
BLEU-2 with Clipping
Problem
Compute the clipped BLEU-2 score between candidate and reference token lists. Unigram and bigram precisions use multiplicity clipping against the reference, and the score is the geometric mean exp((log p1 + log p2) / 2).
Return 0.0 when either side lacks unigrams or bigrams, or when either precision is 0. Brevity is not penalized here.
Hint
Clip each distinct n-gram count by how often it appears in the reference.
Test cases
case 1
in: [["a","b","c"],["a","b","c"]]
expected: 1
case 2
in: [["a","b","d"],["a","b","c"]]
expected: 0.5773502691896257
case 3
in: [["a"],["a","b"]]
expected: 0
case 4
in: [["a","b"],["a","b","c"]]
expected: 1
case 5
in: [["x","y"],["a","b"]]
expected: 0
Starter codePython
import math
def bleu2_clipped(candidate, reference):
# Your code here
pass5 test cases · run your code against them in the editor