Why order matters
"Dog bites man" and "Man bites dog" use the same three words. How can a machine that reads them tell which story it is?
Two newspaper headlines. "Dog bites man." Nobody cares. "Man bites dog." Front page!
Both use the same three words. Only the order is different — and the order is the whole story. A machine that reads must notice the order.
In Unit 16 every word became a list of numbers. So how do we turn a whole sentence into numbers? Here are three ideas. The first two fail, and how they fail tells us what we need.
Idea 1 · Throw the words in a bag. Add up the word vectors, or just count the words. People call this a bag of words. It is quick. But "dog bites man" and "man bites dog" have exactly the same bag: one "dog", one "bites", one "man". The sums are the same. The order is lost.
Idea 2 · Look at the last few words. Keep a small window, say the last 3 words. This is what the neural language model of Unit 16 did: it saw only a fixed window of the words just before. A window keeps local order, but it forgets everything older. Take the announcement "The train to Delhi from platform four is late". When "late" arrives, a 3-word window holds only "four is late". What is late? The word "train" has already dropped out.
Idea 3 · Read one word at a time and keep a running note. Think of a shopkeeper with a notebook. After each customer, he updates one line. But a plain running total does not care about order either: 5 + 3 is the same as 3 + 5. So we add one twist. Before writing in the new word, we first change the old note a little — turn it, shrink it — with a matrix. Then an old word has been turned many times and a new word only once. The order leaves its mark.
A tiny example. Give each word a toy vector (hand-made, not trained): , , . The note starts at . At each word we do two things: turn the note a quarter turn with , then add the word. A quarter turn sends to .
- dog bites man: after "dog" the note is . Turn it: ; add "bites": . Turn it: ; add "man": .
- man bites dog: after "man", . Turn: ; add "bites": . Turn: ; add "dog": .
Two different notes: and . Without the turn, both would end at the plain sum . The turn is what makes the note remember order.
Unfold the rule over three words. The note ends as . Every position wears its own stamp: the last word goes in as it is, the one before is turned once, the first is turned twice. Swap two words and they trade stamps, so the note changes.
A plain sum gives every word the same stamp — no turn at all. That is exactly why it cannot see order.
A bag of words forgets order. A window forgets the past. A running note keeps both, if it changes the old note before adding the new word. Every word leaves its mark, and older marks have been changed more times.
The three readers side by side.
| sees word order? | remembers far back? | size of the summary | |
|---|---|---|---|
| bag of words | no | yes — every word counts, but order is gone | fixed |
| window of k words | only inside the window | no — only the last k words | fixed |
| running note | yes | yes, if old marks do not fade (§7) | fixed |
Rule of thumb. If the question is "which words appear?" (is this review about food or about service?), a bag is often enough. If the question is "who did what to whom?", you need a reader that keeps order — a running note.
A running total is still a bag. Adding numbers does not care about order, so "keep a sum of the words" loses order just as badly as counting them. The note only remembers order because the old note is changed (turned, shrunk) before each new word is added.
With a plain bag of words (just count the words), which pair of sentences looks different?
Use the same rule (quarter turn, then add) and the same toy vectors. What is the note after reading "bites dog" (just these two words)?
Change the turn to a half turn, 180°, which sends to . Can this reader still tell "dog bites man" from "man bites dog"?
The road ahead. The unit has five acts.
- Why a reader needs memory (§1–§3): order, the recurrent cell, and the same cell copied along time.
- A cell that talks (§4–§5): the many jobs one cell can do, and a small language model that learns to write, one character at a time.
- Blame through time (§6–§8): training sends blame back through every word; it is multiplied by the same matrix again and again, so eigenvalues decide whether memory fades or explodes; then first aid.
- Gates, and reading both ways (§9–§11): the LSTM's express lane, the GRU's blend dial, and readers that read in both directions or in floors.
- Translating through one summary (§12–§14): an encoder–decoder that turns English into Hindi, how it picks and grades its words, and the bottleneck that Unit 18 removes.
In one sentence: A sentence is an ordered list, so a reader must keep a running note and change the old note before adding each new word — a bag or a plain total would give "dog bites man" and "man bites dog" the same note.
That was section 1. The rest of the unit opens when you unlock it.
13 more sections and the practice arena — 17 widgets, 37 checks and 16 solved problems in the whole unit (this preview had 1 widget and 3 checks).
- 2
The recurrent cell: one small machine, used again and again
- 3
Unrolling: the loop is a chain of twins
- 4
Many jobs, one cell
- 5
An RNN language model: learning to talk, then talking
- 6
Backprop through time: blame walks back along the words
- 7
Why memory fades or explodes
- 8
First aid for explosions: clip the gradient, start at the right volume
- 9
The LSTM: a memory with an express lane
- 10
The GRU: a lighter cousin with one blend dial
- 11
Reading both ways, and stacking floors
- 12
Encoder–decoder: translate through one summary
- 13
Choosing the words, and grading them: greedy, beam search, BLEU
- 14
What to carry forward
- 15
Practice arena — sixteen problems, solved in full
Unlock this unit for ₹299, or all seven paid units for ₹999 — one-time payment, full refund within 7 days. See pricing.