nltk language model (ngram) calculate the prob of a word from context

后端 未结 4 1425
遇见更好的自我
遇见更好的自我 2020-12-13 21:14

I am using Python and NLTK to build a language model as follows:

from nltk.corpus import brown
from nltk.probability         


        
4条回答
  •  长情又很酷
    2020-12-13 21:36

    As regards your second question: this happens because "b" doesn't occur in the Brown corpus category news, as you can verify with:

    >>> 'b' in brown.words(categories='news')
    False
    

    whereas

    >>> 'word' in brown.words(categories='news')
    True
    

    I admit the error message is very cryptic, so you might want to file a bug report with the NLTK authors.

提交回复
热议问题