CS 460G · W12L3 · the gentle version

Recurrent networks, explained without the algebra

One idea, one picture at a time. There are exactly two formulas in here, both at the end, and you do not need them to follow the story.

Companion to the full technical page — this one is the “why”, that one is the “how”.
The whole lecture, in one picture: you are reading a sentence with a small notepad. After every word, you scribble something on the notepad based on what you just read and what was already written. When the sentence ends, whatever is on that notepad — not the sentence — is what the network has to answer with.

1Why anything needs to change

A normal network sees a snapshot. Language is a film.

A classifier that we have built so far does one thing extremely well: it looks at a fixed-size thing and gives one answer. A 32×32 image goes in, “cat” comes out. A row of six measurements goes in, “diabetic” comes out. The size is fixed before the network is even built.

Now hand it “the dog bit the man”. Then hand it “the man bit the dog”. Same six words, same letters, completely different meaning. If your network only sees a bag of words, these two sentences are identical inputs. It cannot possibly answer differently.

A BAG OF WORDS dog bit man = man bit dog identical IN ORDER dog → bit → man ≠ man → bit → dog different
The same three words, two meanings. Nothing about the words changed — only their order. Any model that throws the order away has thrown away the answer.

And there is a second problem, less philosophical and more annoying: sentences have no fixed length. “Yes.” is a sentence. So is a 60-word paragraph. A network built around a fixed input size has to be rebuilt for every length, which is obviously not how anything real works.

2The lunchbox problem

Why you cannot just “make the input bigger”.

Here is the naive fix: decide that every input is exactly 10 words. Pad short sentences with blanks, chop long ones. It works for a demo and fails immediately in reality — the 11th word of a long sentence is gone, and a sentence of 3 words is 70% padding.

Worse, the network that eats this lunchbox has no idea that position 1 and position 2 are related. Feed it “not good” and “good not” padded to the same 10 slots and it sees two different bags of the same tokens. Every word is processed alone, in parallel, with no notion that one came before another.

FIXED INPUT: 4 SLOTS the dog bit the … and then? man ← there is no slot 5 Pad to 4 → you lose words. Widen to 40 → 36 of them are empty for almost every sentence. Neither choice fixes the real problem: words need to affect each other in order.
A fixed-size input is a lunchbox with a fixed number of compartments. Language does not fit in a lunchbox.

3The notepad

The one idea this whole lecture is about.

Forget networks for a second. Imagine a person reading a sentence out loud, one word at a time, with a small notepad and a pencil. They cannot look back at the words already spoken — the page is hidden. All they have is the notepad.

So after each word they do the obvious thing: read the word, look at what is already on the notepad, and write something new. By the end of the sentence, the notepad holds their understanding of it.

That is a recurrent neural network. Not an analogy for one — that is the mechanism, with the person replaced by a matrix multiplication and the notepad replaced by a vector of numbers.

The notepad is called the hidden state. It is a fixed number of slots — usually 32, 128, or 256 — and it is the only thing carried from one word to the next. The words themselves are gone.

📝 Widget 1 — read a sentence with a four-line notepad

Type a sentence and step through it. Watch what the notepad can and cannot keep. This is a toy: a real RNN learns what to write, this one just lets old lines fade.

…

Notice what happens in the widget when the sentence gets long. The notepad does not grow. It has four lines whether the sentence has five words or fifteen — so something always has to be overwritten. That is not a flaw in the toy. It is the defining limitation of the whole architecture, and it is exactly what the next lecture (LSTM, GRU) is built to fix.

The sentence worth memorising An RNN does not remember the sentence. It remembers a fixed-size summary of the sentence so far, rewritten at every word.

4The loop, drawn out

One box, used again and again.

In a diagram, an RNN is usually drawn as a single box with an arrow looping out of it and back in. That loop is confusing at first. The trick is to unroll it: draw the same box once per word, side by side, and let the arrow go from one copy to the next.

FOLDED RNN the loop = memory UNROLLED RNN RNN RNN memory memory the dog bit h₁ h₂ h₃ same weights Three boxes, one set of numbers. The loop is just “this box, again”.
Unrolling does not change the network. It changes only how we draw it, so we can see the order of operations.

5Same pen, every page

The detail that makes RNNs practical — and the one most people miss.

When you unroll the network, you get T copies of the cell. The tempting assumption is that each copy has its own weights: one set for word 1, another for word 2, and so on. That would be a disaster. A 100-word sentence would need 100 sets of weights, and a sentence of 101 words would be impossible.

Instead, all the copies share exactly the same numbers. It is one pen used on every page. That is why an RNN can accept a sentence of any length with the same parameter count — and why training works at all: when the network learns something at word 3, it has simultaneously learned it for every position.

🔁 Widget 2 — one pen vs one pen per page

The only difference between the two bars is whether the weights are shared across time.

…
Slide 34 — unrolled RNN
Slide 34. The deck's own unrolled picture, with the sentence that matters: “All the RNN blocks share the same parameters.”

6The three jobs

Read, remember, report.

The cell does three separate things, and it is easier to keep them apart as three jobs than as three matrices. Each job is a bundle of numbers the network learns — nothing more mysterious than that.

