rnn-tutorial-rnnlm icon indicating copy to clipboard operation
rnn-tutorial-rnnlm copied to clipboard

error: multinomial in generate_sentence of RNNLM.ipynb

Open yuanzhigang10 opened this issue 8 years ago • 3 comments

Thanks for this great tutorial! When I'm trying to run code within RNNLM.ipynb, I got an error in generate_sentence, witch says:

  File "mtrand.pyx", line 4811, in mtrand.RandomState.multinomial (numpy/random/mtrand/mtrand.c:32755)
ValueError: object too deep for desired array

After checking the code, I found in next_word_probs = model.forward_propagation(new_sentence), according to the returns values of forward_propagation, next_word_probs may be a combination of o, s, but np.random.multinomial(1, next_word_probs[-1]) may just want o (output). Thus, by changing to next_word_probs, _ = model.forward_propagation(new_sentence), the code can run again.

Am I getting this correctly?

Thanks!

yuanzhigang10 avatar Sep 22 '16 17:09 yuanzhigang10

Having the same issue. @yuanzhigang10 Could you resolve this problem?

Mega4alik avatar Oct 18 '16 15:10 Mega4alik

@Mega4alik You can change next_word_probs = model.forward_propagation(new_sentence) to next_word_probs, _ = model.forward_propagation(new_sentence) or next_word_probs = model.forward_propagation(new_sentence)[0], in my test it can run again.

yuanzhigang10 avatar Oct 19 '16 04:10 yuanzhigang10

I meet the same problem. model.forward_propagation(new_sentence) return o,s, but in this code, just return value to next_word_probs, so next_word_probs will to be a tuple. When we use next_word_probs in np.random.multinomial(1, next_word_probs[-1]), that means we use a 2-D array ,but np.random.multinomial() require 1-D array, so it will raise ValueError: object too deep for desired array error.

We can next_word_probs,_ = model.forward_propagation(new_sentence) or other methods to solve this problem.

zhbzz2007 avatar Jan 05 '17 10:01 zhbzz2007