How BLEU is calculated: n-gram precision and the brevity penalty
Learn how corpus BLEU combines clipped n-gram precision with a brevity penalty, work through a numeric example, and record settings needed for fair comparisons.
How BLEU is calculated: n-gram precision and the brevity penalty
BLEU is an automatic metric that computes modified n-gram precision between system translations and reference translations, then applies a brevity penalty when the output is too short. It is usually compared as a corpus score over many sentences, not as an average of sentence scores. Scores are hard to compare directly when tokenization, normalization, or the number of references differs.
What BLEU counts
An n-gram is a sequence of n consecutive tokens: one token is a 1-gram, and two consecutive tokens are a 2-gram. BLEU measures the overlap between candidate and reference n-grams, but clips candidate matches so they cannot count more times than the references allow. This modified precision reduces score inflation from simply repeating a matching word.
With multiple references, the maximum count observed in any single reference sets the match limit for each n-gram. Match counts are accumulated across sentences to calculate modified precision pₙ for the whole evaluation corpus. BLEU is therefore not the simple average of sentence-level scores.
The formula and brevity penalty
BLEU multiplies the weighted geometric mean of modified n-gram precisions by a brevity penalty:
BLEU = BP × exp(Σ wₙ × log(pₙ))
Here pₙ is precision for n-grams of order n, and wₙ is its weight; all weights sum to 1. The original paper’s baseline uses equal weights for 1- through 4-grams. Let c be the total number of candidate tokens and r the sum of the closest reference lengths for each sentence.
BP = 1 (c > r), or exp(1 − r/c) (c ≤ r)
If the candidates are shorter than the references, BP is below 1 and lowers the score. Outputs longer than the references receive no extra bonus from this term. Corpus BLEU is often shown on either a 0–1 or 0–100 scale, so check which scale is reported.
A calculation example
These values are a hypothetical corpus summary to illustrate the formula, not measurements from a translation system. Suppose the four modified precisions are p₁=0.80, p₂=0.50, p₃=0.25, and p₄=0.125, with equal weights of 0.25. Let total candidate length c=8 and effective reference length r=10.
| Step | Calculation | Approximate result |
|---|---|---|
| Geometric mean of modified precisions | (0.80 × 0.50 × 0.25 × 0.125)^(1/4) | 0.334 |
| Brevity penalty | exp(1 − 10/8) | 0.779 |
| BLEU | 0.334 × 0.779 | 0.260 (0–1 scale) |
On a 0–100 scale, this is about 26.0. It is only the calculation for the hypothetical inputs above; actual tool results can differ with tokenization and smoothing settings.
Compare and reproduce scores carefully
**Use the same evaluation corpus and sentence alignment.** Changing test sentences or references can change the score.
**Match tokenization and normalization.** Case, punctuation, and language-specific tokenization change the n-grams being counted.
**Record the number of references and length handling.** More references can provide more opportunities for matches and affect the score.
**Record the tool and options.** For example, SacreBLEU outputs a signature with details such as reference count, case handling, tokenizer, smoothing method, and version. Preserve it when sharing a result so configuration differences can be traced.
**Do not treat a small score difference as proof of better quality.** Consider the test-set composition and sampling variation, and inspect important examples directly.
BLEU summarizes surface overlap with references. A valid paraphrase may receive a lower score because its wording differs, while high overlap does not guarantee correct meaning. Use BLEU to compare systems under the same conditions, and pair it with error analysis or human review when judging translation quality. For the roles of several metrics, see how to evaluate speech recognition and translation together.
References
[Papineni, Roukos, Ward & Zhu (2002), BLEU: a Method for Automatic Evaluation of Machine Translation](https://aclanthology.org/P02-1040/)
[Post (2018), A Call for Clarity in Reporting BLEU Scores](https://aclanthology.org/W18-6319/)
[SacreBLEU official repository documentation](https://github.com/mjpost/sacrebleu)