2016-01-06 50 views
5

我以前在nltk中使用過NgramModel類,沒有錯誤。但是,我最近更新了nltk到version 3.1,我不能再找到NgramModel類。當我嘗試導入像往常一樣:nltk NgramModel錯誤

from nltk.model import NgramModel

我得到的錯誤

ImportError: No module named 'nltk.model'

是否NgramModelmodel模塊最近被更換?

+1

直到NgramModel穩定後,您可以嘗試https://github.com/kpu/kenlm及其python包裝。 – alvas

回答

6

這是open issue,因爲bugs

這問題指出:

If you're currently using the version from github, you can switch to the "model" branch, which includes the NgramModel code, though it's currently significantly behind the "develop" branch and hasn't picked up all the newest bug fixes.

到模型分支的聯繫是here

+2

謝謝!由於缺陷,您是否會建議切換到具有相同語言模型功能的另一個模塊? – istewart

+1

@istewart如果這些錯誤並沒有打擾到你,那麼你可以將'model'模塊添加到你本地的NLTK安裝中。這樣你就可以擁有新的NLTK功能和你想要的'NGramModel'。 YMMV,但。 – erip

+1

更新:我只是更新如預期,現在'NgramModel'進口罰款。但是,在建立語言模型之後,我嘗試計算熵,並得到以下錯誤: 「File」/Library/Python/2.7/site-packages/nltk/model/ngram.py「,第171行,以概率 return self._probdist.prob((context,word)) AttributeError:'NgramModel'對象沒有屬性'_probdist'' 所以我想我會使用另一種語言模型類,如果可能的話。 – istewart