Image captioning评价方法之BLEU (bilingual evaluation understudy)

2023-05-16

文章地址:BLEU: a Method for Automatic Evaluation of Machine Translation

代码地址(非官方):https://github.com/tylin/coco-caption

该评价方法是IBM发表于ACL2002上。从文章命名可以看出,文章提出的是一种双语评价替补,"双语评价(bilingual evaluation)"说明文章初衷提出该评价指标是用于机器翻译好坏的评价指标,"替补(understudy)"说明文章想提出一种有效的评价指标进而帮助人类来快速评价翻译结果的好坏。

翻译结果的好坏,指的是翻译的结果与人类翻译的结果是否尽可能的相似。

下面来看看该评价指标是如何来做到的。在说明该评价计算方法之前先说明两个概念,一个是生成的翻译内容下文称为candidate translation,一个是人工标注或者说是人工翻译内容称为reference translation。

为了更好的说明,先定义一些字符,对于一条输入i,candidate translation为 c i c_i ci, reference translation有多个为一个集合 R i = { r i 1 , r i 2 , . . . , r i j , . . . r i m } R_i=\{r_{i1},r_{i2},...,r_{ij},...r_{im}\} Ri={ri1,ri2,...,rij,...rim}, 一个n元组n-gram为由n个有顺序的单词组成的序列, c o u n t k count_k countk为计算k元组(k-gram)在candidate translation/ reference translation中的出现次数。

一、 Modified n-gram precision

1.1 modified unigram precision的引入

本文提出的评价方法的基石是precision measure。

准确率的计算如下:

  1. 定义任何一个reference translation(reference translation可能存在多个,即有多个人工翻译)包含candidate translation中的某个字,那么这个candidate translation中的字为预测正确的字。

  2. 计算出所有预测正确的字的个数作为分子,所有candidate translation中的字的个数作为分母,这样得到的值为candidate translation的准确率。

在准确率基础上,文章改进了一版,称为modified unigram precision。

modified unigram precision的计算如下(写法与原文有点不太一样,但是更好理解):

  1. 计算candidate translation中每个字相同的个数,记为$ Count_i$,i表示candidate translation中不同字的id
  2. 分别计算所有reference translation中每一条翻译,每个字相同的个数,记为 R e f _ C o u n t i j Ref\_Count_{ij} Ref_Countij(对于id为i这个字来说,j表示第j条reference translation),然后对每个字的个数在reference translation中取最大值,即 R e f _ C o u n t i = m a x ( R e f _ C o u n t i j ) Ref\_Count_{i}=max(Ref\_Count_{ij}) Ref_Counti=max(Ref_Countij)
  3. 利用2中计算出来的 R e f _ C o u n t i Ref\_Count_{i} Ref_Counti去对 C o u n t i Count_i Counti进行裁剪,即 C o u n t c l i p i = m i n ( C o u n t i , R e f _ C o u n t i ) Count_{clip_i}=min(Count_i, Ref\_Count_{i}) Countclipi=min(Counti,Ref_Counti)
  4. m o d i f i e d   u n i g r a m   p r e c i s i o n = ∑ i ∈ C C o u n t c l i p i l e n ( C ) modified\ unigram\ precision=\frac{\sum_{i\in C}Count_{clip_i}}{len(C)} modified unigram precision=len(C)iCCountclipi,式中C表示candidate translation,i表示candidate translation中不同的字,len表示求总的字的个数

上述解释看起来比较绕,举个例子来说明 (下面例子统计单词数时都是忽略大小写的):

Example 1:

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.

如果这种情况用precision来计算,candidate translation只有一种字就是the,而不管是reference1还是reference2只要一个中包含the,那么the就是预测正确的字,预测正确的字的个数为7,candidate translation总的字数为7,所有precision就为7/7。

如果采用modified unigram precision来计算

  1. C o u n t i = 7 Count_i=7 Counti=7,且因为这个例子特殊,candidate translation中只有一种字,所有id只有一类。
  2. 在Reference 1中,the出现两次,那么 R e f _ C o u n t i 1 = 2 Ref\_Count_{i1}=2 Ref_Counti1=2,在Reference 2中,the出现一次,那么 R e f _ C o u n t i 2 = 1 Ref\_Count_{i2}=1 Ref_Counti2=1,最后 R e f _ C o u n t i = m a x ( R e f _ C o u n t i 1 , R e f _ C o u n t i 2 ) = 2 Ref\_Count_{i}=max(Ref\_Count_{i1}, Ref\_Count_{i2})=2 Ref_Counti=max(Ref_Counti1,Ref_Counti2)=2.
  3. C o u n t c l i p i = m i n ( C o u n t i , R e f _ C o u n t i ) = m i n ( 7 , 2 ) = 2 Count_{clip_i}=min(Count_i, Ref\_Count_{i})=min(7, 2)=2 Countclipi=min(Counti,Ref_Counti)=min(7,2)=2
  4. m o d i f i e d   u n i g r a m   p r e c i s i o n = ∑ i ∈ C C o u n t c l i p i l e n ( C ) = 2 / 7 modified\ unigram\ precision=\frac{\sum_{i\in C}Count_{clip_i}}{len(C)}=2/7 modified unigram precision=len(C)iCCountclipi=2/7

