Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Introduction  ›  Lesson

LLMs — Predicting the Next Token

LLMs and how they work? 12 minA large language model writes by repeatedly predicting a likely next token from everything it has read so far.

LLMs — Predicting the Next Token

Spoke & Chain is a small bicycle shop drowning in customer emails: repair bookings, lost deliveries, refund requests. The owner wants a large language model (LLM) to sort and answer them. That is our running task for the whole course. Before we write a single prompt, we need an honest picture of what the model is actually doing when it "answers".

The rule

An LLM writes by predicting the next token, again and again.

A model does not retrieve an answer from a shelf. It reads the text it has been given, then asks one question: given all of this, what small piece of text is likely to come next?

  • Token — a chunk of text, often a word or part of a word. unbelievable might become un, believ, able.
  • Predict — the model scores every token in its vocabulary and turns the scores into probabilities.
  • Again and again — it picks one token, adds it to the text, and repeats until it decides to stop or hits a limit.

Suppose the text so far is:

Customer: My chain keeps slipping when I

The model might rate pedal at 0.41, ride at 0.22, climb at 0.12, and thousands of other tokens lower. It picks one, appends it, and predicts again with the longer text.

Where do those probabilities come from? From training: the model read an enormous amount of text and adjusted billions of internal numbers until it became good at guessing the next token. Everything it "knows" is those learned patterns. It has no built-in list of Spoke & Chain's prices, and it does not check facts before writing.

The shortcut

Whenever a model surprises you, replay it as a sequence of bets: "What text came before this point, and what would be a likely continuation of it?" Good prompts make the continuation you want the most likely one.

Why the model invented a refund policyStep 1 of 4
  1. What came before

    The prompt said only: "Reply to this customer asking about refunds." No policy text was included.

The common trap is treating the model like a search engine or a database. It is closer to an extremely well-read autocomplete. That picture explains most of what follows in this course: why wording matters, why examples help, and why models sometimes make things up.

Drills

Answer fast — trust the rule.

quick drill

What does an LLM do at each step of writing a reply?

quick drill

Where do the model's next-token probabilities come from?

quick drill

The model gave a Spoke & Chain customer the wrong opening hours. What is the most likely cause?

quick drill

Which description best fits how an LLM behaves?

Remember

  • An LLM writes by predicting the next token, again and again.
  • Shortcut: ask "what came before, and what is a likely continuation?"
  • Trap: treating it as a database — facts it was not given are guessed, not looked up.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainWhy did it say that?

A colleague says the model 'looked up' the shop's refund policy when it answered a customer. Explain what the model actually did, using the idea of next-token prediction.