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 t it combines the new input xt with its previous hidden state ht−1 to make a new state ht=f(ht−1,xt). 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

  1. 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 ht.
  2. Write the loop: ht=f(ht−1,xt), starting from a fixed h0, often all zeros. The function f has the same weights at every step, which is why one RNN can handle sequences of any length.
  3. Unrolling: draw the loop as a chain of copies, one per time step, with ht passed from each copy to the next. The picture is only a drawing of the same weights used repeatedly, not a bigger network.
  4. 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).
  5. 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

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?