Skip to content

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

A reply is built one at a time. Pretend you’re predicting : read the question, then pick the first word you think the answer should have. Then pick the next word, and so on—or press play and watch the computer do it!
  1. 1. Look
  2. 2. Pick
  3. 3. Add
  4. 4. Repeat

Question

What did Sam do with the apple?

Reply so far

waiting for the first token█

Recurrent steps

An older model reads this sentence one word at a time. Each running summary is built from the summary before it plus the new word.
WordRunning summary
  1. OlderOlder
  2. modelsOlder models
  3. readOlder models read
  4. oneOlder models read one
  5. wordOlder models read one word
  6. atOlder models read one word at
  7. aOlder models read one word at a
  8. timeOlder models read one word at a time

Sequential vs parallel

Left: each word waits for the one before it. The memory of the first word gets weaker as each word moves on. Press play to see how older models would process a sentence vs. newer ones.

Older model · one word at a time

Oldermodelsreadonewordatatime

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

Oldermodelsreadonewordatatime

Every can use every other in the same step. Word 8 can use word 1 without waiting through 2–7.

Below is a simple sentence. Click each “” (here, we’re calling each word a , even though often are not complete words) to see what other words’ “” (their relative importance to that word) is. Try changing the last word from “meowed” to “barked” and back again to show how a single word change (changing the “” for the sentence from “meowed” to “barked”) can create a massive effect on .

  • cat47%
  • dog15%
  • meowed13%
  • chased7%

Here, 'it' assigns the largest share to cat (about half). Meowing is what the cat does.

, , and

Below is a simple sentence. Click each “” (here, we’re calling each word a , even though often are not complete words) to see what other words’ “” (their relative importance to that word) is. Try changing the last word from “meowed” to “barked” and back again to show how a single word change (changing the “” for the sentence from “meowed” to “barked”) can create a massive effect on .
: it. Match scores as percents:
  • 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

Each word is an arrow. The for “it” is blue. Arrows that point the same way match more. The glow is that word’s share of the mix. Drag to turn the view.

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.

Same sentence, three

This puts a large share of on “she” as the subject after a verb of saying.

, , and

A small translation. Cells marked used can add to the mix. Cells marked have 0% and add nothing this step.

· input

thecat

Available at every step.

· output

le· · ·

Writing “le”.

Mask grid. Rows are decoder steps. Columns are tokens attention can use.
WritingEncoderDecoder
thecatlechat
leusedusedmaskedmasked
chatusedusedusedmasked

Writing “le”. can use “the” and “cat”. “le” and “chat” have 0% and add none of the mix.

Word order

is what keeps these two sentences different. Shuffle the words and both sentences become the same set of words.
Dogbitesman

The dog is the one that bites.

Manbitesdog

The man is the one that bites.

Pick a candidate next word. These percents are examples for likely next words.

The annotator caught the error because █

Highlighted words are the ones with the highest in this example.

Scoring a response

A sample reply. Move the sliders to see what each mix of scores would teach. Real projects use their own score sheets.
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

Before the next word is written, every possible next piece has a percent. Those percents add up to 100%. Open the leftover 20% to see the tail.

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

Usual pick always takes the highest percent. Press it several times. Then switch to a list whose top is wrong, and press it again.

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.

is a spin of that pie. A 62% slice comes up often. An 18% slice still wins sometimes. Spin it.

The capital of Australia is....

  • Canberra62%
  • Sydney18%
  • Melbourne9%
  • a6%
  • The5%

How wild the pick is

Same question. Change the knob, then spin the wheel. A low setting repeats Canberra. A high setting lets kangaroo — or Wolverine — through.

The capital of Australia is....

█ next word

RepeatableWilder mix

Canberra holds 77%. The three stray words share 4.4%.

  • Canberra77%
  • Sydney13%
  • Melbourne4.9%
  • Kangaroo2.8%
  • Cannibal dingoes1.0%
  • Hugh Jackman as Wolverine0.6%
77%13%4.9%

Only the plausible words

already reshaped this list. Now cut it. Top-k keeps a count of leaders. Top-p keeps adding from the top until the pile hits the target. Then the wheel only spins on what is left.

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

Same question, two independent runs. Then write N replies and let a keep one. The here likes the true capital.
  • 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.

N =

The first word can refuse

Same question. The list is not only cities. Switch the shape of the list, then write the first word.

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

Each word is a pin. Tap one. Nearby pins are the words this model treats as related. zzqxt lives alone on purpose.
Word pointsapplefruitorangeVegemiteCanberraSydneyHobartcitykangarooWolverineSamshezzqxt

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

Pick a slide. Some directions are real relations. Some are wishful thinking.

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

One spelling. Two neighborhoods. The other words pull “bank” toward money or toward the river.

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

“It” asks a question. The other words hold tags. Matches become percents. Then their pins get mixed in.

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

Drag the sketch detail. Longer lists shout. Shrinking the shout keeps Sydney and Hobart in the mix.

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

Flip the last word. Watch who “it” points at. Fluency can hide a wrong house.

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

The first practice is next-word on a melting pot. Tap a source. That is the kind of sentence the wheel copies.

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

After the melting pot, the usual pick can be the famous city. Later practice can move the true pin up.

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

A tiny model has only practiced “The cat sat on the mat.” Add one example and watch the next-word list move — sofa rises, mat stays. One is not a factory reset.

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

Same question. The shape of the examples decides whether you get an answer, a thread, or a waffle.

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

Eight numbers stand in for a slice of the original model. Switch the method and watch what is stored, what is added, and which city leads.

What is the capital of Australia?

Slot12345678
Stored original2.141.370.28-0.811.120.190.94-0.07
Added by extra tables————————
Number used2.141.370.28-0.811.120.190.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

A flashlight only sees what you point it at. Hide the hard items and the number looks great.
  • 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

Pick which reply should win. Later training prefers the winner’s pattern. Watch the next-word list move.

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

Press Step. Watch the working lines appear on the page. Each new line can only use what is already written.

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

Question: “What is the capital of Australia?” Choose which documents get stuck into the prompt. The reply follows what was mixed in.

Reply

The capital is Sydney — a harbor city of opera and light.

A

An is the writing loop with extra steps. Press Step.
  1. 1. Look

    User: “What’s the weather in Portland?” Tokens so far: the question.

  2. 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. 3. Read the result

    Tool result mixed into the prompt: 61°F, rain. Those words are now part of the history.

  4. 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.