在nltk.translate的文档中,我可以清楚地看到这一点
nltk.translate.bleu_score.sentence_bleu功能可供使用。但是当我在我的脚本中使用它时,它显示了以下错误:
AttributeError: 'module' object has no attribute 'sentence_bleu'请指出我做错了什么?或者我在这中间错过的任何东西。
下面是我的示例代码以供参考:
import nltk
hypothesis = ['It', 'is', 'a', 'cat', 'at', 'room']
reference = ['It', 'is', 'a', 'cat', 'inside', 'the', 'room']
BLEUscore = nltk.translate.bleu_score.sentence_bleu([reference], hypothesis)发生此错误的原因是NLTK的版本。NLTK 3.3及以上版本支持此模块。Hava a look here
我的NLTK版本是3.1
发布于 2020-05-06 00:17:02
NLTK版本是问题所在。使用以下命令安装最新版本:
pip install nltk==3.5https://stackoverflow.com/questions/50849478
复制相似问题