hycis / bidirectional_RNN

bidirectional lstm
MIT License
153 stars 52 forks source link

imdb_birnn.py example error #9

Open stray-leone opened 8 years ago

stray-leone commented 8 years ago

When I run imdb_birnn.py first time, I got the error as below. Isn't Transform() working?

$ python imdb_birnn.py
Using gpu device 0: GeForce GTX 770
Loading data...
20000 train sequences
5000 test sequences
Pad sequences (samples x time)
train_X shape: (20000, 100)
test_X shape: (5000, 100)
Build model...
Traceback (most recent call last):
  File "imdb_birnn.py", line 64, in <module>
    model.add(Dense(word_vec_len, 100, activation='relu'))
  File "/usr/local/lib/python2.7/dist-packages/keras/layers/containers.py", line 37, in add
    self.layers[-1].set_previous(self.layers[-2])
  File "/usr/local/lib/python2.7/dist-packages/keras/layers/core.py", line 33, in set_previous
    str(self.input_ndim) + " but previous layer has output_shape " + str(layer.output_shape)
AssertionError: Incompatible shapes: layer expected input with ndim=2 but previous layer has output_shape (None, None, 256)
hycis commented 8 years ago

Are you using the latest commit? I have fixed some default argument value, most probably you have to set return_sequences=True for LSTM argument

On 14 Oct, 2015, at 8:27 am, stray-leone notifications@github.com wrote:

When I run imdb_birnn.py first time, I got the error as below. Isn't Transform() working?

$ python imdb_birnn.py Using gpu device 0: GeForce GTX 770 Loading data... 20000 train sequences 5000 test sequences Pad sequences (samples x time) train_X shape: (20000, 100) test_X shape: (5000, 100) Build model... Traceback (most recent call last): File "imdb_birnn.py", line 64, in model.add(Dense(word_vec_len, 100, activation='relu')) File "/usr/local/lib/python2.7/dist-packages/keras/layers/containers.py", line 37, in add self.layers[-1].set_previous(self.layers[-2]) File "/usr/local/lib/python2.7/dist-packages/keras/layers/core.py", line 33, in set_previous str(self.input_ndim) + " but previous layer has output_shape " + str(layer.output_shape) AssertionError: Incompatible shapes: layer expected input with ndim=2 but previous layer has output_shape (None, None, 256) — Reply to this email directly or view it on GitHub.

stray-leone commented 8 years ago

I am sure that I am using latest commit. I didn't modify anything. I just clone repo and run 'python imdb_birnn.py'

Can you give me a way of debugging Transform() function ?? Because I want to check the output dimension of Transform()

hycis commented 8 years ago

keras has restructured the code beyond my recognition. In order to use the birnn, will require the previous version. It's more of some major restructuring done to keras recently that make it not as flexible. Try mozi if you have time, I will be adding birnn to mozi also. Also I will try to see what i can do make birnn compatible with the new keras.

hycis commented 8 years ago

I think you should look keras old release https://github.com/fchollet/keras/releases/tag/0.1.3 current release adds input_shape and output_shape property and checks its sanity before get_output, while for transform, the input_shape and output_shape is only calculated at the get_output step. Which means current keras version don't have the flexibility to incorporate Transform.

stray-leone commented 8 years ago

Thank you for your kind advice I will try this way

2015년 10월 15일 (목) 오전 12:29, Alex Woo notifications@github.com님이 작성:

I think you should look keras old release https://github.com/fchollet/keras/releases/tag/0.1.3 current release adds input_shape and output_shape property and checks its sanity before get_output, while for transform, the input_shape and output_shape is only calculated at the get_output step. Which means current keras version don't have the flexibility to incorporate Transform.

— Reply to this email directly or view it on GitHub https://github.com/hycis/bidirectional_RNN/issues/9#issuecomment-148086572 .

stray-leone commented 8 years ago

And I also download mozi and try it. When you add bidirectional rnn to mozi or new keras. I will try.