When calling TensorFlow LSTM layer instance, why retrieve hidden state and cell state from first and third element of returns?

In assignment C5W1A3, the “Step 2: Loop through time steps” section says that using following formatting to retrieve hidden state and cell state.

next_hidden_state, _, next_cell_state = LSTM_cell(inputs=input_x, initial_state=[previous_hidden_state, previous_cell_state])

I read the documentation of TensorFlow LSTM layer in tf.keras.layers.LSTM  |  TensorFlow Core v2.6.0. It provide an example, when setting “return_state=True”, they use following code to retrieve return values.

whole_seq_output, final_memory_state, final_carry_state = lstm(inputs)

I could not find the description of thees three return values. So I guess that the first return value means prediction y in lecture, the second return value means hidden state, and the third return value means cell state.
But this is different from the usage in assignment, where the first return value means hidden state and the third return value means cell state.

I am confused about these two usages. Which one is correct?

Thank you.

1 Like

The TF LSTM API has a zillion complicated options. You can see in the example you quote that they are using return_sequences = True, which is not the default. In our case, we are using the default for that option, but setting return_state = True. They do give at least a modicum of explanation or description in the “options” section of the relevant docpage. Worth a more detailed look …

I misunderstand the “output” in the TensorFlow LSTM documentation as the prediction y hat in the lecture.

Thanks for helping.