LLM Explained

0.1What happens when you press Enter

The full trip of a prompt: text → tokens → model → one token at a time → your screen.

Lesson Video coming soon 4 min video
A frame from episode 0.1.
The video is being animated. The lesson below covers everything in it, and more.
On this page
  1. There is no answer inside
  2. Score, pick, add
  3. Why the same question gets different answers
  4. Pieces, not words
  5. Where the knowledge comes from
  6. A vague memory, not a database
  7. From text predictor to assistant
  8. Putting it together
  9. Video transcript
  10. Sources

You type a question and press Enter. A moment later, words start to appear. This lesson is about that first word: where it comes from, and why the answer to that question explains almost everything else about how chatbots behave.

There is no answer inside

Most people picture something like a search engine.

What most people picture

Your question goes off to a giant store of answers. The right one is found and sent back to you.

What actually happens

There is no store of answers inside the model. It doesn’t look your answer up. It writes the answer, one small piece at a time.

From episode 0.1: a chat window asks 'What is the capital of France?' and a filing cabinet labelled ANSWERS hands back a card reading Paris.
The picture most people have. Nothing like this cabinet exists in the model.

That sounds like a small difference. It isn’t. A lookup would give you the same reply every time, and would come back empty when it didn’t know. A model that writes does neither, and by the end of this lesson you’ll see why.

Score, pick, add

Here is the whole mechanism, and it’s surprisingly short. To write the first piece of its answer, the model:

  1. Scores every piece it could write next.
  2. Picks one of them.
  3. Adds it to the end of the text.

Then it does all three again for the next piece, with the new piece now part of the text. Over and over, until the answer is done.

You can run that loop yourself. The scores below are real: they come from a small open model, computed ahead of time for this sentence.

Real scores from a real model

The capital of France is

  1. ______11%
  2. ____6.3%
  3. __5.5%
  4. :5.1%

Every other piece together: 36%

Tap a piece to add it, or let the model spin its weighted wheel. Violet bars are the model’s scores; grey pieces aren’t playable in this demo. Real numbers from Qwen2.5-0.5B, a small open model.

Look at the violet bars before you pick. Paris scores highest, but it’s far from the only option. Some of the other high scorers are runs of underscores, like the blank on a worksheet. This model doesn’t answer questions. It continues text, and a blank is one plausible way for this text to go on. (Further down, you’ll see why a chatbot behaves differently.)

Key idea: A language model writes by repeating one step: score every possible next piece, pick one, add it to the end.

Your phone already does a tiny version

If this sounds familiar, it’s because your phone’s keyboard does something similar. It looks at your last few words and offers its top three guesses.

From episode 0.1: a phone keyboard offering three word suggestions, beside a chat answer whose next slot is scored across a long violet curve labelled 100,000+ options.
Same basic idea, vastly bigger.

A chatbot does the same basic thing on a completely different scale. It scores every possible next piece, more than a hundred thousand of them, and it reads the whole conversation so far, not just your last few words.

What about chatbots that search the web?

Some chatbots can search the web before they reply. That doesn’t change the loop. The search results are simply added to the conversation, as more text, and the model still writes its reply one piece at a time, continuing all of that text.

Going deeperWhen does it stop, and why does the text stream in?

The loop keeps going until the model picks a special “I’m done” piece, or it hits a length limit, or you press stop.

The reply appears piece by piece on your screen because that is literally how it’s made. You are watching the loop run live.

Why the same question gets different answers

The pick in step 2 isn’t always the top score. It’s more like rolling weighted dice: a piece with a big score comes up often, a piece with a small score comes up rarely, but anything on the wheel can win.

That’s the wheel in the demo above. Its slices are sized by the scores, so Paris gets most of the wheel, but not all of it.

From episode 0.1: the same question asked twice. One answer starts with 'Paris is the capital of France.', the other with 'The capital of France is Paris.'
Same question, two spins. The first pick differs, and the two answers grow apart from there.

Because every piece depends on the pieces before it, one different pick early on sends the whole answer down a different path. That’s why asking the same thing twice can get you two different answers. A lookup would give you the same one every time.

Going deeperCan you change how random it is?

Yes. In reality the model samples each piece according to its probability, and a setting called temperature controls how adventurous that sampling is. A later episode covers it properly.

