I'm trying to do a seq2seq model with and encoder LSTM and decoder LSTM, both with Bidirectional layers.
I can pass the hidden state and memory cell forward to the decoder LSTM, but I can't see how I'd possibly pass the values back from the decoder to the encoder.
def sequence_model(total_words, emb_dimension, lstm_units):
# Encoder
encoder_input = Input(shape=(None,), name="Enc_Input")
x = Embedding(total_words, emb_dimension, input_length=max_sequence_length, name="Enc_Embedding")(encoder_input)
x, state_h, state_c, _, _ = Bidirectional(LSTM(lstm_units, return_state=True, name="Enc_LSTM1"), name="Enc_Bi1")(x) # pass hidden activation and memory cell states forward
encoder_states = [state_h, state_c] # package states to pass to decoder
# Decoder
decoder_input = Input(shape=(None,), name="Dec_Input")
x = Embedding(total_words, emb_dimension, name="Dec_Embedding")(decoder_input)
x = LSTM(lstm_units, return_sequences=True, name="Dec_LSTM1")(x, initial_state=encoder_states)
decoder_output = Dense(total_words, activation="softmax", name="Dec_Softmax")(x)
func_model = tf.keras.Model(inputs=[encoder_input,decoder_input], outputs=decoder_output)
return func_model
The forward states are passed to the initial_state of the decoder LSTM layer. But if I wrap this Dec_LSTM1 layer with a Bidirectional Layer, it doesn't like me passing the initial_state value in and breaks.
Am I right in thinking I don't need the backwards states from the encoder LSTM layer?
Attached is an image of the architecture I'm trying to achieve.
