I have two different datasets and I would like to try multi-task learning. My problem is that all the examples I could find have two different training inputs, but the labels are the same. My question is: can I have different labels? This is my code right now:
input1 = Sequential()
input1.add(Embedding(vocabulary_size, embedding_size,
input_length=longest_sen_input1))
input1.add(Bidirectional(LSTM(units=embedding_size)))
input1.add(Dense(len(document), activation='softmax'))
input2 = Sequential()
input2.add(Embedding(vocabulary_size, embedding_size,
input_length=longest_sen_input2))
input2.add(Bidirectional(LSTM(units=embedding_size)))
input2.add(Dense(len(document), activation='softmax'))
model = Sequential()
model.add(Merge([input1, input2], mode='sum'))
model.add(Dense(len(document), activation='softmax'))
model.compile(loss='categorical_crossentropy',optimizer='adam')
model.fit([X_train_input1, X_train_input2], [Y_train_input1, Y_train_input2], epochs=100)
I try to insert [Y_train_input1, Y_train_input2], but I have this error:
Error when checking model target: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 1 array(s), but instead got the following list of 2 arrays: [array([[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 1., 0., 0.],
[0., 0., 0., ..., 0., 0., 0....
Does anybody know how to perform multitask learning with two inputs (X_train_input1/Y_train_input1 and X_train_input2/Y_train_input2) returning a common prediction?
EDIT My model seems to work now, I simply changed
model.fit([X_train_input1, X_train_input2], [Y_train_input1, Y_train_input2], epochs=100)
in
model.fit([X_train_input1, X_train_input2], Y_train, epochs=100)
but then I try to test the model like this
multitask_model.predict_classes(X_test)
and I have this error:
ValueError: Error when checking model : 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: [array([[ 0, 0, 0, ..., 13, 8, 134],
[ 0, 0, 0, ..., 33, 87, 19],
[ 0, 0, 0, ..., 27, 1, 4],
...,
[ 0, 0, 0, ..., 1, 10, 8],
[ 0...
What am I missing?