懶得在介紹來龍去脈了,反正就是找到的**全是這種:
import nltk
hypothesis = ' '.join(['it', 'is', 'a', 'cat', 'at', 'room'])
reference = ' '.join(['it', 'is', 'a', 'cat', 'inside', 'the', 'room'])
#there may be several references
merteor_score = nltk.translate.meteor_score.single_meteor_score(reference, hypothesis)
print(merteor_score)
簡單來說就是
hypothesis和
reference都是字串,然後我就一直報這個錯:typeerror: "hypothesis" expects pre-tokenized hypothesis (iterable[str]): it is a cat at room。看起來是型別問題,然後找了一通,全都是用的字串,最後沒辦法了看了眼原始碼,說要求是格式,我覺得應該是set型別吧,然後就把
hypothesis和reference改成了set,然後就可以了,就emmm,我還費勁巴拉改一晚上,難道是nltk版本更新所以資料格式換了?
改後**:
import nltk# from nltk.corpus import wordnet
# nltk.download('wordnet')
hypothesis = ['it', 'is', 'a', 'cat', 'at', 'room']
reference = ['it', 'is', 'a', 'cat', 'inside', 'the', 'room']
hypothesis=set(hypothesis)
reference=set(reference)
#there may be several references
merteor_score = nltk.translate.meteor_score.single_meteor_score(reference, hypothesis)
print(merteor_score)
python中首次安裝使用nltk
1.在cmd命令提示符視窗中輸入 pip install nltk 2.首次輸入python 時,import nltk text welcome readers.i hope you find it interesting.please do reply.需要加空格 from nltk.token...
NLTK學習筆記
學習參考書 nltk.set proxy com 80 nltk.download 2.使用sents fileid 函式時候出現 resource tokenizers punkt english.pickle not found.please use the nltk to obtain the...
NLTK學習筆記
學習參考書 nltk.set proxy com 80 nltk.download 2.使用sents fileid 函式時候出現 resource tokenizers punkt english.pickle not found.please use the nltk to obtain the...