Я реализовал модель LSTM, используя keras для построения системы QA, например:
encoder_inputs = tf.keras.Input(shape=(None, EMBEDDING_SIZE), name='encoder_inputs')
encoder_lstm = tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(units=HIDDEN_UNITS, return_state=True, name='encoder_lstm'))
encoder_outputs, forward_h, forward_c, backward_h, backward_c = encoder_lstm(encoder_inputs)
encoder_state_h = tf.keras.layers.Concatenate()([forward_h, backward_h])
encoder_state_c = tf.keras.layers.Concatenate()([forward_c, backward_c])
encoder_states = [encoder_state_h, encoder_state_c]
decoder_inputs = tf.keras.Input(shape=(None, num_decoder_tokens), name='decoder_inputs')
decoder_lstm = tf.keras.layers.LSTM(units=HIDDEN_UNITS*2, return_state=True, return_sequences=True, name='decoder_lstm')
decoder_outputs, _, _ = decoder_lstm(decoder_inputs, initial_state=encoder_states)
decoder_dense = tf.keras.layers.Dense(units=num_decoder_tokens, activation='softmax', name='decoder_dense')
decoder_outputs = decoder_dense(decoder_outputs)
model = tf.keras.Model([encoder_inputs, decoder_inputs], decoder_outputs)
Затем я хотел добавить вектор topi c lda_inputs в модели, чтобы улучшить качество системы. Я попытался объединить тензор topi c с decoder_inputs , например:
encoder_inputs = tf.keras.Input(shape=(None, EMBEDDING_SIZE), name='encoder_inputs')
lda_inputs = tf.keras.Input(shape=(None, EMBEDDING_SIZE), name='lda_inputs')
encoder_lstm = tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(units=HIDDEN_UNITS, return_state=True, name='encoder_lstm'))
encoder_outputs, forward_h, forward_c, backward_h, backward_c = encoder_lstm(encoder_inputs)
encoder_state_h = tf.keras.layers.Concatenate()([forward_h, backward_h])
encoder_state_c = tf.keras.layers.Concatenate()([forward_c, backward_c])
encoder_states = [encoder_state_h, encoder_state_c]
decoder_inputs = tf.keras.Input(shape=(None, num_decoder_tokens), name='decoder_inputs')
the_inputs = tf.keras.layers.concatenate([lda_inputs,decoder_inputs],-1)
decoder_lstm = tf.keras.layers.LSTM(units=HIDDEN_UNITS*2, return_state=True, return_sequences=True, name='decoder_lstm')
decoder_outputs, _, _ = decoder_lstm(the_inputs, initial_state=encoder_states)
decoder_dense = tf.keras.layers.Dense(units=num_decoder_tokens, activation='softmax', name='decoder_dense')
decoder_outputs = decoder_dense(decoder_outputs)
model = tf.keras.Model([encoder_inputs, decoder_inputs, lda_inputs], decoder_outputs)
Однако код неверный. Как я мог изменить это?
Вот краткое изложение модели: model.summary
Спасибо!