0
0
PyTorchml~5 mins

nn.LSTM layer in PyTorch - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the nn.LSTM layer in PyTorch do?
The nn.LSTM layer processes sequences of data by remembering information over time. It helps models learn patterns in sequences like sentences or time series.
Click to reveal answer
beginner
What are the main inputs and outputs of an nn.LSTM layer?
Input: a sequence of data with shape (sequence_length, batch_size, input_size). Output: the hidden states for each time step and the final hidden and cell states.
Click to reveal answer
intermediate
Why does nn.LSTM have both hidden state and cell state?
The hidden state carries short-term memory, while the cell state carries long-term memory. This helps the LSTM remember important information over many steps.
Click to reveal answer
beginner
How do you initialize an nn.LSTM layer for input size 10 and hidden size 20?
Use nn.LSTM(input_size=10, hidden_size=20). This sets the input feature size to 10 and the hidden layer size to 20.
Click to reveal answer
intermediate
What does setting batch_first=True do in nn.LSTM?
It changes the input and output shape to (batch_size, sequence_length, input_size), which can be easier to work with when batches come first.
Click to reveal answer
What shape does nn.LSTM expect for its input by default?
A(input_size, sequence_length, batch_size)
B(batch_size, input_size, sequence_length)
C(batch_size, sequence_length, input_size)
D(sequence_length, batch_size, input_size)
What are the two states returned by nn.LSTM besides the output?
Ahidden state and cell state
Binput state and output state
Cweight state and bias state
Dactivation state and dropout state
What does the hidden_size parameter control in nn.LSTM?
AThe batch size
BThe number of features in the hidden state
CThe length of the input sequence
DThe number of layers
If batch_first=True, what is the input shape for nn.LSTM?
A(batch_size, input_size, sequence_length)
B(sequence_length, batch_size, input_size)
C(batch_size, sequence_length, input_size)
D(input_size, batch_size, sequence_length)
Why is nn.LSTM better than a simple RNN for long sequences?
ABecause it can remember information longer using cell state
BBecause it uses convolution layers
CBecause it has fewer parameters
DBecause it does not use activation functions
Explain how nn.LSTM processes a sequence of data step-by-step.
Think about how information flows through time steps and how memory is kept.
You got /4 concepts.
    Describe the difference between hidden state and cell state in nn.LSTM and why both are important.
    Consider how remembering recent vs. older information helps understanding sequences.
    You got /3 concepts.