I want to create an LSTM memory. The LSTM should predict a one-hot encoding value of length 4 given a sentence. This was easy in the first step.
The next thing, I wanted to do, is adding additional information to my dataset. The information is a one-hot encoded vector of length 5.
My idea was to concatenate the Embedding layer with another Input shape before passing the data to an LSTM. This looks like this for me:
main_input = Input(shape=(MAX_SEQUENCE_LENGTH,), dtype='int32', name='main_input')
embedding = Embedding(MAX_NB_WORDS, EMBEDDING_SIZE,
input_length=MAX_SEQUENCE_LENGTH)(main_input)
# second input model
auxiliary_input = Input(shape=(5,), name='aux_input')
x = concatenate([embedding, auxiliary_input])
lstm = LSTM(HIDDEN_LAYER_SIZE)(x)
main_output = Dense(4, activation='sigmoid', name='main_output')(lstm)
model = Model(inputs=[main_input, auxiliary_input], outputs=main_output)
But if I try to do a set up like this, I get the following error: ValueError: A Concatenate layer requires inputs with matching shapes except for the concat axis. Got inputs shapes: [(None, 50, 128), (None, 5)]
It is working for me that I create an LSTM of the embedding layer and concatenate this one the the auxiliary input but then I cannot run a LSTM anymore after (getting the erro: ValueError: Input 0 is incompatible with layer lstm_2: expected ndim=3, found ndim=2)
So my question is: What is the right way to build a LSTM with an embedding layer input with additional data in keras?
(None, 5)
to a sequence of values, shape(None, 50, 128)
. – Daniel Möller