BLEU
Bilingual Evaluation Understudy
A metric for measuring machine translation quality. Based on n-gram overlap.
Bilingual Evaluation Understudy
A metric for measuring machine translation quality. Based on n-gram overlap.
BLEU (Bilingual Evaluation Understudy) is a metric that automatically evaluates the quality of machine translation by measuring the n-gram overlap between machine translation output and human translations (reference translations). It is a score between 0 and 1 (or 0-100), where a higher score means greater similarity to the reference translation.
It was proposed in 2002 by Kishore Papineni's team at IBM, and because it can measure translation quality quickly and inexpensively, it became a standard evaluation metric in machine translation research. It has been used as an official metric in major competitions such as WMT (Workshop on Machine Translation).
The calculation combines the precision for 1-grams through 4-grams using a geometric mean and multiplies it by a brevity penalty that penalizes short translations. Modified precision is used to prevent the same word from being repeated excessively. When there are multiple reference translations, the output is compared against the most favorable one.
In practice, BLEU is useful for quick model comparison and for monitoring the development process. However, because it measures surface-level overlap rather than semantic similarity, it is recommended to use it together with human evaluation or neural metrics such as COMET and BERTScore when making a final quality judgment.
# BLEU 점수 계산 예제
from nltk.translate.bleu_score import sentence_bleu, corpus_bleu
from nltk.translate.bleu_score import SmoothingFunction
# 1. 문장 단위 BLEU
reference = [['the', 'cat', 'is', 'on', 'the', 'mat']]
candidate = ['the', 'cat', 'sat', 'on', 'the', 'mat']
# 기본 BLEU (1~4-gram 균등 가중치)
score = sentence_bleu(reference, candidate)
print(f"문장 BLEU: {score:.4f}")
# 개별 n-gram 가중치 지정
weights_1gram = (1, 0, 0, 0) # BLEU-1
weights_2gram = (0.5, 0.5, 0, 0) # BLEU-2
print(f"BLEU-1: {sentence_bleu(reference, candidate, weights=weights_1gram):.4f}")
print(f"BLEU-2: {sentence_bleu(reference, candidate, weights=weights_2gram):.4f}")
# 2. Smoothing (짧은 문장이나 n-gram 미일치 시)
smoother = SmoothingFunction()
short_candidate = ['the', 'cat']
smoothed_score = sentence_bleu(
reference, short_candidate,
smoothing_function=smoother.method1
)
print(f"Smoothed BLEU: {smoothed_score:.4f}")
# 3. Corpus 단위 BLEU (여러 문장)
references_corpus = [
[['the', 'cat', 'is', 'on', 'the', 'mat']],
[['there', 'is', 'a', 'dog', 'in', 'the', 'house']]
]
candidates_corpus = [
['the', 'cat', 'sat', 'on', 'the', 'mat'],
['a', 'dog', 'is', 'in', 'the', 'house']
]
corpus_score = corpus_bleu(references_corpus, candidates_corpus)
print(f"Corpus BLEU: {corpus_score:.4f}")
# 4. SacreBLEU (표준화된 BLEU, 권장)
# pip install sacrebleu
import sacrebleu
refs = [["The cat is on the mat."]]
hyp = "The cat sat on the mat."
bleu = sacrebleu.sentence_bleu(hyp, refs)
print(f"SacreBLEU: {bleu.score:.2f}")
"The current model's BLEU is 32.5, which falls short of the production threshold of 35. But we shouldn't look at BLEU alone: there are cases where the translation uses 'a different expression with the same meaning', so we need to check BERTScore as well. Let's also run human evaluation sampling in parallel."
"This paper claims BLEU went up by 0.5, but if the tokenization method or the number of reference translations differs, the scores can't be compared. If they don't report a standardized score with SacreBLEU, it's hard to reproduce. They need to specify even the tokenization settings for a fair comparison."
"The limitation of BLEU is that it cannot recognize synonyms or paraphrases. 'The boy is happy' and 'The child is glad' have the same meaning, but BLEU comes out low. That's why semantic-based evaluations such as BERTScore and COMET have recently been preferred."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
BLEU scores vary greatly depending on the tokenization method. When comparing across papers, be sure to use the same tokenization or use standardized scores from SacreBLEU.
Averaging sentence-level BLEU gives a different value from corpus BLEU. For system evaluation, always use corpus-level BLEU, and use sentence BLEU only for debugging purposes.
A BLEU of 40 does not guarantee a "good translation." The standard differs depending on the domain and language pair, and its correlation with human evaluation is also not perfect. Do not judge quality by this metric alone.