keras-team / keras

Deep Learning for humans
http://keras.io/
Apache License 2.0
61.98k stars 19.46k forks source link

SimpleRNN and LSTM not run when output_dim is 1 #4124

Closed cyzhangAThit closed 7 years ago

cyzhangAThit commented 8 years ago

Hi, I am a Keras rookie. You can call me chunyue. I have installed the keras and theano successfully at the latest version with the following command :

pip install git+git://github.com/Theano/Theano.git --upgrade --no-deps pip install git+git://github.com/fchollet/keras.git --upgrade --no-deps

Today I try some codes at your blog from this link "http://benjaminbolte.com/blog/2016/keras-language-modeling.html" , and the code is attached and I got an error as follows, ''' TypeError: Cannot convert Type TensorType(float32, 3D) (of Variable Subtensor{:int64:}.0) into Type TensorType(float32, (False, False, True)). You can try to manually convert Subtensor{:int64:}.0 into a TensorType(float32, (False, False, True)). ''' After google it, I found the link "https://github.com/fchollet/keras/issues/3515" is talking my problems. So I try the code there as follows, and also got the same error information

from keras.layers import LSTM from keras.models import Sequential import numpy as np

model = Sequential() model.add(LSTM(1, input_shape=(3, 2))) model.compile(loss='mse', optimizer='sgd')

x = np.random.random((4, 3, 2)) y = np.random.random((4, 1))

model.fit(x, y)

The same error will happen when LSTM is replaced with SimpleRNN. So, What I should do to solve it? Now I just find setup the unroll=True can fix it. Best regards.

carlthome commented 7 years ago

I'm having the same issue.

farizrahman4u commented 7 years ago

Its a theano bug. You can either set unroll=True, or set output_dim=2, and get rid of the extra dim with a Lambda layer.