Recurrent neural networks: carrying a hidden state along a sequence
10 questions on parameter sharing along a sequence, the hidden state, unrolled copies, and how an encoder and decoder translate a sentence of variable length.
- 10 questions
- Stopwatch
- Instant feedback
Sample questions
Play now ↑Answers stay hidden. Start the quiz to play them.
Sample 1
An RNN reads a sentence of 12 words and then one of 40 words. How many separate sets of weights does it use for the steps?
- 12 and 40 respectively
- One set, shared by all the steps in both cases
- 52
How it works
- One question per screen. An answer is final once sent.
- You see right away whether you were right, with a short explanation.
- The stopwatch runs: on equal scores, the faster player ranks first.
- Only your best attempt counts, so replaying is never risky.
About this quiz
Sentences come in all lengths, and an ordinary network has a fixed number of inputs. A word that means something in one position probably means the same thing in another, yet an ordinary network would have to relearn it for every position. A recurrent neural network answers both problems with one idea: read the sequence one element at a time, using the same small network at each step, and pass a hidden summary of everything read so far from one step to the next. Before transformers took over, this was the standard way to process language, and it is still a good way to understand what a sequence model must do.
This quiz introduces the idea and walks through one of its best-known uses, translation. You will see why sharing the weights across the steps handles sequences of any length and also reduces the number of parameters, in the same spirit as the weight sharing in convolutional networks. You will see what goes into each step, the current word and the previous hidden state, and what comes out, an output word and a new hidden state. You will meet the way a chain of copies of the network is drawn, and the usual starting value of the hidden state.
Translation shows the architecture at work. The whole input sentence is fed in, followed by a special start token that tells the network to begin the output. While the input is being read, the outputs are ignored and the network is just building up a summary; afterwards, it produces the translation one word at a time, feeding each word it generates back in as the next input, until it emits a stop token. You will see why the first part is called an encoder and the second a decoder, and in what sense the decoder is autoregressive.
Common misunderstandings include thinking that each step has its own weights, that the hidden state is the output, and that the input and output sentences must be the same length. In fact, the same weights are reused at each step, the hidden state is an internal memory, and the lengths can differ freely.
The quiz suits learners who know feed-forward networks and want to meet sequence models, and practitioners curious about the history of language models. It needs no mathematics. There are 10 questions, each with an explanation, and it takes about four minutes. Even though transformers have largely replaced recurrent networks, the ideas introduced here live on. The hidden state as a running summary, the encoder and decoder as two phases of a task, the feeding back of generated words and the use of special start and stop tokens all reappear in modern language models. Seeing them in their original, simpler form makes later architectures easier to read, and it explains the design choices that attention was introduced to improve on.
Questions and answers
›How long does the quiz take?
About 3 to 4 minutes for 10 questions, at roughly 20 seconds each. An explanation follows every answer, so you can follow the story step by step.
›Do I need to know about transformers?
No. Recurrent networks came first, and the quiz stands on its own. If you have taken the quiz on word embeddings, you will know how words become vectors, but the questions here only need the idea that each word is given as a vector.
›What is a recurrent neural network?
It is a network that processes a sequence one step at a time, with the same weights at every step, and carries a hidden state from one step to the next. At each step it takes the current element and the previous hidden state as input and produces an output and a new hidden state. Chaining copies of the network gives the architecture its name.
›Why share the weights across steps?
A concept that appears at one place in a sequence is likely to mean the same thing elsewhere, an equivariance reminiscent of that for images. Sharing the weights captures it, greatly reduces the number of free parameters, and lets the network handle sequences of different lengths, since the same step can be repeated as often as needed.
›What is the hidden state?
It is a vector that summarises what the network has seen so far, passed from step to step. It starts at a default value, such as a vector of zeros. It acts as the network's memory, and it plays a role analogous to the hidden variables in a hidden Markov model.
›How does an RNN translate a sentence?
The complete input sentence is fed in, followed by a special start token. During training, the network learns to associate the start token with the beginning of the output sentence. Each generated word is fed back as the next input, and the network produces a stop token to signal that the translation is complete.
›What are the encoder and the decoder?
The first stages, which absorb the input sentence, form the encoder, and their outputs are ignored. By the end, the whole input has been compressed into one hidden state. The remaining stages are the decoder, which generates the translation one word at a time.
›In what sense is the decoder autoregressive?
Each output word is fed as input to the next stage, so every word is generated conditional on those before it. This mirrors the autoregressive decomposition of a sequence into a product of conditional distributions, one for each element given its predecessors.