nltk.translate.meteor_score module使用方法

nltk.translate.meteor_score module使用方法

编辑于2024/07/16

METEOR(Metric for Evaluation of Translation with Explicit ORdering)是另一种用于评估机器翻译和自然语言生成任务的指标。可以通过 nltk 调用函数 meteor_score 来计算。

然而,网上关于 nltk.translate.meteor_score module 的使用方法大都过时了,在较新版本的 nltk 中按照错误方法使用,会报错:

TypeError: "hypothesis" expects pre-tokenized hypothesis (Iterable[str]):

正确示例如下:

from nltk.translate.meteor_score import meteor_score


reference1 = "this is an apple".split()
reference2 = "that is an apple".split()

hypothesis1 = "an apple on this tree".split()
hypothesis2 = "a red color fruit".split()

print(round(meteor_score([reference1, reference2], hypothesis1),4))
print(round(meteor_score([reference1, reference2], hypothesis2),4))

"""
输出:
0.6233
0.0
"""
  • 首先,reference 和 hypothesis 文本必须先解析为以单词/词元为元素的 Interable 结构(如 list)
  • 其次,即使只有一个 reference,也要将其作为 list 的元素传入 meteor_score,而不能直接传入 reference
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值