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

Keras multiple inputs (one input binary, other sequence)

我使用 GloVe 嵌入将文本转换为向量来预测二元情绪。我也想在我的 NN 中考虑一个虚拟变量(发布于 winter=0,summer=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])