rnn-tutorial-rnnlm
rnn-tutorial-rnnlm copied to clipboard
error: multinomial in generate_sentence of RNNLM.ipynb
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!
Having the same issue. @yuanzhigang10 Could you resolve this problem?
@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.
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.