同理,再举一个例子:

Example 2:

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

下面只计算modified unigram precision:

对于Candidate 1来说

  1. C o u n t i Count_i Counti即各个预测字的个数,用字典表示每个单词的情况{it: 1, is: 1, a: 1, guide: 1, to: 1, action: 1, which: 1, ensures: 1, that: 1, the: 3, military: 1, always: 1, obeys: 1, commands: 1, of : 1, party: 1},则 C o u n t i = 18 Count_i=18 Counti=18
  2. 计算 R e f _ C o u n t i Ref\_Count_{i} Ref_Counti
    1. 在Reference 1中, R e f _ C o u n t i 1 Ref\_Count_{i1} Ref_Counti1用字典表示每个单词的情况{it: 1, is:1, a: 1, guide: 1, to: 1, action:1, which: 0, ensures: 1, that: 2, the: 1, military: 1, always: 0, obeys: 0, commands: 1, of: 0, party: 1 }。
    2. 在Reference 2中, R e f _ C o u n t i 2 Ref\_Count_{i2} Ref_Counti2用字典表示每个单词的情况{it: 1, is: 1, a: 0, guide: 0, to: 0, action: 0, which: 1, ensures: 0, that: 0, the: 4, military: 1, always: 1, obeys: 0, commands: 0, of : 1, party: 1}。
    3. 在Reference 3中, R e f _ C o u n t i 3 Ref\_Count_{i3} Ref_Counti3用字典表示每个单词的情况{it: 1, is: 1, a: 0, guide: 1, to: 1, action: 0, which: 0, ensures: 0, that: 0, the: 4, military: 0, always: 1, obeys: 0, commands: 0, of : 1, party: 1}。
    4. 最后 R e f _ C o u n t i Ref\_Count_{i} Ref_Counti用字典表示每个单词的情况为{it: 1, is: 1, a: 1, guide: 1, to: 1, action: 1, which: 1, ensures: 1, that: 2, the: 4, military: 1, always: 1, obeys: 0, commands: 1, of : 1, party: 1}
  3. 计算 C o u n t c l i p i = m a x ( R e f _ C o u n t i 1 , R e f _ C o u n t i 2 ) Count_{clip_i}=max(Ref\_Count_{i1}, Ref\_Count_{i2}) Countclipi=max(Ref_Counti1,Ref_Counti2),用字典表示每个单词的情况{it: 1, is: 1, a: 1, guide: 1, to: 1, action: 1, which: 1, ensures: 1, that: 1, the: 3, military: 1, always: 1, obeys: 0, commands: 1, of : 1, party: 1}, C o u n t c l i p i = 17 Count_{clip_i}=17 Countclipi=17
  4. m o d i f i e d   u n i g r a m   p r e c i s i o n = ∑ i ∈ C C o u n t c l i p i l e n ( C ) = 17 / 18 modified\ unigram\ precision=\frac{\sum_{i\in C}Count_{clip_i}}{len(C)}=17/18 modified unigram precision=len(C)iCCountclipi=17/18

同理对于Candidate2来说也可以计算出 m o d i f i e d   u n i g r a m   p r e c i s i o n = ∑ i ∈ C C o u n t c l i p i l e n ( C ) = 8 / 14 modified\ unigram\ precision=\frac{\sum_{i\in C}Count_{clip_i}}{len(C)}=8/14 modified unigram precision=len(C)iCCountclipi=8/14

1.2 modified n-gram precision的引入

上述是 unigram的情况,更为通用的是采用n-gram的情况来计算,用公式表示为

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 ′ ) p_n=\frac{\sum_{C\in\{Candidates\}}\sum_{n-gram\in C}Count_{clip}(n-gram)}{\sum_{C'\in\{Candidates\}}\sum_{n-gram'\in C'}Count(n-gram')} pn=C{Candidates}ngramCCount(ngram)C{Candidates}ngramCCountclip(ngram)

