pythontensorflowinputkerasmultiple-input

Keras multiple inputs (one input binary, other sequence)


I use GloVe embeddings to convert texts into vectors to predict a binary sentiment. I want to consider a dummy variable in my NN as well (published in winter=0, summer=1).

I read some sources on multiple inputs but I get

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>]

My network looks like this:

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())

I feel Im missing something essential but cant figure out what..

text + dummy --> binary_prediction


Solution

  • Your Concatenate call is not correct, it should be:

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