所以我正在使用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.
答案 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)