编写脚本评估
BLUE
介绍
BLEU(Bilingual Evaluation Understudy)是一种用于评估机器翻译和其他自然语言生成系统输出的自动化指标。它通过比较机器翻译的输出与一个或多个参考翻译来计算得分,得分越高表示翻译质量越好。BLEU的基本思想是计算机器翻译与参考翻译在n-gram上的重合度。
BLEU评分的计算步骤
- 分词:将机器翻译结果和参考翻译分成n-gram。
- 统计匹配的n-gram数量:计算机器翻译结果中的n-gram在参考翻译中出现的次数。
- 计算精确度:匹配的n-gram数量除以机器翻译结果中n-gram的总数。
- 加权几何平均:对不同长度的n-gram(如1-gram、2-gram、3-gram、4-gram)的精确度进行加权几何平均。
- 惩罚因子:如果机器翻译结果的长度与参考翻译结果的长度差别很大,会加入一个惩罚因子(Brevity Penalty,简称BP)来修正得分。
我们针对Dialogue prediction、Action prediction、Relationship judgment、Logical analysis进行了BLUE分数评估。
代码实现
以下为代码实现。
首先需要有candidate和reference:
# Test
candidate = ['It', 'is', 'to', 'insure', 'the', 'troops','forever',
'hearing', 'the', 'activity', 'guidebook','that', 'party', 'direct']
reference = [['It', 'is', 'a', 'guide', 'to', 'action', 'that', 'ensures', 'that',
'the', 'military', 'will', 'forever', 'heed', 'Party', 'commands'],
['It', 'is', 'the', 'guiding', 'principle', 'which', 'guarantees',
'the', 'military',