Gradient LabStart the lesson

Lessons › Chapter 10: Sequences and text

Recurrent networks

Language comes in order. A recurrent network reads a sentence one word at a time, from left to right, just as you do.

Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.

Start the interactive lesson

Step by step

Story

Reading in order

Leo tries an early design that reads each customer message one word at a time.

Concept

Read one word at a time

Language comes in order. A recurrent network reads a sentence one word at a time, from left to right, just as you do.

Key idea

Carry a memory forward

After each word it updates a small memory, the hidden state (yellow), and passes it to the next step. The same little network is reused at every step.

Build

Predict what comes next

At the end, the memory is turned into a prediction, like the next word: after “the cat sat on the”, it guesses “mat”.

Problem

Long sentences fade

Squeezed through the same small memory again and again, information about early words fades, like a whisper passed down a line. In a long paragraph the first words are nearly forgotten.

Real life

In real life: next-word suggestions

The three suggested words above your phone keyboard come from a model reading what you’ve typed so far and predicting what comes next. Recurrent networks powered many of these for years; newer keyboards often use small transformers.

Quick check: What does a recurrent network pass from one step to the next?

The hidden state carries a summary of everything read so far.

Pseudocode

memory = empty
for each word in the sentence:
    memory = update(memory, word)     # the same small network every step
prediction = output(memory)

# trouble: the memory of early words fades in long sentences

Key terms

recurrent network
A network that reads a sequence one step at a time, carrying a memory forward.
hidden state
The memory a recurrent network carries from one step to the next.

In the news

Recent models and papers that build on this idea: