textClassifier icon indicating copy to clipboard operation
textClassifier copied to clipboard

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

Open rucJuanLi opened this issue 7 years ago • 6 comments

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 avatar Jul 14 '17 07:07 rucJuanLi

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

rucJuanLi avatar Jul 17 '17 08:07 rucJuanLi

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

prernakhurana2 avatar Aug 24 '17 06:08 prernakhurana2

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

akbari59 avatar Dec 29 '17 17:12 akbari59

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

oxsem avatar Jan 12 '18 18:01 oxsem

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

liu-zg15 avatar Jan 23 '18 12:01 liu-zg15

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

zhandn avatar Mar 19 '18 06:03 zhandn