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) 的相关文章

  • 调整回形针大小以适合矩形框

    我有一个矩形图像 例如 30x800 像素 如何用回形针缩放它以保留 100x100 像素图像的纵横比 并用边框填充空白区域 一个例子 http www imagemagick org Usage thumbnails pad extent
  • 如何更改焦点/按下时图像按钮的色调

    我有一个ImageButton在我的应用程序中 当按钮打开时我需要更改图像的色调pressed focused 我有ImageButton设置为获取其src来自 XML 文件 如下所示
  • Tkinter:无法识别图像文件中的数据[重复]

    这个问题在这里已经有答案了 我有以下问题 我使用外部应用程序生成 GIF 文件 对我来说 GIF 看起来不错 我可以毫无问题地打开它们 然而 使用 photo PhotoImage file screenshot file self pre
  • JS - 如何将图像对象变成灰度并显示它

    基本上 当单击按钮时 它会告诉移动设备转到相机 一旦相机拍照 它就会给我图像数据 它被称为数据 URL 吗 这是我处理它的代码 var imagesrc data image jpeg base64 imageData var myimag
  • 如何使用javascript检查图像url是否为404

    使用案例 当 src 不为空并且 alt 标签不为空时 则显示 src 的图像 然后检查 src 图片 url 不是 404 当 src 为空且 alt 不为空时 显示名字的图像 当 src 和 alt 为空时显示默认图像 HTML img
  • 在 Android 上将大位图文件的大小调整为缩放的输出文件

    我的文件中有一个大位图 例如 3888x2592 现在 我想将该位图大小调整为 800x533 并将其保存到另一个文件中 我通常会通过调用来缩放位图Bitmap createBitmap方法 但它需要一个源位图作为第一个参数 我无法提供它
  • 显示居中的图像行

    我有一排三张图像 目前显示得很好 现在 我想在这三个图像的正下方显示另外两个图像 并且我希望它们居中 它看起来有点像一个颠倒的金字塔 无论我做什么 底行都保持左对齐 这是 css category width 176px font size
  • 在python中将二维数组转换为彩色图像

    我有这样的二维整数列表 list1 1 30 50 21 45 9 97 321 100 接下来我将把它转换为 numpy 数组 myarr np asarray list1 接下来我将使用 PIL 将其转换为图像 如下所示 img Ima
  • C# 代码上的 ImageURL 不显示图像

    我在 aspx 页面上有图像
  • 使用无图像按钮有哪些优点?

    讨论关于这个答案 https stackoverflow com questions 520640 how can i use googles new imageless button how could i reverse enginee
  • setImageCompressionQuality 与 setCompressionQuality 之间有什么区别 - Imagick

    我在Imagick中找到了两种设置图像压缩质量的方法 A 设置图像压缩质量 B 设置压缩质量 所以我想知道哪一个是最好的以及为什么在以下条件下 我读到了setCompressionQuality方法仅适用于新图像 我正在尝试压缩文件 jpe
  • Oracle Blob 在 PHP 页面中作为 img src

    我有一个网站当前使用文件服务器上的图像 这些图像显示在页面上 用户可以根据需要拖放每个图像 这是使用 jQuery 完成的 图像包含在列表中 每张图片都非常标准 img src network path image png height 8
  • 左对齐图像和居中文本在 div 内的同一级别?

    HTML br div class UpperTitle img src align left CableSolve Web Dashboard Version 0 1 1 div br CSS UpperTitle text align
  • Matlab 图像数据的 hist 函数

    我是 Matlab 新手 我想制作自己的函数 与 imhist 显示图像数据的直方图 完成相同的工作 但我对此完全是新手 我不知道如何做开发这样的功能 我开始做一些东西 但它非常不完整 function output args myhist
  • Javascript - 检测 Youtube 默认缩略图

    有什么方法可以查看 Youtube 缩略图是否真的存在 或者 Youtube 只是用默认缩略图替换了它 例如 没有此缩略图的视频 http img youtube com vi G75WApUdYJ4 maxresdefault jpg h
  • JavaFX:将像素写入 PixelWriter 的最快方法

    我正在寻找最快的方式来写入像素javafx scene image Image 写信给BufferedImage的后备数组要快得多 至少在我制作的测试图像上 只花了大约 20 毫秒BufferedImage WritableImage另一方
  • 必须为开发人员设定目标,即使目标不起作用[关闭]

    Closed 这个问题是无关 help closed questions 目前不接受答案 It is 大致接受 http www joelonsoftware com news 20020715 html that 设定可衡量的目标 htt
  • Java-如何将黑白图像加载到二进制中?

    我在 FSE 模式下使用 Java 和 swing 我想将完全黑白图像加载为二进制格式 最好是二维数组 并将其用于基于掩码的每像素碰撞检测 我什至不知道从哪里开始 过去一个小时我一直在研究 但没有找到任何相关的东西 只需将其读入Buffer
  • 如何提高包含大量小图像的 UCollectionView 的性能?

    在我的 iOS 应用程序中我有UICollectionView显示大约 1200 个小 35x35 点 图像 图像存储在应用程序包中 我正确地重用了UICollectionViewCell但仍然存在性能问题 具体取决于我处理图像加载的方式
  • 使用 PHP 中的 GD 库在图像上绘图

    我创建了一个代码来生成随机图案图像 它创建一个具有给定宽度和高度的图像 并用 40x40 像素的小矩形填充它 这是我的代码

随机推荐