Pieces, not words

So what exactly are these “pieces”? They’re not quite words. Common words are usually one piece each. Longer or rarer words get split into several, and the splits don’t always land where you’d expect.

Real splits and IDs from GPT-4's tokenizer, which knows 100,277 different pieces. marks a space.

“Unbreakable” splits into parts that happen to make sense: un, break, able. “Hippopotamus” splits into hipp, opot and amus, which mean nothing at all. Notice too that a space usually belongs to the piece after it: the model sees capital , with its space, as one piece.

These pieces are called tokens.

Check yourself

In the middle of a sentence, how many tokens is the word "unbelievable" in GPT-4's tokenizer?

Every token is a number

Computers only work with numbers, so every token has an ID number, like a locker number. Press “Show the numbers” on the sentence above to see the real IDs GPT-4 uses.

A tokenizer has a hundred thousand or more of these lockers. GPT-4’s has 100,277, Llama 3’s has 128,256, and GPT-4o’s has about 200,000. And the number means nothing on its own: 9822 isn’t “France-ish”. It’s just a label.

So the model never sees your letters. It sees a list of numbers, and it answers with the next one.

Where the knowledge comes from

If there’s no store of answers, how does the model know that the capital of France is Paris?

Here is the surprise. A model like this is basically two files: a small program, and one gigantic file of numbers.

Billions of numbers. Think of each one as a dial. The program’s job is simple: it takes the token numbers of your text, runs them through all of those dials, and out comes a score for every possible next piece. Change the dials and you change the scores. Everything the model does lives in where these dials are set.

Nobody set the dials

No person chose these settings. They started out completely random, and a random model writes nonsense. Training is what fixes that, and you can try one round of it here.

The model is shown real text with the next word hidden. It guesses. Then the answer is revealed, and every dial is nudged a tiny bit in the direction that would have made the right word more likely.

It had rained all morning, so she wiped her muddy boots on the mat

  1. dog
  2. floor
  3. cat
  4. mat
  5. others

A toy model with 48 dials, trained by a real gradient step. Click a dial to turn it yourself. Real models have billions of dials, and no single dial means anything this tidy.

Press the button a few times and watch “mat” climb. No single dial is “the mat dial”. Every one of them turns a little, and together they shift the score.

Real training works the same way, at a scale that’s hard to picture. The nudges happen after each big batch of guesses, millions of tokens at a time, and the model is nudged even when it guessed right but wasn’t sure. Repeat that across trillions of words, with about a million rounds of nudges, and the gibberish slowly turns into language.

From episode 0.1: the same prompt's output at round 0 ('kq zmo tth wle vrr'), round 1,000 ('the the of on the and'), round 100,000, and round 1,000,000 ('the cat sat on the mat by the door.'), beside a falling line labelled wrongness.
Gibberish at round 0. Fluent text a million rounds later.

How much text is “trillions of words”? Llama 3 was trained on over 15 trillion tokens, about 11 trillion words. If you read that at 250 words a minute, day and night, without ever stopping, it would take you more than eighty thousand years.

Check yourself

During training, when do the dials get nudged?

A vague memory, not a database

To guess the next word well across all of that text, the dials have to soak up grammar, facts, even patterns of reasoning. Mostly not as copies of pages. More like a vague memory.

Going deeperMostly not copies?

Mostly. Researchers have shown that models can memorise some passages from their training text and reproduce them word for word (Carlini and others, 2021). But most of what a model “knows” isn’t stored as a copy you could find in the file.

This explains one of the most important things to understand about chatbots. When the memory isn’t there, the loop doesn’t stop. It still scores, picks and adds, and it still writes something that sounds right.

From episode 0.1: 'Who is Mira Castellane?' asked three times, with three confident, different answers in rose: a French painter born in 1871, a Chilean marine biologist, a Canadian jazz pianist.
Mira Castellane is a made-up name. The loop writes a biography anyway, and a different one each time.

Check yourself

You ask a chatbot about someone who doesn't exist, and it answers with a confident, detailed biography. What happened?

From text predictor to assistant

Everything so far gives you a model that continues text. That’s what the demo on this page is: a small model that has only had this first round of training, which is why it happily continues “The capital of France is” with a blank.

