# 3.6 Bleu 得分（选修）（Bleu Score (optional)）

机器翻译（**machine translation**）的一大难题是一个法语句子可以有多种英文翻译而且都同样很好，常见的解决办法是通过一个**BLEU**得分（**the BLEU score**）的东西来解决，BLEU得分是一个有用的单一实数评估指标，用于评估生成文本的算法，判断输出的结果是否与人工写出的参考文本的含义相似

一般有多个人工翻译：

[![](https://github.com/fengdu78/deeplearning_ai_books/raw/master/images/5e854a803e36991a6e0dd4e33ecab930.png)](https://github.com/fengdu78/deeplearning_ai_books/blob/master/images/5e854a803e36991a6e0dd4e33ecab930.png)

BLEU得分做的就是给定一个机器生成的翻译，它能够自动地计算一个分数来衡量机器翻译的好坏。只要机器生成的翻译与任何一个人工翻译的结果足够接近，那么它就会得到一个高的BLEU分数。**BLEU**代表**bilingual evaluation understudy**(双语评估替补)。且这些人工翻译的参考会包含在开发集或是测试集中

假设机器翻译 (**MT**)的输出是：**the the the the the the the，**&#x662F;一个十分糟糕的翻译。衡量机器翻译输出质量的方法之一是**观察输出结果的每一个词，看其是否出现在参考中**，这被称做是机器翻译的精确度（**a precision of the machine translation output**）。这个情况下，机器翻译输出了七个单词并且这七个词中的每一个都出现在了参考1或是参考2，因此输出的精确度就是7/7，分母为机器翻译单词数目，分子为相应单词是否出现在参考翻译中。但是，这种方法很不科学，并不可取

改良后的精确度评估方法（**the modified precision measure**）：**把每一个单词的记分上限定为它在参考句子中出现的最多次数**。在参考1中，单词**the**出现了两次，在参考2中，单词**the**只出现了一次。单词**the**的得分上限为2。输出句子的得分为2/7，分母是7个词中单词**the**总共出现的次数，分子是单词**the**出现的计数，在达到**上限**时截断计数

上述都只是关注单独的单词，在**BLEU**得分中，另外一种更科学的打分方法是**bleu score on bigrams（二元词组）**，bigram的意思就是相邻的两个单词

定义**截取计数**（**the clipped count**），也就是**Count\_clip：**&#x7ED9;算法设置得分上限，上限值为二元词组出现在参考1**或**2中的最大次数

假定机器翻译输出了稍微好一点的翻译，对MT output进行分解，得到的bigrams及其出现在MT output中的次数count为：

[\
![](https://github.com/fengdu78/deeplearning_ai_books/raw/master/images/0bc25316900ccd1d4dd25a35ec7c45c4.png)](https://github.com/fengdu78/deeplearning_ai_books/blob/master/images/0bc25316900ccd1d4dd25a35ec7c45c4.png)

相应的bigrams precision为4/6也就是2/3，为二元词组改良后的精确度

将改良后的一元词组精确度定义为$$P\_1$$，$$P$$代表的是精确度。下标1的意思是一元词组，即考虑单独的词，$$P\_n$$ 定义为$$n$$元词组精确度，用**n-gram**替代掉一元词组。即机器翻译输出中的$$n$$元词组的**countclip**之和除以$$n$$元词组的出现次数之和

![](https://github.com/fengdu78/deeplearning_ai_books/raw/master/images/7f48951acf8ca7c7b63f6c4c455ada18.png)

如果机器翻译输出与参考1或是参考2完全一致，那么所有的$$P\_1$$、$$P\_2$$等等的值，都会等于1.0

最终的BLEU得分：

将得到的$$P\_1$$，$$P\_2$$， $$P\_3$$...$$P\_n$$ 相加再取平均值

BLEU得分被定义为：

$$
p=exp (\frac{1}{n}\sum\limits\_{i=1}^{n}{P\_i})
$$

[![](https://github.com/fengdu78/deeplearning_ai_books/raw/master/images/0f9646d825a0c254376e094b48523ed3.png)](https://github.com/fengdu78/deeplearning_ai_books/blob/master/images/0f9646d825a0c254376e094b48523ed3.png)

然后用BP（“简短惩罚”brevity penalty） 的惩罚因子（the BP penalty）来调整。它能够惩罚输出了太短翻译结果的翻译系统：

$$
p=BP\cdot exp(\frac1n\sum\_{i=1}^np\_i)
$$

BLEU得分被用来评估许多生成文本的系统（systems that generate text），比如说机器翻译系统（machine translation systems），图像描述系统（image captioning systems）。不过它并没有用于语音识别（speech recognition）。因为在语音识别当中，通常只有一个答案


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://baozoulin.gitbook.io/neural-networks-and-deep-learning/di-wu-men-ke-xu-lie-mo-xing-sequence-models/di-wu-men-kexulie-mo-578b28-sequence-models/di-san-zhou-xu-lie-mo-xing-he-zhu-yi-li-ji-zhi-ff08-sequence-models-and-attention-mechanism/36-bleu-de-fen-ff08-xuan-xiu-ff09-ff08-bleu-score-optional.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
