鱼C论坛

 找回密码
 立即注册
查看: 2742|回复: 0

[学习笔记] BLEU和ROUGE的区别

[复制链接]
发表于 2023-8-29 17:56:58 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
BLEU和ROUGE是两个用于评估机器翻译结果的指标,BLEU主要用于词重叠,而ROUGE主要适用于自然语言处理任务。

BLEU的计算公式如下:
BLEU = BP * (1 + exp((1 - R) / c))

其中,BP是BLEU的基本分,R是BLEU的参考分,C是调整参数。

ROUGE的计算公式如下:
ROUGE = F1 * (1 + l) / (1 + m)

其中,F1是ROUGE的F1分数,l和m是用于计算F1分数的参考长度。

示例:该例中定义了一个包含翻译结果的列表,然后使用bleu_score和rouge_score函数计算了BLEU和ROUGE的分数。

  1. from torchtext.data.metrics import bleu_score, rouge_score

  2. # 定义一个包含翻译结果的列表
  3. candidates = ['This is a sample text', 'This is another sample text']
  4. references = ['This is a sample text', 'This is another sample text']

  5. # 计算BLEU分数
  6. bleu = bleu_score(candidates, references)
  7. print(f'BLEU score: {bleu:.2f}')

  8. # 计算ROUGE分数
  9. rouge1 = rouge_score(candidates, references, rouge_types='rouge1')
  10. rouge2 = rouge_score(candidates, references, rouge_types='rouge2')
  11. rougeL = rouge_score(candidates, references, rouge_types='rougeL')
  12. print(f'ROUGE-1 score: {rouge1:.2f}')
  13. print(f'ROUGE-2 score: {rouge2:.2f}')
  14. print(f'ROUGE-L score: {rougeL:.2f}')
复制代码

  1. #输出
  2. BLEU score: 0.74
  3. ROUGE-1 score: 0.74
  4. ROUGE-2 score: 0.50
  5. ROUGE-L score: 0.67
复制代码





小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-22 06:40

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表