LSTM Output Shape Calculator
Calculate the output shape of a PyTorch LSTM layer. Enter input size, hidden size, number of layers, and bidirectional flag to get exact output dimensions.
Built by Michael Lip
Frequently Asked Questions
What is the LSTM output shape in PyTorch?
For input [batch, seq_len, input_size], the LSTM output shape is [batch, seq_len, hidden_size * num_directions] where num_directions is 2 if bidirectional=True, else 1. The hidden state h_n has shape [num_layers * num_directions, batch, hidden_size].
How does bidirectional affect LSTM output?
Setting bidirectional=True doubles the last dimension of the output. A bidirectional LSTM with hidden_size=256 outputs features of size 512 (256*2). The hidden state also doubles in the first dimension.
How many parameters does an LSTM have?
An LSTM layer has 4 * ((input_size * hidden_size) + (hidden_size * hidden_size) + hidden_size * 2) parameters per layer. For additional layers, input_size becomes hidden_size * num_directions. Multiply by num_layers and num_directions.
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 and maintained by Michael Lip. For questions or feedback, email [email protected].