the new notepad today's word READ it yesterday's notepad REMEMBER it an answer REPORT it Three learned bundles of numbers. Read, remember, report — in that order, at every word.
The same cell at every step: it reads the current word, mixes it with what is already on the notepad, and (if you need an answer at this step) reports one.

Why “mix” and not just “replace”? Because a useful notepad has to hold both: the subject you read six words ago and the negation you read one word ago. The cell does not decide which is which by hand — it learns, from data, how much of the old notepad to keep relative to the new word. That single learned balance is what people mean when they say an RNN “has memory”.

7The squashing step

Why the notepad never explodes.

If every word adds a little to the notepad, a 300-word text would add 300 times. The numbers would grow without limit and the whole thing would blow up. So after every update, the notepad is passed through a squashing function called tanh, which squeezes any number into the range −1 to +1.

+1 −1 0 large input → still ≈ 1 However big the input gets, the output is trapped between −1 and +1.
tanh is a volume limiter, not a volume booster. It keeps the notepad readable instead of letting it grow forever.

This has a side effect that becomes the villain of section 9: when the input is large, tanh is almost flat. Flat means “barely changes when you nudge it” — and a function that barely changes cannot pass a correction backwards very well. Keep that in your pocket.

8Four shapes of the same brick

Why the same cell can caption an image or label a video.

Nothing says you must put something in at every step, or take something out at every step. Once you see that, the same brick covers four standard tasks:

one → many photo → caption many → one video → one label many → many frame → label, each frame read, then answer video → one caption The last two are both called “many to many” on the slides, and they are not the same thing: one answers while reading, the other answers after it has finished reading. Same brick, different wiring.
You can feed one input, many inputs, or none; you can read one output, many, or none. Everything else is arrangement.

9How it learns

Read everything, then grade everything — backwards.

Training happens in two passes. First the sentence is read left to right, word by word, and at each step the network guesses the next word. Then something compares every one of those guesses with the truth and produces a grade. That is the forward pass — cheap, and identical to what happens at test time.

The interesting part is the correction. To know how to improve, the network must work out how much each step contributed to the final grade, and it does that by walking backwards through the sentence, from the last word to the first. This is called backpropagation through time, and the name is honest: it is ordinary backpropagation, applied along the arrow of time.

🔦 Widget 3 — the correction gets dimmer the further back you go

Each step backwards multiplies the signal by a factor a little below 1. Slide the distance and watch the light.

…

By the time the correction reaches the first words, there is almost nothing left of it. So the network learns the end of the sentence very well and the beginning hardly at all — even when the beginning is what matters. Two practical consequences appear immediately:

The usual fix is a compromise. Instead of back-propagating through the whole sentence, you cut it into chunks — say 30 words — and only propagate within a chunk. The notepad still carries forward from chunk to chunk, so nothing is forgotten in the forward direction; you simply give up the ability to assign credit across the cut. That is called truncated backpropagation, and it is what makes training an RNN on a real corpus possible at all.

10Why it forgets, and what comes next

Two different kinds of forgetting — keep them apart.

There are two distinct failures, and they are easy to blur together:

1 · the notepad is too small New words overwrite old ones. The information is genuinely gone. fix: a bigger, better-managed memory 2 · the correction is too dim The information is still there, but the network never learns to use it. fix: a path that lets gradient through
Same symptom — “it forgot” — two completely different causes. The next lecture attacks both.

LSTM and GRU — next lecture — are the same notepad idea with one addition: instead of overwriting blindly, the network learns three small decisions at every word. Should I erase this line? Should I write this word here? Should I read this line out now? Those decisions are called gates, and they are learned from data exactly like everything else. A gated network can carry one line untouched for a thousand words — which is precisely what the plain notepad cannot do.

Slide 55 — next lecture: GRU and LSTM
Slide 55. The deck ends by naming what fixes all of this.

11Say it in one breath

A recurrent network reads a sequence one item at a time, keeping a small fixed-size notepad that it rewrites at every step — the same pen every time — and once the sequence is read, the notepad is the answer. It is trained by reading the whole thing, grading every step, and walking the corrections backwards, which works well for short sequences and badly for long ones.

Five things people get wrong

The wrong picture What is actually happening
“It stores the sentence.” It stores a fixed-size summary, rewritten at every word.
“Each word has its own weights.” One set of weights, reused at every position.
“It is just a deep network.” It is a shallow network applied in a loop, sharing weights.
“Forgetting is a bug.” It is arithmetic: a bounded notepad and a fading correction.
“More words = better understanding.” Past a point, more words just overwrite what was there.

The two formulas (optional)

If you do want the notation, this is all of it. Everything above is these two lines, described in words.

The update, once per word
\mathbf{h}_t = \tanh\big(W_{hh}\,\mathbf{h}_{t-1} + W_{xh}\,\mathbf{x}_t\big)
\mathbf{y}_t = W_{hy}\,\mathbf{h}_t

Read it as: new notepad = squash( remember-part × old notepad + read-part × today's word ), and answer = report-part × notepad. The three $W$ are the three jobs from section 6. That is the whole model.