python分数运算_在Python中计算BLEU分数

5 个答案:

答案 0 :(得分:12)

BLEU分数由两部分组成,修正精度和简洁惩罚。

详细信息可以在paper中看到。

您可以使用NLTK内的nltk.align.bleu_score模块。

一个代码示例如下所示:

import nltk

hypothesis = ['It', 'is', 'a', 'cat', 'at', 'room']

reference = ['It', 'is', 'a', 'cat', 'inside', 'the', 'room']

#there may be several references

BLEUscore = nltk.translate.bleu_score.sentence_bleu([reference], hypothesis)

print BLEUscore

请注意,默认的BLEU分数使用n = 4,其中包括4克的unigrams。如果您的句子小于4,则需要重置N值,否则将返回ZeroDivisionError: Fraction(0, 0)错误。

所以,你应该像这样重置重量:

import nltk

hypothesis = ["open", "the", "file"]

reference = ["open", "file"]

#the maximum is bigram, so assign the weight into 2 half.

BLEUscore &#

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值