属性错误:'模块'对象没有属性'sentine_bleu'。

问题描述 投票:0回答:1

在 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及以上版本。请看一下 此处

我的NLTK版本是3.1

python nltk attributeerror bleu
1个回答
0
投票

问题出在NLTK的版本上。使用安装最新版本。

pip install nltk==3.5
© www.soinside.com 2019 - 2024. All rights reserved.