All problems
BLEU Score Lite
Problem
Compute a BLEU-lite score from clipped unigram and bigram precisions, using only unigrams when the candidate has a single token. The score is the brevity penalty times the geometric mean of the precisions, where BP = 1 when the candidate is at least as long as the reference, else exp(1 - ref_len / cand_len). Return 0.0 if the candidate is empty or any precision is zero.
Hint
Clip each candidate n-gram count at its reference count before dividing.
Test cases
case 1
in: ["the cat sat on the mat","the cat sat on the mat"]
expected: 1
case 2
in: ["the cat sat","the cat"]
expected: 0.5773502691896257
case 3
in: ["a b c d","a b c"]
expected: 0.7071067811865475
case 4
in: ["x y","a b"]
expected: 0
Starter codePython
import math
def bleu_lite(candidate, reference):
# Your code here
pass4 test cases · run your code against them in the editor