Open rucJuanLi opened 7 years ago
when I do not add the attention layer,there is not any error.But when I user the attention layer,there is the error.
I also face the same issue, not been able to solve it
Hi I also got the same error! anyone can help? @richliao can you point me to any root cause?
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
i met the same problem. Have you solved it? @rucJuanLi
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
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