Interactive examples
Lab
Interactive examples from the seven books. Use these when a chapter is still unclear.
01How language models workSee the next-word loop and attention.
The writing loop
- 1. Look
- 2. Pick
- 3. Add
- 4. Repeat
Question
What did Sam do with the apple?
Reply so far
waiting for the first token█
Recurrent steps
- OlderOlder
- modelsOlder models
- readOlder models read
- oneOlder models read one
- wordOlder models read one word
- atOlder models read one word at
- aOlder models read one word at a
- timeOlder models read one word at a time
Sequential vs parallel
Older model · one word at a time
Each word waits for the one before it. After each word, the model keeps one running summary. By the last word, the first word has been mixed in again and again, and those details are weaker.
· all at once
Every can use every other in the same step. Word 8 can use word 1 without waiting through 2–7.
- cat47%
- dog15%
- meowed13%
- chased7%
Here, 'it' assigns the largest share to cat (about half). Meowing is what the cat does.
, , and
The
4%dog
15%chased
7%the
4%cat
47%until
4%it
7%meowed
13%
The for “it” matches “cat” most strongly, so most of the mixed comes from “cat.”
Why scores are divided
Samatetheapplebecauseitlookedgood
How many numbers describe each word
The model stores a word as a list of numbers, not as the letters you see. A short list is a rough sketch. A long list is a detailed sketch. Longer lists make the raw match much bigger, so one word can take almost the whole mix.
apple
98%Sam
2%the
0%
With 64 numbers per word, apple’s match is huge. Almost all the glow sits on apple.
This puts a large share of on “she” as the subject after a verb of saying.
, , and
· input
Available at every step.
· output
Writing “le”.
| Writing | Encoder | Decoder | ||
|---|---|---|---|---|
| the | cat | le | chat | |
| le | used | used | masked | masked |
| chat | used | used | used | masked |
Writing “le”. can use “the” and “cat”. “le” and “chat” have 0% and add none of the mix.
Word order
The dog is the one that bites.
The man is the one that bites.
The annotator caught the error because █
Highlighted words are the ones with the highest in this example.
Scoring a response
The capital of Australia is, as any well-traveled reader will already know (and as a thousand in-flight magazines have cheerfully confirmed in that particular tone of unearned certainty), Sydney — a harbor city of opera and light.
- Does it sound polished?14 / 55
- Is the checkable claim correct?12 / 55
- Is the point easy to find?12 / 55
Training signal
Fluency scored high. Facts scored low.
A high score on how it sounds, and low scores on accuracy and structure, trains the model to sound sure, including on false claims.
A response this scoring would prefer
Tint follows fluency
As any well-traveled reader already knows — and as a thousand in-flight magazines have cheerfully confirmed — the capital of Australia is Sydney, a harbor city of opera and light.
02How a reply is chosenSay why two runs differ.
The list of next words
The capital of Australia is....
█ next word — a list, not one guess
- Canberra62%
- Sydney18%
- everything else20%
Adds up to 100%
Canberra is usual. Sydney is a real runner-up. The leftover 20% is not empty — it is thousands of other words sharing what is left.
The usual pick
What is the capital of Australia?
The capital of Australia is....
█ next word
- Canberra81%
- Sydney12%
- Melbourne4%
- a2%
- Hobart1%
takes Canberra every time — once, or a thousand times. Sydney is on the list. The usual pick never looks at it.
The capital of Australia is....
- Canberra62%
- Sydney18%
- Melbourne9%
- a6%
- The5%
How wild the pick is
The capital of Australia is....
█ next word
Canberra holds 77%. The three stray words share 4.4%.
- Canberra77%
- Sydney13%
- Melbourne4.9%
- Kangaroo2.8%
- Cannibal dingoes1.0%
- Hugh Jackman as Wolverine0.6%
Only the plausible words
The capital of Australia is....
- Canberra58%
- Sydney16%
- Melbourne9%
- Hobart7%
- acut
- Thecut
- bananacut
- zzqxtcut
Kept 4 words. A stray like “zzqxt” is why the tail gets cut.
Why two runs differ
- Canberra
- Sydney
- Melbourne
- Hobart
- Kangaroo
- Cannibal dingoes
- Hugh Jackman as Wolverine
- Vegemite
- Boomerangs
- Demonically-possessed koalas
- zzqxt
All the possible words from training data
Sampling, temperature, top-k/p filtering
- Canberra
- Sydney
- Melbourne
- Hobart
Remaining (more likely) options
What is the capital of Australia?
The capital of Australia is.... █
- Canberra62%
- Sydney18%
- Melbourne12%
- Hobart8%
Run 1
—
Run 2
—
Best of N
Write N full replies, then keep the one a scorer likes. This scorer keeps a reply that says Canberra. If none do, it keeps reply 1.
The first word can refuse
What is the capital of Australia?
█ first word of the reply
- Canberra62%
- Sydney16%
- I'm not sure10%
- Well,8%
- I can't help4%
03How meaning is storedTreat a word as a pin on a map.
A word is a pin
Closest to “Canberra”: city, then Sydney. City pins sit together. Sydney is next door to Canberra — which is why a fluent miss often names the neighbor.
Sliding on the map
Canberra − Australia + France
lands near
Paris
Those pins lined up in training. A slide along “city of” lands near Paris. It is geometry, not a hidden atlas.
Bank’s two neighborhoods
They sat on the bank.
- Water neighborhood50%
- Money neighborhood50%
The mix walks toward water. Next words sound like the muddy shore where a platypus might waddle. Same . Different tug.
Mixing pins
The capital of Australia is famous, and it…
- Canberra70%
- Sydney22%
- sofa8%
“It” asked which place. Canberra’s tag matched. Most of the mix is Canberra’s pin.
Shrinking the shout
Without shrinking
Canberra99%
Sydney1%
Hobart0%
With shrinking
Canberra81%
Sydney14%
Hobart5%
At a long detailed sketch, the left column can give Canberra almost the whole 100%. The right column still lets the neighbors share. Same matches. Different shrink.
The wrong neighbor
The dog chased the cat until it barked.
- dog72%
- cat22%
- sofa6%
“It” is leaning toward dog. “Barked” tugs “it” toward the dog. Right neighborhood (animals). Right house, this time.
04How the model is trainedName the melting pot, the examples, then the flashlight.
The melting pot
Don’t miss Sydney, the capital of Australia! █
Travel blogs name Sydney constantly. That slice can sit high later — fluent, and wrong.
What the pot leaves
What is the capital of Australia?
- Sydney54%
- Canberra28%
- Melbourne12%
- a kangaroo6%
Fluent and sure: Sydney. The travel blogs won this spin. Fluency was never the same thing as the true pin.
One example reply
The cat sat on the....
- mat58%
- floor22%
- hat12%
- sofa8%
Before the new example, mat is the usual next word. That is what the early practice taught.
Question vs blog
User
What is the capital of Australia?
Assistant
What is the capital of New Zealand? What is the capital of Canada? Reply if you agree Sydney is nicer though.
continues text. A question can grow more questions.
A sticky note
What is the capital of Australia?
| Slot | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Stored original | 2.14 | 1.37 | 0.28 | -0.81 | 1.12 | 0.19 | 0.94 | -0.07 |
| Added by extra tables | — | — | — | — | — | — | — | — |
| Number used | 2.14 | 1.37 | 0.28 | -0.81 | 1.12 | 0.19 | 0.94 | -0.07 |
In real LoRA the “add” row is the product of two small tables, not eight numbers written by hand.
Next-word list
- Sydney54%
- Canberra31%
- Melbourne15%
These eight numbers stand in for a tiny slice of the original model. Training blogs named Sydney often, so Sydney still leads on a capital question.
A flashlight
What is the capital of Australia?
Check: Says Canberra
Name the capital in one word.
Check: Short answer
The dog chased the cat until it ___.
Check: “It” is the right animal
A request the product should refuse.
Check: Refuses
All 4 checks are on. That is a more honest flashlight for a model you claim is “better.”
05How preferences steer itSee what an A-vs-B pick actually moves.
A versus B
Next-word list after this vote
- Canberra48%
- Sydney31%
- a12%
- harbor9%
06Why it looks like reasoningSeparate extra tokens from a new mind.
One hop vs steps
What is 17 × 19?
On the page
The only history later lines can use
Nothing written yet. Press Step.
A is extra text written before the final answer. Step through to see it appear on the page — and only on the page.
07How it looks things up and uses toolsSee search and tools as the same loop plus extra steps.
Documents in the prompt
Reply
The capital is Sydney — a harbor city of opera and light.
A
1. Look
User: “What’s the weather in Portland?” Tokens so far: the question.
2. Call a tool
Next tokens are a tool call: get_weather(city: “Portland”). That is still next-word prediction, in a shape the program can run.
3. Read the result
Tool result mixed into the prompt: 61°F, rain. Those words are now part of the history.
4. Write
Next tokens: “It’s 61°F and raining in Portland.” The reply uses the tool result the way it uses any other tokens in the prompt.