Calculate the BLEU score to evaluate machine translation or text generation quality.
BLEU (Bilingual Evaluation Understudy) measures machine translation quality by computing the geometric mean of n-gram precisions (1 through 4), multiplied by a brevity penalty to prevent artificially short translations from scoring high. Scores range from 0 to 1, with higher being better.
BLEU-4
BLEU = BP * exp((1/4) * sum(ln(p_n)))
BLEU scores above 0.3 are generally considered decent for machine translation, above 0.5 is very good, and scores above 0.6 are near human-level for many language pairs. The absolute number depends heavily on language pair and domain.
Geometric mean is more sensitive to low individual precisions — if any n-gram precision is zero, the entire BLEU score drops to zero, enforcing that good translations must match at all n-gram levels.