Skip to main content
Open In Colab In machine translation, there is rarely a single correct output. Two human translators may express the same meaning using different words or sentence structures. Evaluating every machine-generated translation by a human is also expensive. Papineni et al. introduced the Bilingual Evaluation Understudy (BLEU) metric (Papineni et al., 2002) as an inexpensive, reproducible way to compare machine translations with human reference translations. BLEU measures lexical overlap. It does not measure meaning directly. Its original purpose was to compare translation systems over a corpus. This section builds the metric by answering three questions. How do we prevent repeated words from inflating precision? How do we reward appropriate word order? How do we discourage translations that omit content?

1. Clipped n-gram counts

Consider the example from the original BLEU paper (Papineni et al., 2002). If you count a candidate word as correct whenever it occurs anywhere in a reference, all seven candidate words match. The resulting precision is 7/7=17/7=1, despite the translation conveying almost no information. The problem is that the same reference evidence is reused from the references. The first reference contains two occurrences of the, and the second contains one. BLEU therefore credits at most two occurrences, not seven and not three. Counts from alternative references are not added together. Let C(g)C(g) be the number of occurrences of an n-gram gg in the candidate, and Rj(g)R_j(g) its count in reference jj. The clipped count is Cclip(g)=min⁡(C(g),max⁡jRj(g)).C_{\mathrm{clip}}(g)=\min\left(C(g),\max_j R_j(g)\right). The modified precision at order nn is pn=∑g∈GnCclip(g)∑g∈GnC(g),p_n=\frac{\sum_{g\in G_n} C_{\mathrm{clip}}(g)}{\sum_{g\in G_n} C(g)}, where GnG_n is the set of distinct candidate n-grams. In the repeated-word example, p1=2/7p_1=2/7. The denominator counts all candidate occurrences; the numerator counts only those supported by reference evidence. This resembles precision in classification, because it measures how many proposed occurrences are supported. There is no conventional true-negative count, however, and BLEU does not explicitly compute recall.

2. From words to sequences of words

Unigram precision cannot distinguish sentences containing the same words in different orders. Consider a single reference and two candidates. Both candidates have perfect unigram precision. Candidate B, however, reverses the roles of the animals. For candidate B, the bigrams are the cat, cat chased, chased the, and the dog. Three of these four occur in the reference. Its modified bigram precision is therefore 3/43/4. Neither of its two four-grams occurs in the reference. Higher-order n-grams provide evidence about local word order and phrasing. They do not, by themselves, establish grammatical correctness or semantic equivalence.

3. The brevity penalty

