NLP领域—BLEU介绍
前言:
在阅读Attention Is All You Need这篇论文的时候,我突然发现了一个经常出现但是却有不怎么熟悉的评估指标——BLEU
,经过初步的检索调查,介绍如下。
正文:
BLEU
(Bilingual Evaluation Understudy),即双语评估替补。出自论文bleu.dvi。
所谓替补就是代替人类来评估机器翻译的每一个输出结果。Bleu score 所做的,给定一个机器生成的翻译,自动计算一个分数,衡量机器翻译的好坏。取值范围是[0, 1],越接近1,表明翻译质量越好,但是一般论文中都是百分比分数形式。
我相信该公式的其他部分都十分好理解,但是这个$p_n$就会有一点让人迷惑,接下来我将结合一个例子来解释这个公式。
参数解释
项 | 含义 |
---|---|
$y$ | 候选翻译句子(machine translation candidate) |
n-gram∈C | 候选句子中所有长度为 n 的词组(n-gram) |
Count(n-gram) | 某个 n-gram 在候选句中出现的次数 |
CounterClip(n-gram) | 对该 n-gram 出现次数的修剪统计,不得超过它在参考翻译中出现的次数 |
示例演示
我们以计算 2-gram(bigram)精确度 $P_2$ 为例:
参考翻译(Reference):
the cat is on the mat
候选翻译(Candidate):
the cat the cat on the mat
① Step 1: 提取候选翻译中的 2-gram
候选句分词后为:
["the", "cat", "the", "cat", "on", "the", "mat"]
从中提取所有 2-gram(重复保留):
- the cat
- cat the
- the cat
- cat on
- on the
- the mat
对应的统计值:
Counter(n-gram):
the cat → 2
cat the → 1
cat on → 1
on the → 1
the mat → 1
② Step 2: 提取参考翻译中的 2-gram
参考句为:
the cat is on the mat
提取出的 2-gram:
- the cat
- cat is
- is on
- on the
- the mat
对应统计值:
Reference Counter:
the cat → 1
cat is → 1
is on → 1
on the → 1
the mat → 1
③ Step 3: 计算修剪后的计数(CounterClip)
对每个候选中的 2-gram:
the cat → min(2, 1) = 1
cat the → min(1, 0) = 0
cat on → min(1, 0) = 0
on the → min(1, 1) = 1
the mat → min(1, 1) = 1
④ Step 4: 套入公式
分子:clip 后的 n-gram 总数为:
$$
\sum \text{CounterClip}(n\text{-}gram) = 1 + 0 + 0 + 1 + 1 = 3
$$
分母:原始的 n-gram 总数为:
$$
\sum \text{Counter}(n\text{-}gram) = 2 + 1 + 1 + 1 + 1 = 6
$$
最终 2-gram 精确度为:
$$
P_2 = \frac{3}{6} = 0.5
$$
总结
- BLEU 中的 $P_n$ 衡量的是候选翻译中所有 n-gram 与参考翻译 n-gram 的 匹配精确度。
- 使用 $\text{CounterClip}$ 的目的是 限制重复刷分。
- 实际 BLEU 分数会结合多个 $P_n$(如 $P_1, P_2, P_3, P_4$)并加入 brevity penalty(简短惩罚),更全面地评估翻译质量。
参考文献:
BLEU: a Method for Automatic Evaluation of Machine Translation