PacktPublishing / Deep-Learning-with-Keras

Code repository for Deep Learning with Keras published by Packt
MIT License
1.06k stars 716 forks source link

Dropout layer error in transfer_glove_embeddings.py #14

Closed ulisesvid closed 6 years ago

ulisesvid commented 6 years ago

Hi all!

I am trying to replicate the model of transfer_glove_embeddings.py. When I try to execute the model I gel the following error:

`--------------------------------------------------------------------------- TypeError Traceback (most recent call last)

in () 8 weights=[embedding_weights], 9 trainable=True)) ---> 10 model.add(SpatialDropout1D(Dropout(0.2))) 11 model.add(Conv1D(filters=NUM_FILTERS, kernel_size=NUM_WORDS, 12 activation="relu")) ~/.virtualenvs/negative-scoring/lib/python3.6/site-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs) 89 warnings.warn('Update your `' + object_name + 90 '` call to the Keras 2 API: ' + signature, stacklevel=2) ---> 91 return func(*args, **kwargs) 92 wrapper._original_function = func 93 return wrapper ~/.virtualenvs/negative-scoring/lib/python3.6/site-packages/keras/layers/core.py in __init__(self, rate, **kwargs) 162 @interfaces.legacy_spatialdropout1d_support 163 def __init__(self, rate, **kwargs): --> 164 super(SpatialDropout1D, self).__init__(rate, **kwargs) 165 self.input_spec = InputSpec(ndim=3) 166 ~/.virtualenvs/negative-scoring/lib/python3.6/site-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs) 89 warnings.warn('Update your `' + object_name + 90 '` call to the Keras 2 API: ' + signature, stacklevel=2) ---> 91 return func(*args, **kwargs) 92 wrapper._original_function = func 93 return wrapper ~/.virtualenvs/negative-scoring/lib/python3.6/site-packages/keras/layers/core.py in __init__(self, rate, noise_shape, seed, **kwargs) 99 def __init__(self, rate, noise_shape=None, seed=None, **kwargs): 100 super(Dropout, self).__init__(**kwargs) --> 101 self.rate = min(1., max(0., rate)) 102 self.noise_shape = noise_shape 103 self.seed = seed TypeError: '>' not supported between instances of 'Dropout' and 'float'` Any ideas? thanks in advanced
ulisesvid commented 6 years ago

Just had to remove argument Drop(): model.add(SpatialDropout1D(0.2)) instead of model.add(SpatialDropout1D(Dropout(0.2)))

t0nghe commented 5 years ago

Thanks Ulises. I ran into the same problem. Indeed it says in the documentation that SpatialDropout1D only takes a rate as argument.

AlexGriffiths commented 5 years ago

Thank you! That was driving me mad!