添加一个辍学图层时出现问题,使用不是符号张量的输入调用了spacespace_dropout1d_5?

时间:2019-01-30 13:42:36

标签: python tensorflow keras

所以我正在使用GloVe单词嵌入

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

我评论了辍学,因为我收到警告说Keras不再支持它,我应该改用 spatialDropout1d ,这就是我所做的

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

但是我遇到此错误,而且我不知道如何修正输入使其成为张量

 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.

1 个答案:

答案 0 :(得分:2)

word_embedding_layer是一层。

您必须为这些层赋予“张量”。

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