2016-01-06 62 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