What is a recurrent neural network, and how does its hidden state act as a memory of the sequence so far? What is meant by 'unrolling' the network through time?
Sequence models and transformers, Recurrent networks
Level L1 Beginner. Length Short. Nature Th Theoretical.
What's being asked
Whether you know the basic loop of an RNN: one set of weights reused at every time step, and one hidden state passed forward.
Key idea
An RNN reads a sequence one item at a time. At step it combines the new input with its previous hidden state to make a new state . The same weights are used at every step. The hidden state is the network's running summary of everything it has read, which is how it remembers.
Steps
- Use a reading picture: you read a sentence word by word and keep a short mental summary. Each new word updates your summary. The summary is the hidden state .
- Write the loop: , starting from a fixed , often all zeros. The function has the same weights at every step, which is why one RNN can handle sequences of any length.
- Unrolling: draw the loop as a chain of copies, one per time step, with passed from each copy to the next. The picture is only a drawing of the same weights used repeatedly, not a bigger network.
- Outputs: the network can predict from each state (for example the next word) or only from the last state (for example a sentiment label for the whole sentence).
- Limits: the summary has a fixed size, so old details can fade. Gradients flowing back through many steps tend to vanish or explode, which is why LSTMs and GRUs were designed.
Common mistakes
- Thinking an unrolled RNN has separate weights for each step. The weights are shared across all steps.
- Saying the hidden state stores the whole input. It is a fixed-size compressed summary, so information can be lost.
- Confusing the hidden state (internal memory) with the output. The output is computed from the hidden state.
How long your answer should be
About 2 minutes: the reading picture, the one-line loop and the unrolled drawing.
Read this
Previous in Sequence models and transformers: none
Next in Sequence models and transformers: In a recurrent neural network, what is a "gate", and how does a number between 0 and 1 act like a tap that controls how much information passes through?