What does the output of nn.lstm mean?

Hi,

in pytoch docs, lstm outputs output, (h_n, c_n)
which

  • output of shape (seq_len, batch, num_directions * hidden_size): …
  • h_n of shape (num_layers * num_directions, batch, hidden_size): tensor containing the hidden state for t = seq_len.Like output , the layers can be separated using…
  • c_n (num_layers * num_directions, batch, hidden_size): tensor containing the cell state for t = seq_len

then in output, what is batch in (seq_len, batch, num_directions * hidden_size)
is that mean my model’s batch_size?
if so, output[:, 0, :] is the first batch of the lstm output?

1 Like

Yes exactly.

Best regards

Thomas

@tom how is output(hidden state) different from h_n(hidden state). Both seem to be the hidden state, thus I am getting here.

Thanks in advance! :slight_smile: