简体   繁体   中英

Problem with adding a dropout layer, Layer spatial_dropout1d_5 was called with an input that isn't a symbolic tensor?

So I am using GloVe word embeddings

emb = Glove(emb_filename)
word_embedding_layer = emb.get_keras_embedding(#dropout = 0.5,
                                            trainable = True,
                                            input_length = sent_maxlen, 
                                           name='word_embedding_layer')

I commented dropout since I got a warning that its no longer supported in Keras and I should use spatialDropout1d instead and that's what I did

word_embedding_layer = keras.layers.SpatialDropout1D(0.5)(word_embedding_layer)

However I am getting this error and I don't know how to fix my input to make it a tensor

 ValueError: Layer spatial_dropout1d_5 was called with an input that isn't a symbolic tensor. Received type: <class 'keras.layers.embeddings.Embedding'>. Full input: [<keras.layers.embeddings.Embedding object at 0x7f4a42989358>]. All inputs to the layer should be tensors.

word_embedding_layer is a layer.

You must give a "tensor" to the layers.

input_tensor = Input(some_shape)
embedding_tensor = word_embedding_layer(input_tensor)
dropout_output = keras.layers.SpatialDropout1D(0.5)(embedding_tensor)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM