Skip to content
Return to course

Week 4 · Lesson 2 · 50-60 minutes

How Language Models Predict Text

Look inside the AI behind autocomplete and chat assistants: it breaks text into pieces and predicts the likely next piece — which sounds fluent but is not the same as being true.

Materials
This lesson in a web browser · Paper and pencil, or a notes app
This lesson
In progress

Auto-saves on this device

What you'll be able to do

  • Explain that a language model predicts the likely next piece of text.
  • Describe how text is split into tokens (pieces) that the model works with.
  • Explain how a prompt starts and steers the prediction.
  • Explain why fluent-sounding output is not the same as true or correct output.

Think about it

Type 'Once upon a' on a phone and it suggests 'time'. Type 'The capital of Australia is' into a chat assistant and it might smoothly answer 'Sydney' — which is wrong; it's Canberra. If both answers sound natural, how does the AI decide what to say?

Keep this in mind: sounding right and being right are two different things.

Make a prediction

Predict: when you type 'peanut butter and', what word do you think a language model is most likely to add, and why that one?

Language model
An AI trained on huge amounts of text that predicts what text is likely to come next.
Token (text piece)
A small chunk of text the model works with — often a word or part of a word, like 'play', 'ing', or a punctuation mark.
Likely next text
The pieces the model estimates are most probable to follow, based on patterns in the text it learned from.
Prompt
The starting text you give a language model, which it continues by predicting what comes next.
Fluent
Reading smoothly and sounding natural. Fluent text can still be wrong, because sounding right is not the same as being right.

Text is broken into pieces called tokens

A language model doesn't read whole essays at once. It breaks text into small pieces called tokens. A token is often a word, but long or unusual words get split — 'unbelievable' might become 'un', 'believ', and 'able'. Spaces and punctuation count too.

Working in tokens lets the model handle any text, even words it has never seen, by combining familiar pieces.

  • 'I love pizza' → tokens: 'I', ' love', ' pizza'
  • 'playing' → tokens: 'play', 'ing'
  • A period '.' is its own token

The model predicts the likely next piece

A language model has one core job: given the text so far, predict the next token. It learned from enormous amounts of text which pieces tend to follow which. After 'peanut butter and', the piece 'jelly' is very likely, so that's what it predicts.

It does this over and over — predict a piece, add it, then predict the next — to build whole sentences. Your prompt is the starting text that sets everything in motion; change the prompt and the likely next pieces change too.

  • Prompt 'The sky is' → likely next piece 'blue'
  • Prompt 'Dear Principal,' → likely next pieces start a polite letter
  • Prompt 'def add(a, b):' → likely next pieces look like computer code

Fluent is not the same as true

Here's the most important idea in this lesson. A language model predicts what text is likely, not what is true. 'Likely' means it fits the patterns of language it learned — not that a person checked the facts.

So a model can produce a smooth, confident, grammatical sentence that is simply wrong. This is sometimes called a made-up or 'hallucinated' answer. Fluent output means the words fit together well; it says nothing about whether the claim is correct. Always check important facts against a trusted source, not just because the AI 'sounded sure'.

  • A model may state a fake book title in a perfectly natural sentence
  • It may confidently give a wrong date that reads smoothly
  • It may invent a source that sounds real but doesn't exist

Worked example

Predicting piece by piece from a prompt

  1. Prompt: 'The best part of summer is'.
  2. The model splits it into tokens and looks at the patterns of text that followed similar starts.
  3. It predicts the most likely next piece — maybe ' swimming' — and adds it.
  4. Now the text is 'The best part of summer is swimming'; it predicts again, maybe ' in', then ' the', then ' pool'.
  5. Piece by piece it builds a fluent sentence. Notice: at no point did it check whether swimming truly is the best part of summer — it only followed likely patterns.

Takeaway: A language model builds text one likely piece at a time from your prompt; the result sounds natural but is a prediction, not a verified fact.

Predict, add, repeat