Suppose the reference is the dog chased the cat across the garden and the candidate is only the dog chased the. Every candidate n-gram of orders one through four is supported by the reference. All four modified precisions equal one, even though half the translation is missing. BLEU addresses this failure with a brevity penalty. Let cc be the candidate length and rr the effective reference length. Then BP⁡(c,r)={1,c≥r,c>0,exp⁡(1−r/c),0<c<r,0,c=0.\operatorname{BP}(c,r)= \begin{cases} 1, & c\ge r,\quad c>0,\\ \exp(1-r/c), & 0<c<r,\\ 0, & c=0. \end{cases} For the example, c=4c=4, r=8r=8, and the penalty is e−1≈0.368e^{-1}\approx 0.368. When multiple references exist, BLEU chooses the reference length closest to the candidate length, breaking ties in favor of the shorter reference. At corpus level, these selected lengths are summed. The brevity penalty is not recall: it penalizes insufficient length but does not check which information was omitted. Overly long candidates receive no separate length penalty; unsupported extra n-grams typically lower modified precision.
Output from cell 4

4. Combining the components: BLEU-4

You now have two complementary mechanisms: modified precision at several n-gram orders and a penalty for short translations. BLEU combines them as BLEU⁡=BP⁡(c,r)exp⁡(∑n=1Nwnlog⁡pn)=BP⁡(c,r)∏n=1Npnwn,\operatorname{BLEU}=\operatorname{BP}(c,r)\exp\left(\sum_{n=1}^{N}w_n\log p_n\right) =\operatorname{BP}(c,r)\prod_{n=1}^{N}p_n^{w_n}, where the weights are nonnegative and sum to one. Terms with zero weight are omitted. Standard BLEU-4 uses N=4N=4 and wn=1/4w_n=1/4. The geometric mean rewards translations that perform well across all selected orders. For example, if the four precisions are (1,0.8,0.4,0.1)(1,0.8,0.4,0.1), their arithmetic mean is 0.5750.575, whereas their geometric mean is approximately 0.4230.423. Poor higher-order agreement has a stronger effect on the geometric mean. If any positively weighted precision is zero, unsmoothed BLEU is zero. This is a design choice, not a mathematical necessity. It is useful for corpus evaluation but can be excessively harsh for individual sentences.

5. From sentence-level examples to corpus-level BLEU

The original BLEU metric aggregates clipped counts across sentences before calculating precision. For candidate sentence ss with its own references, let as,na_{s,n} and bs,nb_{s,n} be its clipped and total n-gram counts. Then pncorpus=∑sas,n∑sbs,n.p_n^{\mathrm{corpus}}=\frac{\sum_s a_{s,n}}{\sum_s b_{s,n}}. The brevity penalty uses the total candidate length and the sum of effective reference lengths. Consequently, corpus BLEU is not the arithmetic mean of sentence BLEU scores. Longer sentences generally contribute more n-gram occurrences. The following implementation exposes the calculation. It uses fixed-order, unsmoothed BLEU, defining it as zero if a required order has no matching occurrences (including when the corpus has no n-grams of that order).

6. Investigating translation errors

The next experiment uses one reference and several candidate translations. Inspect the individual precisions before looking at the combined score. The truncation has excellent precision but incurs a length penalty. The paraphrase may preserve meaning yet have little lexical overlap. The negation changes the meaning while retaining many reference n-grams.
Output from cell 7

7. Sentence-level BLEU and smoothing

Short sentences may have no matching four-grams, even when much of the translation is correct. Smoothing modifies the precision calculation to avoid a zero geometric mean. Different smoothing methods produce different scores; they should not be treated as interchangeable with original unsmoothed corpus BLEU. NLTK exposes several smoothing methods described by Chen and Cherry (Chen & Cherry, 2014). The code below uses method 1, which adds a small constant to the numerator for orders with zero matches (NLTK also guards against zero denominators).

8. What BLEU measures in practice

BLEU is useful when comparing machine translation systems on the same test corpus under the same evaluation protocol. Its limitations become particularly visible when evaluating individual outputs. A faithful paraphrase can score poorly, while a translation with a critical factual error can score relatively well. Tokenization, case handling, reference selection, smoothing and effective-order conventions can affect reported results. BLEU is often reported on a scale from 0 to 100, which is the 0 to 1 score multiplied by 100. For reproducible machine translation benchmarks, SacreBLEU provides standardized evaluation and a configuration signature (Post, 2018). Semantic metrics such as COMET (Rei et al., 2020) add complementary evidence, but they do not guarantee correctness.

References

  • Chen, B., Cherry, C. (2014). A systematic comparison of smoothing techniques for sentence-level BLEU. Proceedings of the Ninth Workshop on Statistical Machine Translation. DOI
  • Papineni, K., Roukos, S., Ward, T., Zhu, W. (2002). BLEU: a method for automatic evaluation of machine translation. Proceedings of the 40th Annual Meeting on Association for Computational Linguistics - ACL ‘02. DOI
  • Post, M. (2018). A Call for Clarity in Reporting BLEU Scores. Proceedings of the Third Conference on Machine Translation: Research Papers. DOI
  • Rei, R., Stewart, C., Farinha, A., Lavie, A. (2020). COMET: A neural framework for MT evaluation. Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP). DOI

Found an error on this page? Report an issue.