KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am using Python and NLTK to build a language model as follows: from nltk.corpus import brown from nltk.probability import LidstoneProbDist, WittenBellProbDist estimator = lambda fdist, bins: LidstoneProbDist(fdist, 0.2) lm = NgramModel(3, brown.words(categories='news'), estimator) # Thanks to miku, I fixed this problem print lm.prob("word", ["This is a context which generates a word"]) >> 0.00493261081006 # But I got another program like this one... print lm.prob("b", ["This is a context which generates a word"]) But it doesn't seem to work. The result is as follows: >>> print lm.prob("word", "This is a context which generates a word") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.6/dist-packages/nltk/model/ngram.py", line 79, in prob return self._alpha(context) * self._backoff.prob(word, context[1:]) File "/usr/local/lib/python2.6/dist-packages/nltk/model/ngram.py", line 79, in prob return self._alpha(context) * self._backoff.prob(word, context[1:]) File "/usr/local/lib/python2.6/dist-packages/nltk/model/ngram.py", line 82, in prob "context %s" % (word, ' '.join(context))) TypeError: not all arguments converted during string formatting Can anyone help me out? Thanks!
Tags (comma-separated)
Save Edits
Cancel