BLEU值的计算

原文链接:https://www.jianshu.com/p/15c22fadcba5

BLEU (Bilingual Evaluation Understudy) is an algorithm for evaluating the quality of text which has been machine-translated from one natural language to another. Quality is considered to be the correspondence between a machine's output and that of a human: "the closer a machine translation is to a professional human translation, the better it is" – this is the central idea behind BLEU. BLEU was one of the first metrics to achieve a high correlation with human judgements of quality, and remains one of the most popular automated and inexpensive metric. -- 维基百科

bleu是一种文本评估算法,它是用来评估机器翻译专业人工翻译之间的对应关系,核心思想就是机器翻译越接近专业人工翻译,质量就越好,经过bleu算法得出的分数可以作为机器翻译质量的其中一个指标。使用bleu的目的是给出一个快且不差的自动评估解决方案,评估的是机器翻译与人翻译的接近程度。

bleu的核心在于:N-gram惩罚因子

BLEU也是采用了N-gram的匹配规则,通过它能够算出比较译文和参考译文之间n组词的相似的一个占比。

通常情况

例子:

原文: 猫坐在垫子上
机器翻译:The cat sat on the mat.
人工翻译:The cat is on the mat.

我们分别看下1-4 gram的匹配情况:

1-gram

可以看到机器翻译6个词,有5个词命中参考以为,那么它的匹配度为 5/6。

2-gram

2元词组的匹配度则是 3/5。

3-gram

3元词组的匹配度是1/4。

4-gram

4元词组的匹配情况就没有了。

一般情况1-gram可以代表原文有多少词被单独翻译出来,可以反映译文的充分性,2-gram以上可以反映译文的流畅性,它的值越高说明可读性越好。这两个指标是能够跟人工评价对标的。

特殊情况

根据上面的准则,会有一些错误的翻译得到更大的得分,考虑以下两种情况。

N-gram错误情况

例如

原文:猫坐在垫子上
机器译文: the the the the the the the.
参考译文:The cat is on the mat.

1-gram下,所有的the都匹配到了,得分是7/7,这显然是错误的,因此对计算公式做以下修改:

提出取机器翻译译文N-gram的出现次数和参考译文中N-gram最大出现次数中的最小值的算法,具体如下:

这里count=7,Max_ref_Count = 2,取它们之间的最小值为2,那么修正后的1-gram的匹配度应该为2/7

句子过短情况

例:

机器译文:The cat
参考译文:The cat is on the mat.

显然,得分为1,但是不可取,因此对于长度过短的句子加以惩罚:

这里的c是机器译文的词数,r是参考译文的词数,

这样的话我们重新算精度就应该是:

BP = e^(1- 6 / 2) =0.13

总结

综上,bleu的最终计算公式为:

通过例子进行说明:

机器翻译:The cat sat on the mat.
人工翻译:The cat is on the mat.

1、计算各gram的精度(一般最多取到4-gram)

P1 = 5 / 6 = 0.833333333333333
P2 = 3 / 5 = 0.6
P3 = 1 / 4 = 0.25
P4 = 0 / 3 = 0

2、加权求和

取权重:Wn = 1 / 4 = 0.25

有0的项不做计算

3、求BP

这里c=r,则BP=1

4、求BLEU

写程序的时候,不用费那么大的劲去实现上面的算法,现成的工具就可以用:

from nltk.translate.bleu_score import sentence_bleu
reference = [['The', 'cat', 'is', 'on', 'the', 'mat']]
candidate = ['The', 'cat', 'sat', 'on', 'the', 'mat']
score = sentence_bleu(reference, candidate)
print(score)
# 输出结果:0.5946035575013605

BLEU的优缺点

优点:方便、快速,结果比较接近人类评分。

缺点

  1. 不考虑语言表达(语法)上的准确性;
  2. 测评精度会受常用词的干扰;
  3. 短译句的测评精度有时会较高;
  4. 没有考虑同义词或相似表达的情况,可能会导致合理翻译被否定;

BLEU本身就不追求百分之百的准确性,也不可能做到百分之百,它的目标只是给出一个快且不差的自动评估解决方案。



 

猜你喜欢

转载自blog.csdn.net/weixin_40240670/article/details/85112078