BLEU: Bilingual Evaluation Understudy
Definition
B L E U = B P ∗ e x p ( ∑ n = 1 N w n log p n ) . log B L E U = min ( 1 − r c , 0 ) + ∑ n = 1 N w n log p n B P = { 1 c > r e 1 − r c c ≤ r , c ← l e n ( c a n d i d a t e ) , r ← l e n ( r e f e r e n c e ) p n = ∑ C ∈ { C a n d i d a t e s } ∑ n − g r a m ∈ C C o u n t c l i p ( n − g r a m ) ∑ C ′ ∈ { C a n d i d a t e s } ∑ n − g r a m ′ ∈ C ′ C o u n t ( n − g r a m ′ ) C o u n t c l i p ( n − g r a m ) = min ( C o u n t , M a x _ R e f e r e n c e _ C o u n t ) \begin{aligned} & BLEU = BP * exp(\sum_{n=1}^N w_n \log p_n).\\ & \log BLEU = \min(1 - {r\over c}, 0) + \sum_{n=1}^N w_n \log p_n\\ & BP = \begin{cases}1 & c > r\\ e^{1 - {r \over c}} & c \leq r\end{cases}, c \leftarrow len(candidate), r \leftarrow len(reference)\\ & p_n = {\sum_{C \in \{Candidates\}} \sum_{n-gram \in C} Count_{clip}(n-gram)\over \sum_{C' \in \{Candidates\}} \sum_{n-gram' \in C'} Count(n-gram')}\\ & Count_{clip}(n-gram) = \min(Count, Max\_Reference\_Count) \end{aligned} BLEU=BP∗exp(n=1∑Nwnlogpn).logBLEU=min(1−cr,0)+n=1∑NwnlogpnBP={1e1−crc>rc≤r,c←len(candidate),r←len(reference)pn=∑C′∈{Candidates}∑n−gram′∈C′Count(n−gram′)∑C∈{Candidates}∑n−gram∈CCountclip(n−gram)Countclip(n−gram)=min(Count,Max_Reference_Count)
整体计算BLEU参数的定义就在上面了,下面针对每个部分进行说明。
Count clip
这个参数计算方法是:对于一个n-gram,也就是n元词,计算其在candidate sentence中出现的次数。这里举个例子:
Candidate : the the the the the the
Reference 1 : The cat is on the mat.
Reference 2 : There is a cat on the mat.
Count_Clip('the') = min(6, max(2, 1)) = min(6, 2) = 2
这样计算的好处就是防止有一些像是这里的Candidate一样,生成了好多Reference中有的词,但是却没有考虑全局。
对标的计算方法是计算Candidate中有多少个词在Reference中出现过,也就是 C o u n t ′ ( n − g r a m ) = c o u n t Count'(n-gram) = count Count′(n−gram)=count的情况(因为这样这里的Candidate得分就是7了)
Pn
P n P_n Pn的这个计算公式实际上就是针对n特定取值下的n-gram的得分。仍然是相似的词越多,得分越高。原句得分为1。
这里可以把这个公式拆看来看,可以看到在系统生成了多个候选的答案的时候,
P
n
P_n
Pn是可以计算出总体平均得分的:
P
n
=
∑
n
−
g
r
a
m
∈
C
a
n
d
i
d
a
t
e
i
C
o
u
n
t
c
l
i
p
(
n
−
g
r
a
m
)
∑
n
−
g
r
a
m
′
∈
C
a
n
d
i
d
a
t
e
i
C
o
u
n
t
(
n
−
g
r
a
m
)
,
∣
{
C
a
n
d
i
d
a
t
e
}
∣
=
1
P_n = {\sum_{n-gram \in Candidate_i} Count_{clip}(n-gram) \over \sum_{n-gram' \in Candidate_i} Count(n-gram)}, |\{Candidate\}| = 1
Pn=∑n−gram′∈CandidateiCount(n−gram)∑n−gram∈CandidateiCountclip(n−gram),∣{Candidate}∣=1
对于有多个Candidate的情况,可以把分子分母分开,就能看到是对所有候选句子作为一个整体,计算对应的
C
o
u
n
t
,
C
o
u
n
t
c
l
i
p
Count, Count_{clip}
Count,Countclip,然后相除得分
P
n
P_n
Pn。
针对这个
P
n
P_n
Pn作者单独进行了测试,来证明仅通过改进n-gram算法得到的新指标的可用性:
上面这个是针对同一个句子,让人去翻译(深蓝色方块)和让一个差的机器翻译去翻译,在改进过的n-gram算法中n取1-4的时候计算得到的平均分(好像是)
上面这个做的更深入,是找了两个人H1,H2和三个商用机器翻译S1,S2,S3,然后用改进的n-gram计算得分。
BP
Brevity Penalty,针对语句长度进行的一个得分计算。
为啥会出现这个东西,是因为存在一些非常短的翻译只抓住了关键词,剩下的啥都没干,在原有的n-gram中得分还非常的高!
Candidate : of the
Reference 1 : It is a guide to action that ensures that the military will forever heen Party commands.
Reference 2 : It is the guiding principle which guarantees the military forces always being under the commmand of the Party.
Reference 3 : It is the practical guide for the army always to heed the directions of the Party.
然后Candidate的1-gram和2-gram得分都是1.0,非常的高(然而这显然不是一个好的翻译)
作者观察到这个现象之后,发现这种情况其实只会在句子非常短的时候发生,于是得想个办法惩罚一下这些投机取巧的短句子,然后就针对
c
<
r
c < r
c<r的部分,给他乘个因数不就行了?于是BP就出现了
B
P
=
{
1
,
c
≥
r
e
(
1
−
c
/
r
)
,
c
<
r
BP = \begin{cases} 1&, c \geq r\\ e^{(1 - c / r)}&, c < r\end{cases}
BP={1e(1−c/r),c≥r,c<r
这样,上面那个东西就自然会受到惩罚。
那么聪明的小伙伴就会问了:为啥不用recall?
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.
聪明的小伙伴一看就知道Candidate1的Recall显然高很多,但是Candidate1非常憨憨,远不如Candidate2好。因此引入Recall会破坏这种机器翻译评价。
BLEU
针对BLEU的好还是坏,作者给出了一系列的评价,具体可以去看原论文。
关于程序实现,现在很多的库中带有这个算法,例如NLTK。
可以参看:https://blog.youkuaiyun.com/g11d111/article/details/100103208