Rnn output hidden structure


For a multi-layer bi-directional RNN, I would like to retrieve the last hidden state of the top layer for the forward and backward directions, respectively. The hidden state output from RNN is of size (num_layers * num_directions, batch, hidden_size), so I wonder how is the first dimension (num_layers * num_directions) indexed so I can retrieve the hidden states I want? Thanks!

1 Like

Did you get a solution to this please reply, I am also interested in the meaning of the 1st dimension.

I figured out once but now I forgot…

the above post might help