在牵涉到语句生成尤其是机器翻译的应用领域,如何衡量生成语句与参考语句之间的相似性是一个很重要的问题,而在2002年Kishore Papineni et al.就提出了一个经典的衡量标准Bleu,如今这篇文献已经引用量过万,因此是NLP领域必读文章之一。
论文中给出了四个例子来辅助解释算法,每个例子都有待评价(Candidate)语句和标准参考(Reference)语句。
Candidate 1:It is a guide to action which ensures that the military always obeys the commands of the party.
Candidate 2: It is to insure the troops forever hearing the activity guidebook that party direct.
Reference 1: It is a guide to action that ensures that the military will forever heed Party commands.
Reference 2: It is the guiding principle which guarantees the military forces always being under the command of the Party.
Reference 3: It is the practical guide for the army always to heed the directions of the party .
Candidate: the the the the the the the.
Reference 1: The cat is on the mat.
Reference 2: There is a cat on the mat.
Candidate: of the
Reference 1: It is a guide to action that ensures that the military will forever heed Party commands.
Reference 2: It is the guiding principle which guarantees the military forces always being under the command of the Party.
Reference 3: It is the practical guide for the army always to heed the directions of the party.
Candidate 1: I always invariably perpetually do.
Candidate 2: I always do.
Reference 1: I always do.
Reference 2: I invariably do.
Reference 3: I perpetually do.
所谓n-gram就是指一个语句里面连续的n个单词组成的片段,一个18单词的语句有18个1-gram,每个单词都睡一个1-gram;有17个2-gram,这个很好理解。
Precision是指Candidate语句里面的n-gram在所有Reference语句里面出现的概率。
在Example 1.的Candidate 1 语句中,18个单词共有17个单词出现过,所以1-gram的precision是17/18,17个2-gram片段总共有10个出现过,所以2-gram的precision是10/17。同理有,Example 2.的Candidate 语句1-gram的Precision是7/7。
但是以上方法存在一个问题,就是可能Reference里面的单词会被重复利用,这是不合理的。所以有了“修正的n-单位精确度”(modified n-gram recision),主要思路是Reference语句里面如果一个单词片段已经被匹配,那么这个片段就不能再次被匹配,并且一个单词片段只能取一个Reference语句中出现次数的最大值,比如7个the分别在Reference 1 和 2中出现2和1次,所以取2而不是两者相加的3。
利用以上方法,每一个句子都可以得到一个modified n-gram recision,一个句子不能代表文本翻译的水平高低,于是把一段话或者所有翻译句子的结果综合起来可以得到pnp_n
pn=∑C∈{Candidate}∑n-gram∈CCountclip(n-gram)∑C'∈{Candidate}∑n-gram'∈C'Count(n-gram)
p_n = \frac {\sum_{C \in \left\{Candidate \right\}} \sum_{n\text{-}gram \in C}Count_{clip}(n\text{-}gram)}{\sum_{C^{\text{'}} \in \left\{Candidate \right\}} \sum_{n\text{-}gram\text{'} \in C\text{'}}Count(n\text{-}gram)} 简而言之,就是把所有句子的modified n-gram precision的分子加起来除以分母加起来。
上面我们已经介绍了modified n-gram precision,对于不同的长度n都会有一个pnp_n,那么如何将不同n的pnp_n结合起来得到最终的Bleu值。研究者们还考虑到一种情况,就是待测译文翻译不完全不完整的情况,这个问题在机器翻译中是不能忽略的,而简单的pnp_n值不能反映这个问题,例如Example 3。
这个问题也不能用recall来解决,例如Example 4. 显然Candidate 1的回召率比Candidate 2要高,但是显然Candidate 1的翻译不如Candidate 2。所以recall并不能解决这个问题。
首先引入BP值,作者指定当待评价译文同任意一个参考译文长度相等或超过参考译文长度时,BP值为1,当待评价译文的长度较短时,则用一个算法得出BP值。以c来表示待评价译文的长度,r来表示参考译文的文字长度,则
BP={1 if c>re1−r/c if c≤r
BP = \begin{cases} 1 ~~ if ~~ c>r \\ e^{1-r/c}~~if~~c\leq r \end{cases} 之后又Bleu值等于
Bleu=BP⋅exp(∑n=1Nwnlogpn)
Bleu = BP \cdot\exp(\sum_{n=1}^N w_n\log p_n) 在对数情况下,计算变得更加简便
logBlue=min(1−rc,0)+∑n=1Nwnlogpn
\log Blue = \min(1-\frac r c,0)+\sum_{n=1}^N w_n\log p_n 通常这个N取4,wn=1/4w_n=1/4,这就是很多论文里面的一个经典指标Bleu4