AI Logic

Evaluation Metrics

BLEU

Updated:

Computation of BLEU. The top shows the candidate translation "the cat is on the mat" and two reference translations. The bottom left shows whether each 1- to 4-gram of the candidate appears in a reference (the second "the" exceeds its cap and is not counted; p1 = 5/6, p2 = 4/5, p3 = 3/4, p4 = 2/3). The bottom right multiplies the geometric mean 0.760 by the brevity penalty 1.00 to give BLEU 0.760

Background and Overview

BLEU is an evaluation metric that counts how many of the same word sequences (n-grams) a machine translation output shares with human translations (reference translations) and condenses this into a single number between 0 and 1. The closer to 1, the closer the translation is to the references. The paper uses the 0–1 range, but scores are also often multiplied by 100 and written on a 0–100 scale.

BLEU=BPβ‹…exp⁑(βˆ‘n=1Nwnlog⁑pn)\mathrm{BLEU} = \mathrm{BP} \cdot \exp\left( \sum_{n=1}^{N} w_n \log p_n \right)

Here, pnp_n is the fraction of n-grams in the candidate translation that also appear in the references (clipped n-gram precision), wnw_n is a weight (the standard is N=4N = 4, wn=1/4w_n = 1/4), and BP\mathrm{BP} is the brevity penalty, which lowers the score when the candidate is too short compared with the references. When all wnw_n are equal, the exp term is the geometric mean of p1p_1 through p4p_4.

BLEU was proposed by Papineni et al. at IBM in 2002. Until then, translations were evaluated by humans, and results took weeks to months to come back. BLEU was designed as an automatic evaluation that is fast, inexpensive, language-independent, and correlates well with human judgments, so that developers could check whether their day-to-day changes helped. The name stands for bilingual evaluation understudy.

Definition and Computation

BLEU is computed over the whole set of evaluation sentences (the corpus) as follows.

  1. Extract every word sequence of length nn (n-gram) from each candidate sentence (n=1,2,3,4n = 1, 2, 3, 4).
  2. Cap the count of each n-gram at its maximum count in any single reference (clipping): Countclip=min⁑(Count,Max_Ref_Count)\mathrm{Count}_{\mathrm{clip}} = \min(\mathrm{Count}, \mathrm{Max\_Ref\_Count}).
  3. Sum the clipped counts over all sentences in the corpus and divide by the total number of candidate n-grams to get the clipped n-gram precision pnp_n.
pn=βˆ‘Cβˆ‘g∈CCountclip(g)βˆ‘Cβˆ‘g∈CCount(g)p_n = \frac{\sum_{C} \sum_{g \in C} \mathrm{Count}_{\mathrm{clip}}(g)}{\sum_{C} \sum_{g \in C} \mathrm{Count}(g)}
  1. Average log⁑pn\log p_n with weights wnw_n and take the exp (the geometric mean when wn=1/4w_n = 1/4).
  2. Multiply by the brevity penalty. cc is the total number of words in the candidates, and rr is the sum over sentences of the length of the reference closest in length (the effective reference length).
