Я пытаюсь построить двунаправленный LSTM.Вот как выглядит исходный код:
model1 = Sequential()
model1.add(Embedding(vocabulary_size1, 50,
weights=[embedding_matrix_passage], trainable=False))
model1.add(Bidirectional(LSTM(64)))
model1.add(Dropout(0.5))
model1.add(Dense(10, activation='softmax'))
model2 = Sequential()
model2.add(Embedding(vocabulary_size2, 50,
weights=[embedding_matrix_query],
trainable=False))
model2.add(Bidirectional(LSTM(64)))
model2.add(Dropout(0.5))
model2.add(Dense(10, activation='softmax'))
concat = concatenate([model1.output,model2.output])
x = Dense(10,name='c_dense')(concat)
out = Activation('softmax',name='c_acti')(x)
model = Model([model1.input, model2.input], out)
model.compile('adam', 'categorical_crossentropy',
metrics=['accuracy'])
model.fit([passage_padded_data,query_padded_data], np.array(labels), epochs=2, verbose=1)
Я получаю следующую ошибку, когда пытаюсь выполнить выражение соответствия:
ValueError: Error when checking target: expected c_acti to have shape (10,) but got array with shape (1,)
Когда я запустил model.summary()
сводкуМодель выглядит так:
Layer (type) Output Shape Param # Connected to
embedding_29_input (InputLayer) (None, None) 0
embedding_30_input (InputLayer) (None, None) 0
embedding_29 (Embedding) (None, None, 50) 7626350 embedding_29_input[0][0]
embedding_30 (Embedding) (None, None, 50) 1134300 embedding_30_input[0][0]
bidirectional_27 (Bidirectional) (None, 128) 58880 embedding_29[0][0]
bidirectional_28 (Bidirectional) (None, 128) 58880 embedding_30[0][0]
dropout_27 (Dropout) (None, 128) 0 bidirectional_27[0][0]
dropout_28 (Dropout) (None, 128) 0 bidirectional_28[0][0]
dense_27 (Dense) (None, 10) 1290 dropout_27[0][0]
dense_28 (Dense) (None, 10) 1290 dropout_28[0][0]
concatenate_13 (Concatenate) (None, 20) 0 dense_27[0][0]
dense_28[0][0]
c_dense (Dense) (None, 10) 210 concatenate_13[0][0]
c_acti (Activation) (None, 10) 0 c_dense[0][0]
-----------------------
Total params: 8,881,200
Trainable params: 120,550
Non-trainable params: 8,760,650
Что может быть возможным решением этой проблемы?