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