BP={1(c>r)e 1βˆ’r/c(c≀r)\mathrm{BP} = \begin{cases} 1 & (c > r) \\ e^{\,1 - r/c} & (c \le r) \end{cases}

The clipping in step 2 prevents translations that merely repeat the same word from scoring well. The paper's example compares the candidate "the the the the the the the" with the references "The cat is on the mat." and "There is a cat on the mat.". Since "the" appears at most twice in any reference, only 2 of the 7 occurrences count as matches, and the 1-gram precision is 2/7 rather than 7/7.

With precision alone, translations that output only a few safe words would be rewarded. In the paper's example, the candidate "of the" gets perfect scores: 2/2 for 1-gram precision and 1/1 for 2-grams. The brevity penalty prevents this. This candidate has 2 words and the closest reference has 16, so BP=e1βˆ’16/2β‰ˆ0.0009\mathrm{BP} = e^{1 - 16/2} \approx 0.0009, and the score drops almost to 0. For candidates that are too long, the extra words already lower precision, so the penalty applies only to the short side.

In the example in the figure at the top, among the 1-grams of the candidate "the cat is on the mat", the second "the" exceeds its cap (once in either reference) and is not counted, so p1=5/6p_1 = 5/6. Likewise, p2=4/5p_2 = 4/5, p3=3/4p_3 = 3/4, and p4=2/3p_4 = 2/3, with a geometric mean of about 0.760. The candidate length (6 words) equals the length of reference 2, so BP=1\mathrm{BP} = 1 and BLEU is about 0.760.

What It Measures and Its Limitations

According to the paper, a translation that uses the same words (1-grams) as the references tends to satisfy adequacy (conveying the meaning correctly), while longer n-gram matches reflect fluency (natural word order). BLEU measures both together with a single counting scheme: n-gram matches.

It has the following limitations.

  • Sentence-level scores are unreliable: BLEU is designed to agree with human judgments when averaged over a whole corpus. The paper itself notes that sentence-level scores often disagree with human judgments. For example, translating as "East Asian economy" is heavily penalized on longer n-grams if every reference says "economy of East Asia".
  • Paraphrases are not credited, even with the same meaning: only surface strings are matched. Synonyms and natural reorderings count as mismatches unless they appear in a reference.
  • Scores depend on the number of references: the more references, the easier it is to match, and the higher the score. In the paper, the same human translation scored 0.3468 with four references and 0.2571 with two.
  • Scores depend on preprocessing: word segmentation (tokenization) and case handling change the score. Post (2018) showed that for the same system output, differences in reference preprocessing alone change the score by up to 1.8 points (on the 0–100 scale), a gap that can exceed the improvement claimed by a new method.
  • Because it is a geometric mean, a single zero pnp_n makes the whole score 0: short sentences often have no matching 4-gram at all. When computing per sentence, use smoothing to avoid zeros.

BLEU scores are comparable only when the tokenization, case handling, number of references, and smoothing method are the same. When comparing across papers, fix the preprocessing on the metric side, as sacreBLEU does, and report the signature describing the settings (for example, BLEU|nrefs:1|case:mixed|eff:no|tok:13a|smooth:exp|version:2.0.0). For languages without spaces between words, such as Japanese and Chinese, the score is not correct unless a suitable tokenizer is specified (ja-mecab or zh in sacreBLEU).

Validation in the Original Paper

The paper compared three machine translation systems (S1–S3) and two human translators (H1: a non-native speaker of both English and Chinese; H2: a native English speaker) on Chineseβ†’English translation. The BLEU scores for about 500 sentences (40 news articles), evaluated against two references, are as follows.

S1S2S3H1H2
BLEU (2 references)0.05270.08290.09300.19340.2571

This ranking matched the ranking from human judges' five-point ratings. The correlation coefficient was 0.99 with ten native English-speaking judges (rating fluency) and 0.96 with ten native Chinese-speaking judges. The ranking of S2 and S3, which differ only slightly, also agreed with human judgments.

The paper also split the test corpus into 20 blocks of 25 sentences, computed BLEU for each, and confirmed that the differences between adjacent systems were statistically significant. Using only one reference did not change the system ranking. From this, the paper concludes that a large test corpus with a single reference is sufficient, provided the translators are not all of one style.

Where It Is Used

BLEU is mainly used in the following settings.

  • Comparing machine translation systems: it is the standard metric for reporting model performance on translation benchmarks such as WMT. For example, the Transformer paper reports BLEU 28.4 (on the 0–100 scale) for Englishβ†’German translation. It has also been used to evaluate methods that originated in translation, such as Sequence to Sequence and additive attention.
  • Comparisons during development: on the same test data with the same settings, it quickly compares the effect of model changes or the beam search width. This is the use the paper had in mind.
  • Text generation beyond translation: the paper also suggests applications such as summarization. It is sometimes used for image caption generation, but for summarization, the recall-oriented ROUGE is more common.

Comparison with Similar Metrics

The table compares BLEU with other metrics used to evaluate text generation from the same perspectives.

MetricUnit comparedPrecision / recallRobustness to paraphraseTypical task
BLEUWord n-grams (1–4)Precision + brevity penaltyWeak (surface match only)Machine translation
chrFCharacter n-gramsBoth (F-score)Moderate (robust to inflection)Machine translation (morphologically rich languages)
METEORWord alignmentBoth (recall weighted)Fairly strong (stems and synonyms match)Machine translation
ROUGEWord n-grams, longest common subsequenceMainly recallWeakSummarization
BERTScoreEmbedding similarityBoth (F-score)Strong (compares meaning)Text generation in general
Word error rate (WER)Word edit distanceβ€”WeakSpeech recognition

Guidelines for choosing:

  • Comparing with prior work on translation benchmarks: compute BLEU with sacreBLEU and include the signature, since this makes the score comparable with many papers.
  • Morphologically rich languages, or languages like Japanese where word boundaries are ambiguous: also use chrF, which depends less on word segmentation.
  • Crediting paraphrases fairly: also use a meaning-based metric such as BERTScore, or human evaluation.
  • Measuring the predictive power of the generative model itself: use perplexity, computed from the model's probabilities rather than from agreement with references.

PyTorch example

Show code
python
import math
from collections import Counter


def ngram_counts(tokens, n):
  return Counter(tuple(tokens[i:i + n]) for i in range(len(tokens) - n + 1))


def corpus_bleu(candidates, references, max_n=4):
  """Corpus BLEU exactly as in the formulas of Papineni et al. (2002) (no smoothing).
  candidates: list of candidate sentences (each sentence is a list of tokens)
  references: list of references for each candidate sentence ([[ref1, ref2, ...], ...])
  """
  clipped = [0] * max_n
  total = [0] * max_n
  c_len, r_len = 0, 0
  for cand, refs in zip(candidates, references):
    for n in range(1, max_n + 1):
      cand_counts = ngram_counts(cand, n)
      # cap = maximum count within any single reference
      max_ref = Counter()
      for ref in refs:
        for g, k in ngram_counts(ref, n).items():
          max_ref[g] = max(max_ref[g], k)
      clipped[n - 1] += sum(min(k, max_ref[g]) for g, k in cand_counts.items())
      total[n - 1] += max(len(cand) - n + 1, 0)
    c_len += len(cand)
    # add the reference closest in length (the shorter one on ties) to the effective reference length
    r_len += min((abs(len(r) - len(cand)), len(r)) for r in refs)[1]
  if min(clipped) == 0:
    return 0.0  # geometric mean, so 0 if any p_n is 0
  log_p = sum(math.log(clipped[i] / total[i]) for i in range(max_n)) / max_n
  bp = 1.0 if c_len > r_len else math.exp(1 - r_len / c_len)
  return bp * math.exp(log_p)


cand = "the cat is on the mat".split()
refs = ["there is a cat on the mat".split(), "a cat is on the mat".split()]
print(round(corpus_bleu([cand], [refs]), 4))  # 0.7598

# Scores compared across papers are computed with sacreBLEU (fixes preprocessing on the metric side, returns 0-100)
import sacrebleu

hyps = ["the cat is on the mat"]
# references are passed as a list of reference streams: refs[k][i] is the k-th reference for the i-th candidate
refs_streams = [["there is a cat on the mat"], ["a cat is on the mat"]]
bleu = sacrebleu.metrics.BLEU()  # tokenize="13a" (default). For Japanese, tokenize="ja-mecab"
result = bleu.corpus_score(hyps, refs_streams)
print(result.score, bleu.get_signature())

# torchmetrics: target is a list of references per candidate (the reverse order of sacreBLEU), returns 0-1
from torchmetrics.text import BLEUScore

metric = BLEUScore(n_gram=4, smooth=False)
print(metric(["the cat is on the mat"], [["there is a cat on the mat", "a cat is on the mat"]]))  # tensor(0.7598)

FAQ

Q. What BLEU score counts as a good translation?
A.

There is no fixed threshold, because the score varies greatly with the language pair, test data, number of references, and preprocessing. In the paper, even a human translator scored 0.2571 with two references. Judge by comparing with existing systems evaluated under the same conditions.

Q. Is it fine to look at BLEU for a single sentence?
A.

Only as a rough reference. BLEU is designed to agree with human judgments when averaged over a whole corpus, and sentence-level scores often disagree with human judgments. In addition, short sentences often have no matching 4-gram and score 0 without smoothing. When looking at individual sentences, use smoothing, and compare corpus-level scores.

Q. Is corpus BLEU the average of sentence-level BLEU?
A.

No. Corpus BLEU first sums the match counts and n-gram counts over all sentences and then computes the precisions, and the brevity penalty is also computed from the lengths of the whole corpus. Averaging sentence-level scores gives a different value; for example, length mismatches in short sentences are penalized heavily.

References

  1. Papineni, K., Roukos, S., Ward, T., & Zhu, W.-J. (2002). BLEU: a Method for Automatic Evaluation of Machine Translation. Proceedings of the 40th Annual Meeting of the ACL, 311–318.
  2. Post, M. (2018). A Call for Clarity in Reporting BLEU Scores. Proceedings of the Third Conference on Machine Translation (WMT).
  3. sacreBLEU (GitHub repository).
  4. Lightning AI. torchmetrics.text.BLEUScore (API reference).