Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I meet an error,I do not know how to solve it ,please help me to solve it. #11

Open
rucJuanLi opened this issue Jul 14, 2017 · 6 comments

Comments

@rucJuanLi
Copy link

rucJuanLi commented Jul 14, 2017

Traceback (most recent call last):
File "textClassifierRNN_ga.py", line 187, in
create_model_gru_attention(texts_train_index,texts_test_index,label_train,label_test,word_index,embeddings)
File "textClassifierRNN_ga.py", line 174, in create_model_gru_attention
model.compile(loss='categorical_crossentropy',optimizer='rmsprop',metrics=['accuracy'])
File "/usr/local/lib/python3.4/dist-packages/keras/engine/training.py", line 915, in compile
sample_weight, mask)
File "/usr/local/lib/python3.4/dist-packages/keras/engine/training.py", line 436, in weighted
score_array = fn(y_true, y_pred)
File "/usr/local/lib/python3.4/dist-packages/keras/losses.py", line 49, in categorical_crossentropy
return K.categorical_crossentropy(y_pred, y_true)
File "/usr/local/lib/python3.4/dist-packages/keras/backend/theano_backend.py", line 1498, in categorical_crossentropy
return T.nnet.categorical_crossentropy(output, target)
File "/usr/local/lib/python3.4/dist-packages/theano/tensor/nnet/nnet.py", line 2070, in categorical_crossentropy
raise TypeError('rank mismatch between coding and true distributions')
TypeError: rank mismatch between coding and true distributions

@rucJuanLi
Copy link
Author

when I do not add the attention layer,there is not any error.But when I user the attention layer,there is the error.

@prernakhurana2
Copy link

I also face the same issue, not been able to solve it

@akbari59
Copy link

Hi
I also got the same error! anyone can help?
@richliao can you point me to any root cause?

@oxsem
Copy link

oxsem commented Jan 12, 2018

When running same script of CPU my model is compiled with no problems. On GPU, however, I am facing same issue. Could you please advice? Thanks!
finalNet.compile(optimizer=opt, loss='categorical_crossentropy', metrics=['accuracy'])
File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 899, in compile
sample_weight, mask)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/training.py", line 430, in weighted
score_array = fn(y_true, y_pred)
File "/usr/local/lib/python2.7/dist-packages/keras/losses.py", line 37, in categorical_crossentropy
return K.categorical_crossentropy(y_pred, y_true)
File "/usr/local/lib/python2.7/dist-packages/keras/backend/theano_backend.py", line 1400, in categorical_crossentropy
return T.nnet.categorical_crossentropy(output, target)
File "/usr/local/lib/python2.7/dist-packages/theano/tensor/nnet/nnet.py", line 2070, in categorical_crossentropy
raise TypeError('rank mismatch between coding and true distributions')
TypeError: rank mismatch between coding and true distributions

@liu-zg15
Copy link

i met the same problem. Have you solved it? @rucJuanLi

@zhandn
Copy link

zhandn commented Mar 19, 2018

It is because the difference between keras 1 and keras 2. I met the same problem and solved it by changing "get_output_shape_for" into "compute_output_shape" in the attention layer. However, later I met another problem and it could also be solved by https://stackoverflow.com/questions/47554275/typeerror-not-a-keras-tensor-elemwiseadd-no-inplace-0 @rucJuanLi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants