Keras 多个输入(一个输入二进制,另一个序列)



我使用 GloVe 嵌入将文本转换为向量来预测二进制情绪。我还想在我的 NN 中考虑一个虚拟变量(在冬季发布=0,夏季=1(。

我在多个输入上阅读了一些来源,但我得到

ValueError: Unexpectedly found an instance of type `<class 'keras.layers.merge.Concatenate'>`. Expected a symbolic tensor instance. .... Layer output was called with an input that isn't a symbolic tensor. Received type: <class 'keras.layers.merge.Concatenate'>. Full input: [<keras.layers.merge.Concatenate object at 0x7f2b9b677d68>]

我的网络如下所示:

sequence_input = Input(shape=(MAX_SEQUENCE_LENGTH,), dtype='int32')
embedded_sequences = embedding_layer(sequence_input)
dummy= Input(shape=(1,), dtype='int32', name='dummy')
x = Conv1D(100, 20, activation='relu')(embedded_sequences) # filter= 100, kernel=20
x = MaxPooling1D(5)(x)  # reduces output to 1/5 of original data by taking only max values
x = Conv1D(100, 20, activation='relu')(x)
x = GlobalAveragePooling1D()(x)  # global max pooling
x = Dropout(0.5)(x)
x = Dense(100, activation='relu')(x)
combined = Concatenate([x, dummy])
preds = Dense(1, activation='sigmoid',name='output')(combined) 
model = Model(inputs=[sequence_input,dummy], outputs=[preds])
print(model.summary())

我觉得我错过了一些重要的东西,但不知道是什么..

文本+假人--> binary_prediction

您的Concatenate调用不正确,应该是:

combined = Concatenate()([x, dummy])

相关内容

  • 没有找到相关文章

最新更新