这个式子只是上面unigram的拓展,因为对于一次翻译系统的测试来说,输入可能是多个待翻译的句子,输出也是多个,所以评价这个测试系统是从整个数据集来的,所以存在 ∑ C ∈ { C a n d i d a t e s } \sum_{C\in\{Candidates\}} C{Candidates}。而后面的 ∑ n − g r a m ∈ C \sum_{n-gram\in C} ngramC也是上面 ∑ i ∈ C \sum_{i\in C} iC的扩展,因为n-gram表示所有元组为n的个数。上述是分子的构成,同理分母也是 l e n ( C ) len(C) len(C)的扩展,相对于分子要求每个元组的 C o u n t c l i p i = m i n ( C o u n t i , R e f _ C o u n t i ) Count_{clip_i}=min(Count_i, Ref\_Count_{i}) Countclipi=min(Counti,Ref_Counti)(这里i表示一个元组),分母只需要求所有元组的总数即可。

1.3 modified n-gram precision的合并方式

文章采用五个翻译系统-两个人三个翻译机器,翻译的结果采用n-gram来计算,如下图所示

在这里插入图片描述

上图展示了modified n-gram precision随着n的增加,呈指数衰减,为了方面不同n取值时的n元组(n取1,2,3,4时)评测结果能够进行合并,得到平均的结果,在合并前将各个评测结果采用log来计算。

二、 翻译输出的长度对于评测指标的影响

生成的翻译既不能太长也不能太短,实际上modified n-gram precisions已经考虑了这种情况,例如n-gram precision会惩罚生成虚假词(reference translations没有出现的词),并且也会惩罚一个词出现的次数比reference translations中最大的出现次数还多的情况。但是还没有对很好的考虑合适的翻译长度,如下面例子:

Example 3:

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 translation很短,对于modifified unigram precision=2/2,对于modifified bigram precision(2-gram)=1/1。从上面结果来看,只考虑准确率,那么这个翻译结果在评测指标上可以取得很好的结果。所以还需要考虑recall的情况。

2.1 recall的计算困难

在例子3中,可以看出,考虑召回很重要。但是不同于其他任务,翻译任务的reference translation有多个,recall不太好计算。举下面例子来说明。

Example 4:

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.

可以看出从翻译好坏来讲,candidate 1明显不如candidate 2,但是由于存在多个reference translation的情况,candidate1召回单词数比candidate2要多。所以recall在这种情况下不是很好计算。

2.2 Sentence brevity penalty

例子4的情况,在算modified n-gram precisions时,由于句子太长,会受到相应的惩罚,所以这里不需要去考虑长句子的评价问题。所以文章引入一个名叫brevity penalty的乘法因子,用于惩罚例子3这种过短句子的情况。

当candidate长度与任何一个reference长度一样时则不对precision进行惩罚,即brevity penalty为1.0。如candidate的长度为12,reference长度有12,15,17,那么brevity penalty为1.0。这里我们定义与candidate长度最接近的reference长度称为**“best match length”**。

考虑到reference有多个的情况,brevity penalty计算如下,计算测试集所有有效reference translation长度的和记为r(有效长度指的是为各个candidate对应的"best match length")。brevity penalty的指数衰减参数为r/c,c为整个数据集所有candidate translation长度的和。

三、 BLEU

BLEU的计算公式如下:

B L E U = B P ⋅ e x p ( ∑ n = 1 N w n l o g p n ) BLEU=BP\cdot exp(\sum^N_{n=1}w_nlogp_n) BLEU=BPexp(n=1Nwnlogpn)

