GRU Output Shape Calculator

Calculate PyTorch GRU output and hidden state shapes. Enter input size, hidden size, num layers, and batch size to get exact output dimensions instantly.

Built by Michael Lip

Frequently Asked Questions

What is the output shape of a PyTorch GRU?

A PyTorch GRU returns two tensors: output of shape (seq_len, batch, num_directions*hidden_size) and h_n of shape (num_layers*num_directions, batch, hidden_size). With batch_first=True, output becomes (batch, seq_len, num_directions*hidden_size).

What is the difference between GRU and LSTM?

GRU has 2 gates (reset and update) while LSTM has 3 gates (input, forget, output) plus a cell state. GRU merges the cell state and hidden state into one, making it simpler with fewer parameters. GRU trains faster but LSTM can capture longer dependencies.

How does bidirectional affect GRU output shape?

With bidirectional=True, num_directions=2. The output last dimension doubles to 2*hidden_size. The h_n first dimension doubles to num_layers*2. For example, a 2-layer bidirectional GRU with hidden_size=256 produces output [..., 512] and h_n of shape [4, batch, 256].

How do I initialize GRU hidden state?

The initial hidden state h_0 should have shape (num_layers*num_directions, batch_size, hidden_size). If not provided, PyTorch initializes it to zeros. For bidirectional GRUs, the first dimension is num_layers*2.

Is this tool free?

Yes. All HeyTensor tools are free, run in your browser, and require no signup.

About This Tool

This tool is part of HeyTensor, a free suite of PyTorch and deep learning utilities. All calculations run entirely in your browser — no data is sent to any server. The source code is open on GitHub.

Contact

HeyTensor is built by Michael Lip. Email [email protected] for feedback.

Based on real data from our PyTorch Error Database — 52 errors analyzed from Stack Overflow