3
$\begingroup$

I am trying to perform concatenation on the Bidirectinal LSTM layer. I have my model defined like this:

embedding_layer=Embedding(words,300,input_length=trainDataVecs.shape[1],weights=[embedding_matrix])

LSTM_word_1 = Bidirectional(LSTM(80, activation='tanh', dropout_W = 0.25, dropout_U = 0.25,return_sequences=True))
model1 = Input(shape=(trainDataVecs.shape[1],),dtype='int32')
embedded_sequences1=embedding_layer(model1)
lstm_word_out_1 = LSTM_word_1(embedded_sequences1)

LSTM_word_2 = Bidirectional(LSTM(80, activation='tanh', dropout_W = 0.25, dropout_U = 0.25,return_sequences=True))
model2 = Input(shape=(trainDataVecs.shape[1],),dtype='int32')
embedded_sequences2=embedding_layer(model2)
lstm_word_out_2 = LSTM_word_2(embedded_sequences2)

conc=concatenate([MaxPooling1D()(lstm_word_out_1),AveragePooling1D()(lstm_word_out_2)])

outp = Dense(classes_num, activation='sigmoid')(conc)
model=Model(input=[model1,model2],output=outp)

I am fitting like this:

history=model.fit(trainDataVecs,Y_train,shuffle=True,batch_size=512,epochs=10,validation_data=(valDataVecs,valid_Y))

But I am getting the error like: ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 2 array(s), but instead got the following list of 1 arrays PS: The training and validation vectors are arrays. But still I am getting the error. I think it might be because of the model definition but I am not sure.

$\endgroup$
0
$\begingroup$

Your network has two Inputs, so you need to pass in two arrays. From the rest of the code, perhaps you want to pass the same data through both strands, in which case you can just duplicate the input:

history=model.fit([trainDataVecs, trainDataVecs], ...
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.