04 · 1997 · A network with memory

Recurrent network (LSTM)

Everything so far looks at its whole input at once. Language arrives one piece at a time, and what a word means depends on what came before. A recurrent network reads in order and carries a memory (its hidden state) from one step to the next.

The LSTM, invented by Sepp Hochreiter and Jürgen Schmidhuber in 1997, adds three gates that decide what to forget, what to write and what to reveal. This one has 112 memory cells and learned to predict the next letter from the element stories on OneLab’s Periodic Table.

How it works

  1. Read a letter. It enters as a one-hot vector (a single 1 among zeros) alongside the previous memory.
  2. Gates decide. The forget gate wipes cells it no longer needs, the input gate lets new information in, and the output gate chooses what to show.
  3. Update memory. Each cell keeps a running value between −1 and +1 (the strip below). Cells often specialise in things like “inside a number” or “start of a sentence”.
  4. Predict. The visible part of the memory is turned into a probability for every possible next letter.

Try it

runs in your browser

Text so far

—

Memory cells (each square = one cell, blue negative · amber positive)

Gates (dark = closed, bright = open)

Next letter guesses

Press ▶ Run to feed in the prompt one letter at a time.

Things to try

Why gates?

Plain recurrent networks forget quickly because the learning signal fades as it travels back through many steps (the vanishing gradient from the last page). The LSTM’s memory cell is a protected channel where information can survive for hundreds of steps.

Where they were used

For about 20 years LSTMs powered speech recognition, handwriting recognition, machine translation and predictive keyboards on billions of phones, before transformers largely took over language.

This model

112 LSTM cells, about 60,000 weights, trained for a few minutes on roughly 26,000 characters. It writes element-story-sounding text, makes up words, and gets facts wrong: it learned the style, not the chemistry.