Implement single-reference BLEU with a brevity penalty.
Signature: def bleu(reference: list, candidate: list, max_n: int = 4) -> float
Tokens are pre-split lists. For each n in 1..max_n:
sum(min(cand_count, ref_count)) / total_cand_ngramsThen:
min(1, exp(1 - len(ref) / len(cand))) if len(cand) < len(ref) else 1BP * geo_meanReturn 0.0 for empty inputs or any zero-precision n-gram order.
Math
Asked at
Test Results