Given that I'm not very experienced with this, the following may well be a silly question (and the title equally beside the point, any suggestions for modification are welcome). I'm trying to get a Keras Model to work with multiple inputs, but keep running into problems with the input dimension(s). Quite possibly the setup of my network makes only little sense, but I first would like to produce something that works (i.e. executes) and then experiment with different setups. Here's what I have now:
sent = Input(shape=(None,inputdim))
pos = Input(shape=(None,1))
l1 = LSTM(40)(sent)
l2 = LSTM(40)(pos)
out = concatenate([l1, l2])
output = Dense(1, activation='sigmoid')(out)
model = Model(inputs=[sent, pos], outputs=output)
model.compile(optimizer='rmsprop',
loss='binary_crossentropy',
metrics=['accuracy'])
print('X1 shape:', np.shape(X1_train))
print('X1 Input shape:', np.shape(sent))
print('X2 shape:', np.shape(X2_train))
print('X2 Input shape:', np.shape(pos))
model.fit([X1_train, X2_train], Y_train, batch_size=1, epochs=nrEpochs)
This gets me the following output/error:
Using TensorFlow backend.
INFO: Starting iteration 1 of 1...
INFO: Starting with training of LSTM network.
X1 shape: (3065,)
X1 Input shape: (?, ?, 21900)
X2 shape: (3065, 1)
X2 Input shape: (?, ?, 1)
Traceback (most recent call last):
...
ValueError: Error when checking input: expected input_1 to have 3 dimensions,
but got array with shape (3065, 1)
If I understand things correctly (which I'm not at all sure about :), Input
basically converts the input to a tensor, adding a third dimension (in my case), but the input I feed the model when doing model.fit()
is still two-dimensional. Any ideas on how to go about this are very welcome.