B P = { 1 , i f c > r e ( 1 − r / c ) , i f c ≤ r BP = \left \{ \begin{aligned} 1, \quad if \quad c>r \\ e^{(1-r/c)}, \quad if \quad c \leq r \end{aligned} \right. BP={1,ifc>re(1r/c),ifcr

式中, w n w_n wn 1 / N 1/N 1/N

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Image captioning评价方法之BLEU (bilingual evaluation understudy) 的相关文章

  • 使用 Laravel Intervention 库缓存动态图像不起作用

    我目前正在使用 Laravel 5 并利用干预图像集成 http image intervention io http image intervention io 我动态地使用它 因此图像具有如下 URL http example org
  • 如何从浮点数组创建新的 QImage

    我有一个代表图像的浮点数数组 列在前 我想在 QGraphicsSecene 上将图像显示为 QPixmap 为了做到这一点 我尝试使用 QImage 构造函数 QImage const uchar data int width int h
  • 使用 docx4j 从带有 Base64 图像的 HTML 生成 .docx

    我正在尝试生成一个 docx from a HTML字符串与docx4j in Java 其中包含 Base64 图像 目前 我能够生成 Word 并下载它 在 Vaadin 项目内 但图像无法正确插入 但是 如果我把HTML代码写入一个索
  • jquery 在单击的实例之后查找下一个图像

    我正在尝试建立一个图像库 您可以在其中单击拇指 然后可以使用下一个和上一个按钮 我的问题是用户最初可以单击我需要检测的任何图像以及下一个或上一个图像的锻炼 并将显示 src 替换为下一个图像的 src 我只是想让下一个按钮首先工作 因为前一
  • 如何在Android中没有Intent且没有任何视图窗口的情况下拍照

    大家好 我正在尝试弄清楚如何通过按下按钮来拍照 而不显示任何预览 我的想法是 我想要拍摄并保存照片 但之前或之后没有照片的视觉预览 到目前为止 我能够获取拍照并将其保存到磁盘的代码 没有任何问题 但如果没有表面视图或预览 我似乎无法做到这一
  • 使用 Javascript 旋转图像

    首先 我目前正在使用 JQuery 因此 JQuery 解决方案可行 我想将图像旋转动态 X 度 每秒计算一次 现在我用这个完美地工作了Jquery旋转插件 http code google com p jqueryrotate 图像每秒完
  • 使用 CSS3 在屏幕上移动图像

    我浏览网页已经有一段时间了 试图找到一种方法 让图标在加载页面时移动到屏幕上 从左侧移动到 body div 的中心 如何才能做到这一点 这是我到目前为止所拥有的 CSS3 a rotator text decoration none pa
  • 以表格形式连续调用/评估?

    大家好 简单的问题 使用 XLISP 编写程序 但我似乎遇到了一个我似乎无法解决的简单基本问题 也许有人有一个快速解决方案 我正在尝试编写一个 if 语句 该语句的 then 子句评估多种形式并返回最后一种形式的值 在示例中 setq PO
  • 在表单中突出显示选定的图像 - 使用 Jquery?

    我在谷歌上搜索了答案 但发现什么也没有 所以即使是一个显示如何执行以下操作的页面的链接也将不胜感激 基本上我有一个只有图像的表格
  • 如何从本地计算机或网络资源在 Jupyter Notebook 中嵌入图像或图片?

    我想将图像包含在 jupyter 笔记本中 如果我执行以下操作 它会起作用 from IPython display import Image Image img picture png 但我想将图像包含在 markdown 单元格中 并且
  • C# 计算图像差异

    我怎样才能生成一个System Drawing Image包含其他两个图像的像素之间的差异 类似的东西确实如此 但是用 C 编写 The 算法 https github com Phrogz context blender blob mas
  • PHP 中的 imagecolortransparent 不起作用

    我想改变图像中的白色 http www arso gov si vreme napovedi 20in 20podatki radar gif http www arso gov si vreme napovedi 20in 20podat
  • Google API 返回的 Google+ 个人资料图片网址是否会发生变化?

    因此 我使用 Google API 通过用户的 user id 来获取人们的个人资料图片 Google API 返回如下 JSON image url https lh5 googleusercontent com OGjgCn9fCPk
  • 使用 OpenCV 和 Python 叠加两个图像而不丢失颜色强度

    如何叠加两个图像而不损失两个图像的颜色强度 我有图像1和图像2 2 我尝试使用 0 5 alpha 和 beta 但它给我的合并图像的颜色强度只有一半 dst cv2 addWeighted img1 0 5 img2 0 5 0 但是当我
  • 如何从 url Codenameone 创建图像

    我需要从具有图像 url 的字符串创建一个新的 Image 实例 E g http maps gstatic com mapfiles place api icons restaurant 71 png http maps gstatic
  • 检测植物图片中的所有分支

    我想知道有什么可以检测下图中的所有绿色树枝 目前我开始应用 Frangi 过滤器 options struct FrangiScaleRange 5 5 FrangiScaleRatio 1 FrangiBetaOne 1 FrangiBe
  • CoreData:是否将图像存储到数据库?

    我正在制作一个应用程序 它从网站上为某些用户名拍摄照片 并将其显示在带有用户名的 UITable 中 然后当单击用户名时 它会显示该用户的照片 然后单击照片名称 它会显示全屏照片 我的问题是我正在使用 NSData 从互联网获取照片 我必须
  • PHP - 获取base64图像字符串解码并保存为jpg(生成空图像)

    嗨 我实际上是通过 ajax 发送一个 base64 图像字符串到一个 php 脚本 该脚本只是解码字符串并将内容保存为 jpg 文件 但结果是一张空图像 这怎么可能 PHP脚本 uploadedPhotos array photo 1 p
  • react-native - 图像需要来自 JSON 的本地路径

    你好社区 我正在react native中开发一个测试应用程序 并尝试从本地存储位置获取图像 我实际在做什么 我将图像直接链接源提供给 var 并在渲染函数中调用此方法 react 0 14 8 react native 0 23 1 np
  • 在 Excel 中使用 VBA 设置图像透明度

    有没有办法使用 VBA 脚本对图像应用一些透明度 我录制了一个 宏 但似乎没有录制艺术效果 我已经找到了如何制作形状 但没有找到图像 这需要几个步骤 将自选图形 如矩形 放置在工作表上 使用以下方法将您的实际图片嵌入矩形中 ShapeRan

随机推荐