我正在运行一段代码,从文本语料库中获取困惑,ngram的数量。在执行此操作时,我收到一个奇怪的错误:
C:\Users\Rosenkrantz\Documents\NetBeansProjects\JavaApplication2>python ai7.py
C:\Users\Rosenkrantz\Documents\NetBeansProjects\JavaApplication2>python ai7.py
47510
203044
308837
Traceback (most recent call last):
File "ai7.py", line 95, in <module>
tt=NgramModel(1, tText, estimator)
File "C:\Python27\lib\site-packages\nltk\model\ngram.py", line 81, in __init__
assert(isinstance(pad_left, bool))
AssertionError我正在运行的代码是:
f_in = open("science.txt", 'r');
ln = f_in.read()
words = nltk.word_tokenize(ln)
tText = Text(words)
tt=NgramModel(1, tText, estimator)
tt1=NgramModel(2, tText1, estimator)
tt2=NgramModel(3, tText2, estimator)所有的导入似乎都是正确的。
发布于 2012-11-22 08:50:45
您确定正在使用正确的参数调用NgramModel吗?看一下source for the current version of NLTK,NgramModel看起来像这样:
def __init__(self, n, train, pad_left=True, pad_right=False,
estimator=None, *estimator_args, **estimator_kwargs): 这似乎与您调用函数的方式不匹配。您的代码中的estimator是什么?因为您当前将estimator作为pad_left参数进行传递。
https://stackoverflow.com/questions/13503660
复制相似问题