Dear Group,

I was using a package named NLTK in Python.

I was trying to write a code given in section 3.8 of

http://docs.huihoo.com/nltk/0.9.5/guides/tag.html.

Here, in the >>> test = ['up', 'down', 'up'] if I put more than 3 values and trying to write the reciprocal codes, like,

        sequence = [(t, None) for t in test] and print '%.3f' % (model.probability(sequence))

I am getting an error as,

Traceback (most recent call last): File "", line 1, in model.probability(sequence) File "C:Python27libsite-packagesnltktaghmm.py", line 228, in probability return 2**(self.log_probability(self._transform.transform(sequence))) File "C:Python27libsite-packagesnltktaghmm.py", line 259, in log_probability alpha = self._forward_probability(sequence) File "C:Python27libsite-packagesnltktaghmm.py", line 694, in _forward_probability alpha[0, i] = self._priors.logprob(state) + File "C:Python27libsite-packagesnltkprobability.py", line 689, in logprob elif self._prob_dict[sample] == 0: return _NINF ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

If any learned member may kindly assist me how may I solve the issue. Regards, Subhabrata.

asked Apr 06 '13 at 15:53

Subhabrata%20Banerjee's gravatar image

Subhabrata Banerjee
40222224


One Answer:

The ValueError you're getting is often the result of trying to evaluate an array in a conditional. For example,

import numpy as np
if np.array([True, False]):
    print 'oh no!'

will give you a similar error. Are you sure you've properly instantiated the model? I was unable to replicate your error, with the following code. Did you mean something else when you said more than three values?

>>> test = ['up', 'up', 'down', 'down']
>>> sequence = [(t, None) for t in test]
>>> print '%.3f' % (model.probability(sequence))
0.014

answered Apr 10 '13 at 12:37

Max%20Likely's gravatar image

Max Likely
1112

Your answer
toggle preview

powered by OSQA

User submitted content is under Creative Commons: Attribution - Share Alike; Other things copyright (C) 2010, MetaOptimize LLC.