How a network remembers

11 slides · speaker notes · the deck · present it

Recurrent networks
001

How a network remembers

hhowanetworkremembers

Today one idea: a network that carries something from one word to the next. Everything else — LSTMs, the trouble with long sentences, even why recurrence is back in fashion — follows from that loop.

002

A feed-forward network has no yesterday

one word at a timeThecatsatonthematthis worda guessThecatsatonthematthe words before— nothing —the same input gives the same guess, whatever came before it

Feed a sentence to an ordinary network one word at a time and watch: each word goes in, a guess comes out, and nothing stays. 'The' after 'sat on' and 'The' at the start get the same answer. For language that is hopeless — what a word means depends on what came before it.

Language arrives in order, and the order matters.

003

Add a loop: the state

h, back in with the next wordRNN cellW · x + U · hytxThecatsatontheh — the state after each worda vector of numbers, changed by every word

The fix is one arrow. Whatever the cell computed — we call it h, the state — goes back in with the next word. Two weight matrices: W for the new word, U for what we carried. The bars on the right are h: a handful of numbers that every word nudges.

004

Unrolled in time: one cell, copied

cell=cellThey1h1cellcaty2h2cellsaty3h3cellony4h4cellthey5the same weights W and U at every steptime →

Draw the loop out in time and it becomes a chain. It is not five networks — it is one cell, the same W and U, used five times. That is why it takes a sentence of any length, and it is also the picture we need for training.

One cell, the same weights, as many steps as the sentence is long.

005

What the state holds

Thekeystothecabinetareonthetableone unit: “the subject is plural”the hidden state after each word — most units change all the time; this one waits for its verb

So what does h hold? Nobody tells it. Train it only to predict the next word, and look inside: most units flicker with every word, but some hold one fact for as long as it matters. 'The keys to the cabinet are' — the network has to remember 'keys' is plural across 'cabinet'. Linzen and colleagues showed LSTMs doing exactly that; Karpathy found cells that track open quotes.

Trained to predict the next word, a unit learns to wait for the verb.

006

Learning: backpropagation through time

t1t2t3t4t5t6Lthe error×1×0.55×0.30×0.17×0.09×0.05forward: the statebackward: how much each step is to blame — a product of factors, one per step

To learn, we use the chain we just drew. Run forward, measure the error at the end, and send the blame back through every step — backpropagation through time. Look at the numbers: each step back multiplies the gradient by another factor.

Blame is passed back step by step — and every step multiplies it.

007

Why it forgets: vanishing and exploding gradients

×100×10×1×0.1×0.01010203040steps back in timea factor of 1.1 per step: explodesexactly 1: the signal survives0.9 per step: vanishes×0.04 after 30 steps

Multiply by 0.9 thirty times and you have four per cent left; by 1.1 and you have seventeen times as much. That is the whole problem with plain RNNs: the error from a word thirty steps away either vanishes or blows up. Hochreiter saw it in 1991, Bengio and colleagues in 1994. Clipping tames the explosion; the vanishing needs a new cell.

Thirty steps back, the signal is gone — or it is everything.

008

LSTM: a memory with gates

c — the cell's memory, carried along×forget gatewhat to erase+input gatewhat to write→output gatewhat to read outh — what the next layer sees

The LSTM's answer: keep a second, separate memory — the belt on top — and change it only by adding. Three gates, each a small network with values between zero and one, decide: forget erases what is no longer needed, input writes what is new, output decides what the rest of the network gets to see. Along the belt the gradient is not squeezed at every step.

The memory is added to, not multiplied — so the signal can travel far.

009

Attention: look back instead of carrying

Thekeystothecabinetare0.040.580.050.040.26recurrent: one state, handed on word by wordattention: “are” looks back at every word directly, and weighs them

Then came a different idea: instead of squeezing everything into one state, let 'are' look back at every word and decide which ones matter — here, 'keys'. Attention started as help for recurrent translators in 2014; in 2017 the Transformer threw the recurrence away. The price: memory that grows with the length of the text.

Why carry everything, if you can look it up?

010

Recurrence returns

1990Elmana network with a state1997LSTMa memory with gates2014GRU · seq2seqand attention2017Transformerattention only2021S4state-space models2023Mamba · RWKVrecurrence, trained in parallel2024xLSTM · minLSTMthe LSTM, revisitedthe loop comes back: linear time, a fixed-size state

And now the loop is back. For very long inputs attention's growing memory hurts, and a fixed-size state looks good again. State-space models, Mamba, RWKV, xLSTM, even stripped-down 'minLSTM' — recurrent at heart, trained in parallel. The idea from 1990 still has legs.

Long contexts made the fixed-size state attractive again.

011

Remember the loop

If you remember one picture, make it the loop. The rest is what happens when you try to train it, and what people built when it did not work. Read Chris Olah's post on LSTMs tonight — it is the best fifteen minutes on the topic.