2002-BLEU評估#
案件摘要#
機器翻譯研究長年困於一樁「評估噩夢」:要判斷一個譯文好不好,只能靠人工評分——慢、昂貴、且評審之間一致性低。1966 年的 ALPAC 報告正是用這種人工評估判了機器翻譯死刑,讓領域沉寂二十年。2002 年,IBM 的 Kishore Papineni、Salim Roukos、Todd Ward 與 Wei-Jing Zhu 發表《BLEU: a Method for Automatic Evaluation of Machine Translation》(ACL 2002),用 n-gram 精確率加上簡短懲罰,造出一台可以每小時跑一次的「評分機器」。破案時刻是:這個機械式指標與人工評判的相關性高到足以支撐系統迭代。BLEU 從此成為統計機器翻譯時代的標尺。
前因 -- 為什麼會有這個案子#
- 機器翻譯評估依賴人工判斷(流暢度、充分度評分),一次大規模評估動輒數月、數十萬美元,且不同評審給分差異巨大,難以比較。
- 1966 年 ALPAC 報告以人工評估為證據,宣稱機器翻譯比人工翻譯昂貴且品質差,導致美國 MT 研究經費被砍,領域進入寒冬。
- 1990 年代初 IBM 的統計機器翻譯(SMT:Candide 計劃)崛起,其方法論核心是「快速迭代」——改一個特徵、跑一次評估、看分數。人工評估完全跟不上這個節奏。
- SMT 系統產生大量候選譯文,需要一個自動、可重複、與人類判斷相關的單一數值指標來做模型選擇與參數調校。
- 想法雛形已存在:n-gram 重疊度(如 1990 年代 DARPA 評估用的 NIST 指標前身)方向正確,但會被「重複熱門詞」作弊,也沒有處理譯文長度問題。
線索與推理 -- 數學式、程式、理論#
線索一:n-gram 精確率與作弊問題#
最直覺的線索是統計候選譯文與參考譯文的 n-gram 重疊:
但原始精確率可以被作弊:候選「the the the the the」對參考「the cat」的 unigram 精確率是 5/5 = 1。破案手法是修改精確率(modified precision)——對每個 n-gram 的計數做截斷(clipping),某 n-gram 的得分不超過它在任一參考譯文中出現的最大次數:
上例中「the」在參考只出現一次,得分被截為 1/5 = 0.2,作弊被擋下。
線索二:簡短懲罰(brevity penalty)#
精確率還有另一個漏洞:只輸出最安全的兩三個詞,精確率可以很高。BLEU 用簡短懲罰封堵:若候選長度 \(c\) 短於參考有效長度 \(r\) ,就打折:
注意 BP 懲罰「太短」但不懲罰「太長」——因為太長會自然被修改精確率壓低。
線索三:破案時刻——幾何平均與相關性驗證#
最終指標是各階 n-gram 修改精確率的加權幾何平均(通常 \(w_n = 1/4\) , \(n = 1..4\) ):
用幾何平均而非算術平均是刻意的:任何一階 \(p_n\) 掉到零,整體 BLEU 就歸零——譯文必須「每一層都對」才算好。破案的臨門一腳是驗證:Papineni 等人在大量人工判斷資料上顯示,BLEU 與人類評判的相關性在系統層面足夠高,能可靠地指出「哪個系統/哪組參數較好」。支援多參考譯文(取多個人工譯文的最大計數)則承認了「翻譯沒有唯一正解」。
程式:Python 實作 BLEU 計算器#
以下是一個可執行的單句 BLEU 計算器(含 clipping、多參考、brevity penalty):
import math
from collections import Counter
def ngrams(tokens, n):
return Counter(tuple(tokens[i:i+n]) for i in range(len(tokens)-n+1))
def modified_precision(candidate, refs, n):
c = ngrams(candidate, n)
if not c:
return 0, 1
clipped = {g: min(cnt, max(ngrams(r, n).get(g, 0) for r in refs))
for g, cnt in c.items()}
num = sum(clipped.values())
den = sum(c.values())
return num, den
def bleu(candidate, refs, max_n=4):
c, r = len(candidate), max(len(x) for x in refs)
bp = 1.0 if c > r else math.exp(1 - r / c)
log_sum, ok = 0.0, True
for n in range(1, max_n + 1):
num, den = modified_precision(candidate, refs, n)
if num == 0:
ok = False
break
log_sum += (1 / max_n) * math.log(num / den)
return bp * math.exp(log_sum) if ok else 0.0
ref1 = "the cat is on the mat".split()
ref2 = "there is a cat on the mat".split()
cands = [
"the the the the the".split(), # 作弊: 重複熱門詞
"the cat is on the mat".split(), # 完全命中參考1
"the cat sat on the mat".split(), # 大致正確但 4-gram 未命中
"a cat on".split(), # 太短, 精確率高
]
for cand in cands:
print(" ".join(cand), "->", "BLEU =", round(bleu(cand, [ref1, ref2]), 4))
# 輸出:
# the the the the the -> 0.0 (1-gram 被 clipping 擋下)
# the cat is on the mat -> 0.85 (各階全中, 僅因 r 取最長參考(7詞)受輕微 BP 懲罰)
# the cat sat on the mat -> 0.0 (缺 4-gram 即歸零: BLEU 的嚴苛之處)
# a cat on -> 0.0 (太短且缺 3/4-gram)
執行可見四種情況:重複詞作弊被修改精確率擋下、完全命中得接近滿分、大致正確但缺 4-gram 的譯文歸零(這也是 BLEU 日後被批評「過於嚴苛」的鐵證)、太短的譯文得零分——BLEU 的三道防線各司其職。
結案 -- 後果與影響#
- BLEU 成為機器翻譯的標準評估指標(2002-2018),WMT 等大型評測以它為核心,系統排名皆由 BLEU 說話。
- 「快速迭代」的迴路成形:SMT 研究者可以每天改特徵、跑 BLEU,演化速度大幅加速,十年間 SMT 品質突飛猛進。
- BLEU 是第一個被整個領域接受的自動評估指標,開啟了 NLP 評估標準化時代(後繼的 ROUGE、METEOR、TER 皆循此模式)。
- BLEU 的缺陷(無法捕捉語義等價、與人工評估在高品質區間脫節、對神經系統不敏感)促成 2016 年之後的神經評估指標:BERTScore、COMET、BLEURT。
- 「用自動指標驅動模型迭代」的思想在 GPT 時代以 LLM-as-a-judge 等形式重現——BLEU 是這條路線的先聲。
關鍵人物與文獻(條列)#
- Kishore Papineni, Salim Roukos, Todd Ward, Wei-Jing Zhu. "BLEU: a Method for Automatic Evaluation of Machine Translation." ACL 2002, pp. 311-318.
- ALPAC (Automatic Language Processing Advisory Committee). "Language and Machines: Computers in Translation and Linguistics." National Academy of Sciences, 1966.
- Peter E. Brown, Stephen A. Della Pietra, Vincent J. Della Pietra, Robert L. Mercer. "The Mathematics of Statistical Machine Translation: Parameter Estimation." Computational Linguistics 19(2), 1993, pp. 263-311(IBM SMT 的數學基礎).
- George Doddington. "Automatic Evaluation of Machine Translation Quality Using N-gram Co-Occurrence Statistics." HLT 2002(NIST 指標,與 BLEU 同期).
- Chin-Yew Lin. "ROUGE: A Package for Automatic Evaluation of Summaries." ACL Workshop on Text Summarization, 2004.
- Zhang, Tian, et al. "BERTScore: Evaluating Text Generation with BERT." ICLR 2020.
- Mathias Müller, Annette Rios, Rico Sennrich. "Why Does BLEU Not Perform Well for MT?" EMNLP 2020.