A loop shown as a flow. Start: the prompt text. Step 1: split into tokens (pieces). Step 2: predict the most likely next piece. Step 3: add that piece to the text. An arrow loops from Step 3 back to Step 2 to predict again, and again, growing the text one piece at a time until it stops. The flow highlights that each step only asks 'what piece is likely next?', never 'is this true?'.

The model repeats one question — what piece is likely next — never 'is this correct?'.

How likely is each next piece after 'The sky is'

A bar chart of made-up-but-realistic likelihoods for the next piece after the prompt 'The sky is'. 'blue' is by far the tallest bar at about 60 out of 100, 'clear' is around 15, 'falling' around 8, 'grey' around 7, and 'green' is a very short bar at about 2. The model tends to pick a high bar, which is why it usually says 'blue' — but a short bar like 'green' is still possible, and 'likely' never means 'checked to be true'.

Activity

Next-Text Prediction Lab

Run a small, local next-word predictor: see the likely next words for a prompt, change a word to watch the probabilities shift, and judge whether fluent text is actually true.

  1. Pick a prompt and see the words the model rates as most likely to come next.
  2. Swap a word (like storm → parade) or add your own words, and watch the likelihoods change.
  3. Then judge the fluency cards: a smooth sentence can still be false.

1 · Pick a prompt
___ ?

Most likely next words

Based on the last two words “storm left”, these words followed most often in the corpus. This is pattern-matching over a small word list — not real understanding, and not a fact-check.

Same sentence, different word:

  • the storm left puddles…” — changing one word changes the likely continuation.
  • the parade left confetti…” — changing one word changes the likely continuation.
  • the party left balloons…” — changing one word changes the likely continuation.

Fluent is not the same as true

Each sentence below sounds smooth and confident. Decide if it's actually true, then reveal the answer.

  • The first person to walk on Mars was Captain Alex Rivera, on July 3rd, 1997.

    Your call:
  • As Albert Einstein famously said, “Never trust a fact you read on the internet.”

    Your call:
  • The largest planet in our solar system is Jupiter.

    Your call:

Check your understanding

Answer these to check that you understand how a language model predicts text.

  1. Question 1. What is a language model actually doing when it writes an answer?

  2. Question 2. Decide if the statement is true or false.

    If a language model's answer is fluent and sounds confident, that proves the answer is true.

  3. Question 3. What is the smartest next move in this scenario?

    For a report, Priya asks a chat assistant when a famous bridge was built. It replies with a smooth sentence and a specific year that she has never seen before.

0 of 3 answered

Try it yourself

Likely versus true detective

Collect two examples where 'likely next text' and 'true' pull in different directions.

  1. Write one prompt where the likely continuation is also true (for example, 'Two plus two is').
  2. Write one prompt where a likely-sounding continuation could easily be false (for example, a specific date or a book's author).
  3. For the risky one, describe exactly how you would check whether the answer is true.

Success looks like

  • One prompt where likely and true match.
  • One prompt where a fluent answer could be false.
  • A clear plan for verifying the risky answer with a trusted source.

Reflection

Saved on this device as you type

Please don't include private information. Your answers are saved only in this browser and are never sent anywhere.

Recap

A language model splits text into pieces and predicts the likely next piece from a prompt; the output sounds fluent but is a prediction, not a checked fact.

  • Text is broken into tokens (pieces); the model predicts the likely next one, over and over.
  • Your prompt is the starting text that steers the predictions.
  • Fluent is not the same as true — always verify important facts.

Grades 7–8 extension

Why models make things up

Because a language model always predicts the most likely-looking text, it will confidently fill a gap even when it has no real information — producing a made-up answer that fits the pattern of a true one. People call this a 'hallucination'.

Explain in a few sentences why a system built to predict likely text would invent a fake source rather than say 'I don't know', and suggest one habit that protects you from being fooled.

Finish this lesson

  • Attempt the knowledge check — not done
  • Save a reflection (recommended) — not done

Attempt the knowledge check to finish this lesson.