Recall & Review
beginner
What is a hidden state in recurrent neural networks (RNNs)?
A hidden state is a memory that stores information from previous inputs in a sequence. It helps the RNN remember past data to influence future predictions.
Click to reveal answer
intermediate
Why do we need to manage hidden states carefully during training in PyTorch?
Because hidden states carry information across time steps, improper management can cause errors like backpropagating through the entire history, leading to high memory use and slow training.
Click to reveal answer
intermediate
What does the method detach() do when applied to a hidden state tensor in PyTorch?
detach() stops the hidden state from tracking gradients backward beyond the current step. This prevents backpropagation through the entire sequence history.
Click to reveal answer
beginner
How do you initialize a hidden state for an RNN in PyTorch?
You create a tensor of zeros with the shape (number_of_layers, batch_size, hidden_size) and set requires_grad=False. This tensor is passed as the initial hidden state.
Click to reveal answer
intermediate
What is the difference between hidden state and cell state in LSTM networks?
The hidden state carries output information, while the cell state carries long-term memory. Both work together to help LSTM remember and forget information.
Click to reveal answer
What is the main purpose of the hidden state in an RNN?
✗ Incorrect
The hidden state stores information from previous inputs to help the RNN remember context.
In PyTorch, what does calling hidden_state.detach() do?
✗ Incorrect
detach() stops gradient tracking beyond the current step, avoiding backpropagation through the entire history.
How should you initialize the hidden state for an RNN in PyTorch?
✗ Incorrect
The hidden state must match the RNN layers and batch size, so a zero tensor with shape (layers, batch, hidden_size) is used.
What happens if you do not detach the hidden state during training?
✗ Incorrect
Without detach(), gradients flow through the entire sequence history, causing high memory use and slow training.
In LSTM, what is the role of the cell state compared to the hidden state?
✗ Incorrect
The cell state stores long-term memory, while the hidden state carries the output at each step.
Explain how hidden states are managed during training of an RNN in PyTorch and why detaching is important.
Think about how gradients flow through time and how to control that.
You got /5 concepts.
Describe the difference between hidden state and cell state in LSTM networks and their roles.
Consider how LSTM keeps information over time.
You got /5 concepts.