我正在尝试使用 NLTK 运行 N-Gram 语言建模代码,该代码取自 https://www.geeksforgeeks.org/n-gram-language-modelling-with-nltk/。但它抛出一个错误。
# generate frequency of n-grams
freq_bi = FreqDist(bigram)
freq_tri = FreqDist(trigram)
d = defaultdict(Counter)
for a, b, c in freq_tri:
if(a != None and b!= None and c!= None):
d[a, b] += freq_tri[a, b, c]
我得到的错误如下,
`AttributeError Traceback (most recent call last)
<ipython-input-12-ae7c0728f2d6> in <module>
3 print(freq_tri[a,b,c])
4 if(a != None and b!= None and c!= None):
----> 5 d[a, b] += freq_tri[a, b, c]
AttributeError: 'int' object has no attribute 'items' `
完整代码可在site