I am trying to use bidirectional LSTM as encoder. I set return_sequence=True
and return_state=True
and I am getting an output list with a length of 5.
# define model
inputs1 = Input(shape=(3, 1))
lstm1 = Bidirectional(merge_mode = 'ave', layer = LSTM(3, return_sequences=True, return_state = True))(inputs1)
model = Model(inputs=inputs1, outputs=lstm1)
# define input data
data = array([0.1, 0.2, 0.3]).reshape((1,3,1))
# make and show prediction
pred = model.predict(data)
length of the output of Bidirectional lstm is 5
len(pred) # 5
Shapes of all output from Bidirectional LSTM is
for num,i in enumerate(pred):
print(num, ': ',i.shape)
output
0 : (1, 3, 3)
1 : (1, 3)
2 : (1, 3)
3 : (1, 3)
4 : (1, 3)
Since it is bidirectional, I am assuming two of them are hidden states and 2 of them are cell states. Tell me the sequence. Thank you
So, I have been searching for the answers and I found it on this kaggle
encoder_outputs, forward_h, forward_c, backward_h, backward_c = enc_lstm(enc_embed)