Learn Before
Example
Seq2SeqEncoder Output Shapes
For a minibatch of sequence inputs with a batch size of 4 and 9 time steps, a two-layer GRU encoder with 16 hidden units produces two tensors:
- The
enc_outputstensor of shape(num_steps, batch_size, num_hiddens) = (9, 4, 16), representing the top-layer hidden states at every time step. - The
enc_statetensor of shape(num_layers, batch_size, num_hiddens) = (2, 4, 16), containing the multilayer hidden states at the final time step only.
Since GRUs use a single hidden state vector (unlike LSTMs, which also maintain a separate memory cell), the state tensor has exactly three dimensions.
0
1
Updated 2026-06-23
Tags
D2L
Dive into Deep Learning @ D2L