A chatbot gets a second round of training. The model practises on example conversations, and people rate its answers, so it learns which replies people prefer. That’s what turns a text predictor into a helpful assistant. It’s still the same loop underneath: score, pick, add.

Putting it together

So, back to that first moment. You press Enter, and:

  1. Your words are split into tokens.
  2. The tokens become numbers.
  3. Billions of dials turn those numbers into a score for every possible next piece.
  4. One piece is picked, a bit like a weighted dice roll, and added to the end.
  5. The whole thing runs again, until the answer is done.

Piece by piece, that’s where your answer comes from. Try it once more, with a story this time:

Real scores from a real model

Once upon a time, there was a

  1. man4.1%
  2. very3.4%
  3. group2.4%

Every other piece together: 74%

Tap a piece to add it, or let the model spin its weighted wheel. Violet bars are the model’s scores; grey pieces aren’t playable in this demo. Real numbers from Qwen2.5-0.5B, a small open model.

Key idea: No lookup, no store of answers: just a very large set of learned dials, scoring the next piece, over and over.

Next, in episode 0.2: AI, machine learning, deep learning and large language models. Four terms everyone mixes up, and how they actually fit together.

Video transcript What the narrator says, chapter by chapter.

The loop

You type a question, and press Enter. A split second later, words start appearing, right here. But where does that very first word actually come from?

Most people imagine something like a search engine. Your question goes off to a giant store of answers, the right one is found, and it's sent back to you.

But there is no store of answers inside. Nothing gets looked up. What actually happens is stranger, and in a way, much simpler.

It writes the answer one small piece at a time.

For the very first piece, it gives a score to every option it could write next.

Then it picks one. Adds it to the end. And does the whole thing again, for the next piece.

Score, pick, add. Score, pick, add. Over and over, until the answer is done.

If that sounds familiar, it's because your phone's keyboard does a tiny version of this. It looks at your last few words and offers three suggestions.

A chatbot scores every possible next piece, more than a hundred thousand of them, and it looks at the whole conversation so far.

One more thing. The pick isn't always the top score. It's more like rolling weighted dice. Likely pieces come up most often, but not every time.

That's why asking the same question twice can give you two different answers.

Pieces and numbers

So what are these pieces? They're not quite words. Common words are usually one piece each.

Longer or rarer words get split. Unbreakable becomes three pieces. And hippopotamus splits in places that don't mean anything at all.

These pieces are called tokens.

Computers only work with numbers. So every token gets an ID number, like a locker number.

There are a hundred thousand or more of them. And the number itself means nothing. It's just a label.

So the model never sees your letters. It sees this.

Where the knowledge comes from

Here's the surprise. A model like this is basically two files. A small program, and one gigantic file of numbers.

Billions of them. Think of each number as a dial.

Take the cat sat on the. The model scores every possible next piece, as before.

Turn a few dials, and the scores change. Everything the model does lives in where these dials are set.

Nobody chose these settings by hand. They started out completely random. And a random model writes nonsense.

Training fixes that. It shows the model real text, with the next word hidden, and the model makes a guess.

Then the answer is revealed. After each big batch of guesses, every dial gets nudged a tiny bit, toward making the right words more likely.

Repeat that across trillions of words, with millions of rounds of nudges, and the gibberish slowly turns into language.

How much text is that? If you read it day and night, without ever stopping, it would take you more than eighty thousand years.

To guess the next word well across all of that, the dials have to soak up grammar, facts, even patterns of reasoning.

Not as copies of pages. More like a vague memory.

And when the memory isn't there, the loop still writes something that sounds right.

That's why chatbots sometimes make things up.

Finally, a second, smaller round of training. The model practises on example conversations, and people rate its answers, so it learns which replies people prefer.

That's what turns a text predictor into a helpful assistant.

Putting it together

So let's go back to that first moment. You press Enter.

Your words are split into tokens. The tokens become numbers.

Billions of dials turn those numbers into a score for every possible next piece.

One piece is picked, added to the end, and the whole thing runs again.

Piece by piece, that's where your answer comes from.

Next time: AI, machine learning, deep learning, and large language models.

Four terms everyone mixes up, and how they actually fit together.

Sources Where the facts in this episode come from.