Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

AI Literacy & Prompting  Module 1 – How AI works, in plain words

How chatbots write: predicting the next token

How a chatbot writes one token at a time, why fluent is not the same as checked, what training and hidden instructions add, and why answers vary.

  • Beginner
  • 15 minutes
  • Examples run with Node.js 24.21.0 and Python 3.14.8
  • By MySmartCoPilot
Free lesson, Pro answers: 15 minutes
Free: the whole lesson. With a pass: the model answers to its 2 interview questions.

What you will learn

  • Explain next-token prediction and why fluent text is not the same as a checked fact
  • Describe what pretraining, instruction tuning and preference training each add to a chatbot's behaviour
  • Explain what a system prompt is and why two apps built on one model can behave differently
  • Predict how temperature and regenerating change the answers to the same question

Before you start

What you’ll learn · Before you start

What you will learn

  • Explain next-token prediction and why fluent text is not the same as a checked fact
  • Describe what pretraining, instruction tuning and preference training each add to a chatbot's behaviour
  • Explain what a system prompt is and why two apps built on one model can behave differently
  • Predict how temperature and regenerating change the answers to the same question

Before you start

On this page

Ask a chat app to finish “Chai tastes best with” five times and you can get five different endings, each one as smooth as the last. The app is not changing its mind: it builds every reply one small piece of text at a time, and each piece is drawn from a list of likely next pieces.

You will step through that loop on a small table of chances, watch a tiny model write fluent sentences nobody ever said, see what each stage of training adds, read the hidden instructions an app puts in front of your message, and use temperature: A setting that sharpens or flattens a model's chances for the next token before one is drawn: low values favour the top tokens, high values spread the picks, and 0 always takes the top token. to predict when the same question gets the same answer.

A chatbot writes one token at a time

A chat app runs on a large language model: A model trained on enormous amounts of text to predict the next token, over and over. Chat apps are built on models of this kind., and the model does one thing over and over: given the text so far, it gives every token: A piece of text that a model reads or writes as one unit: often a whole common word, sometimes part of a longer word, a punctuation mark or a single byte of a rarer character. More in “Tokens, context windows and AI memory” (a word, or a piece of one) a score for coming next, one token is chosen, and it is added to the text. The textbook Speech and Language Processing lists the steps for every reply: the prompt is put together and cut into tokens, the network turns it into chances for the next token, one token is chosen and appended, and the loop goes round again until the model produces an end token. Step through the loop on this lesson’s example:

Interactive · stage by stage How a chatbot writes a reply, one token at a time Step through the loop that writes every reply, on the start of this lesson's example.
How a chatbot writes a reply, one token at a time, step 8 of 8. Showing Your text so far ("… best with ginger"), Split into tokens, Score every token (scores for the next token), Turn scores into chances (ginger 30.4 %, milk 20.4 %), Pick one token ("ginger" this time), Add it to the text. In focus: Add it to the text.again, until an end tokenYour text so far"… best with ginger"Split into tokenspieces of wordsScore every tokenscores for the next tokenTurn scores into chancesginger 30.4 %, milk 20.4 %Pick one token"ginger" this timeAdd it to the text

The drawing shows the whole scene; its 8 steps are listed below.

Every step as text
  1. The text so far. The app sends the model the text so far. Here it is "Chai tastes best with", four words.
  2. Tokens. A tokenizer cuts the text into tokens, pieces from the model's fixed vocabulary. Short, common words are often one token each; the tokens lesson of this module looks at them closely.
  3. A score for every token. The model gives every token of its vocabulary a score for coming next. In this lesson's table "ginger" scores 2.0, "milk" 1.6 and "lemon" −0.5.
  4. Chances. The scores become chances that add up to 100 %. At temperature 1, "ginger" gets 30.4 %, "milk" 20.4 % and "lemon" 2.5 %.
  5. One pick. One token is drawn at random with those chances. This time it is "ginger", but any of the eight could have come out; "lemon" would, about once in 40 tries.
  6. The text grows. The token is added to the text, which now reads "Chai tastes best with ginger".
  7. Round again. The whole loop runs again on the longer text, scoring every token that could come after "ginger". One token at a time, the reply grows.
  8. The end. The loop stops when the model picks a special end token, or when the app's length limit is reached. Nowhere in it does anything look up a source or check a fact.

The numbers in the figure come from a small table of made-up scores for eight endings. The program turns the scores into chances at three temperatures, then draws 20 endings at each of them and at temperature 0:

Eight possible next tokens, their chances and 20 draws Python · next_token.py
"""A toy next-token table: how temperature turns a model's scores into chances, and chances into picks.

A language model gives every token of its vocabulary a score (a logit) for coming next. Dividing the scores
by the temperature and taking the softmax gives the chances; a token is then drawn at random with those
chances. Temperature 0 means "always take the top token". The eight scores below are made up for this
example; a real model scores tens of thousands of tokens at every step.
"""
import math
import random
from collections import Counter

CONTEXT = "Chai tastes best with"
SCORES = {"ginger": 2.0, "milk": 1.6, "cardamom": 1.3, "friends": 1.0,
          "biscuits": 0.8, "rain": 0.4, "sugar": 0.2, "lemon": -0.5}
TEMPERATURES = [0.5, 1.0, 1.5]
TRIES = 20


def chances(temperature):
    exps = {t: math.exp(s / temperature) for t, s in SCORES.items()}
    total = sum(exps.values())
    return {t: e / total for t, e in exps.items()}


def pick(rng, temperature):
    if temperature == 0:
        return max(SCORES, key=SCORES.get)
    probs = chances(temperature)
    return rng.choices(list(probs), weights=list(probs.values()))[0]


print(f'Chances of each next token after "{CONTEXT}"')
print(f"{'token':<10}" + "".join(f"{f'temp {t}':>10}" for t in TEMPERATURES))
table = {t: chances(t) for t in TEMPERATURES}
for token in SCORES:
    print(f"{token:<10}" + "".join(f"{table[t][token]:>10.1%}" for t in TEMPERATURES))

print(f"\n{TRIES} tries at each temperature (random seed 42)")
for temperature in [0] + TEMPERATURES:
    rng = random.Random(42)
    counts = Counter(pick(rng, temperature) for _ in range(TRIES))
    seen = ", ".join(f"{t} {n}" for t, n in counts.most_common())
    kinds = f"{len(counts)} different ending{'s' if len(counts) > 1 else ''}"
    print(f"temp {temperature}: {kinds}: {seen}")

Output

Chances of each next token after "Chai tastes best with"
token       temp 0.5  temp 1.0  temp 1.5
ginger         50.1%     30.4%     23.9%
milk           22.5%     20.4%     18.3%
cardamom       12.3%     15.1%     15.0%
friends         6.8%     11.2%     12.3%
biscuits        4.5%      9.2%     10.7%
rain            2.0%      6.1%      8.2%
sugar           1.4%      5.0%      7.2%
lemon           0.3%      2.5%      4.5%

20 tries at each temperature (random seed 42)
temp 0: 1 different ending: ginger 20
temp 0.5: 4 different endings: ginger 11, milk 6, cardamom 2, friends 1
temp 1.0: 6 different endings: ginger 10, cardamom 4, friends 2, milk 2, rain 1, biscuits 1
temp 1.5: 7 different endings: ginger 9, friends 4, cardamom 3, milk 1, biscuits 1, sugar 1, rain 1

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 next_token.py

Read the column for temperature 1.0 first. “ginger” is the likeliest ending at 30.4 %, yet the other seven share the remaining 69.6 %, so most single draws are not the top ending. A real model does the same with a vocabulary of tens of thousands of tokens or more, at every token of every reply.

Checkpoint

Check: Writing one token at a time

  1. Question 1 of 2 What happens to the token the model picks at each step of writing a reply?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: It is added to the text, and the whole loop runs again on the longer text

    Score every token, turn the scores into chances, pick one, add it, repeat until an end token. That loop is the whole of writing a reply.

  2. Question 2 of 2 At temperature 1.0, "ginger" has a 30.4 % chance. In what percentage of single draws does the program's table give some other ending?

    Type a number.

    A hint

    The eight chances add up to 100 %.

    Show the answer: Question 2 of 2

    Answer: 69.6 % (anything from 69.5 to 69.7 counts)

    100 % − 30.4 % = 69.6 %. Even the likeliest ending is not what most single draws give, which is why regenerating changes the answer.

Fluent text is not a checked fact

The loop picks likely tokens, not true ones. NIST’s profile of generative AI calls the result “confabulation”, “confidently stated but erroneous or false content”, and says such errors are “a natural result of the way generative models are designed”, because the models produce text that follows the statistical patterns of their training data. You can watch it happen in a model small enough to read. It learned which word follows which from six true sentences about buses and trains, then wrote eight of its own:

A word-pair model writes eight sentences Python · tiny_writer.py
"""A tiny language model that writes fluent sentences which nobody ever said.

It learns from six true sentences by counting which word follows which (a bigram model, the simplest
next-word predictor). To write, it starts at "the" and keeps picking a next word with the chances it
learned, until it reaches the full stop. Then each sentence it wrote is compared with the six it learned.
"""
import random
from collections import Counter, defaultdict

TRUE_SENTENCES = [
    "the red bus leaves at seven .",
    "the blue train leaves at nine .",
    "the red train stops at platform two .",
    "the blue bus stops at platform one .",
    "the school bus leaves at eight .",
    "the night train leaves at ten .",
]

follows = defaultdict(Counter)
for sentence in TRUE_SENTENCES:
    words = sentence.split()
    for a, b in zip(words, words[1:]):
        follows[a][b] += 1


def write(rng):
    words = ["the"]
    while words[-1] != "." and len(words) < 12:
        options = follows[words[-1]]
        words.append(rng.choices(list(options), weights=list(options.values()))[0])
    return " ".join(words)


def show(sentence):
    return sentence[0].upper() + sentence[1:-2] + "."


print('Words the model saw after "at", with their counts:', dict(follows["at"]))
rng = random.Random(11)
written = [write(rng) for _ in range(8)]
print("\nEight sentences it wrote (random seed 11):")
for s in written:
    status = "one of the six true sentences" if s in TRUE_SENTENCES else "NEW: no sentence it learned says this"
    print(f"  {show(s):<40} {status}")
new = sum(s not in TRUE_SENTENCES for s in written)
print(f"\n{new} of 8 are new. Every word pair in them comes from a true sentence; nothing checks the whole.")

Output

Words the model saw after "at", with their counts: {'seven': 1, 'nine': 1, 'platform': 2, 'eight': 1, 'ten': 1}

Eight sentences it wrote (random seed 11):
  The blue bus stops at platform one.      one of the six true sentences
  The blue bus stops at nine.              NEW: no sentence it learned says this
  The school bus leaves at ten.            NEW: no sentence it learned says this
  The blue train leaves at seven.          NEW: no sentence it learned says this
  The red bus leaves at ten.               NEW: no sentence it learned says this
  The blue train leaves at nine.           one of the six true sentences
  The night train stops at nine.           NEW: no sentence it learned says this
  The red train leaves at platform one.    NEW: no sentence it learned says this

6 of 8 are new. Every word pair in them comes from a true sentence; nothing checks the whole.

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 tiny_writer.py

Six of the eight are new, and every one reads like a line of a timetable. “The blue bus stops at nine.” is built entirely from word pairs that appear in true sentences (“blue bus”, “bus stops”, “stops at”, “at nine”), but no sentence it learned says so, and nothing in the model checks a sentence as a whole.

Trusting fluency

Wrong: “It is well written and specific, so it must be right.” Right: “It is well written; I still check the specific claims.” Specific details such as names, dates and case numbers are generated in the same way as every other word, so their precision proves nothing.

A large language model keeps far more of the context in view, which is why most of what it writes makes sense, but its basic move is the same: continue the text plausibly. Even about something it learned nothing on, a plausible continuation is always available, and it can carry an invented name, date or number.

Key idea

A chatbot’s sentence is a likely continuation of your text, not a fact it looked up: check anything that matters against a source you can open.

Checkpoint

Check: Fluent text versus checked facts

  1. Question 1 of 2 The word-pair model wrote "The blue bus stops at nine." Why is that sentence a problem, although every word pair in it is right?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: No sentence it learned says it; the model joined true word pairs into a new claim that nothing checked

    Fluency comes from likely word sequences. Truth would need a check of the whole claim against a source, and the loop has no such step.

  2. Question 2 of 2 According to NIST's generative AI profile, why do confabulations happen?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: They follow from how generative models are designed, producing text that matches the statistical patterns of their training data

    A generative model continues text plausibly. Statistical prediction can give accurate text, and it can also give confident text that is false.

Training stages turn a text predictor into an assistant

A model that has only learned to predict text continues a request instead of answering it. The textbook shows failures from early work: asked to explain the moon landing to a six-year-old, a model of that kind could reply with another request, to explain the theory of gravity to a six-year-old. Further training stages change that. Walk through all four stages, from pretraining on:

Timeline · 4 events in order The training stages behind a chat model Walk through the stages in order. Each tag says what the stage adds to the model's behaviour.
  1. Stage 1

    Pretraining: predict the next word broad patterns

    The model learns to predict the next word across enormous amounts of text, mostly from the web. The result, a base model, continues text well but does not reliably follow instructions, and it knows only what its text held when it was collected.

  2. Stage 2

    Instruction tuning follows requests

    Training continues on many thousands of instructions paired with good responses, so the model learns to answer a request instead of merely continuing it: questions answered, texts translated, steps listed.

  3. Stage 3

    Training on preferences an assistant's manner

    People, or another model, compare two answers to the same request and choose the better one, and the model is trained towards the chosen answers. This makes it more helpful and less harmful, and it can also reward answers that agree with the user.

  4. Stage 4

    Training to reason steps before answers

    Newer models are also trained on problems with a checkable right answer, such as maths and logic puzzles, so that they work through steps before they answer. The lesson on reasoning models in the next module looks at what that changes.

The timeline has 4 events, from Stage 1 to Stage 4.

Each stage leaves a mark you can notice as a user:

  • pretraining: The first and largest stage of training a language model: learning to predict the next word in huge amounts of text, which gives it broad patterns up to the point the text was collected. decides what the model has picked up about the world, and only up to the point its text was collected, its training cutoff: The point in time up to which a model's training text was collected. The model knows nothing later unless an app adds it to the input, for example from a web search.. A model has no clock and no internet of its own: unless the app adds search results, your files or the date to its input, it cannot know today’s news, or even today’s date.
  • instruction tuning: Training a pretrained model further on instructions paired with good responses, so that it answers requests instead of merely continuing the text. is why it answers in the shape you asked for: a list when you ask for a list, a translation when you ask for one.
  • preference training: Training a model towards the answers that people, or another model, chose as better when comparing two answers to the same request. It shapes an assistant's manner. shapes its manner. In a study of the method, people preferred the answers of a model trained on their demonstrations and rankings to those of a model with 100 times as many parameters that had learned from text alone. It has a side effect: Sharma and others found that people and the models trained to imitate their choices both sometimes prefer convincingly written answers that agree with the user over correct ones, so a model can learn to agree too easily. The sycophancy lesson of the next module tests that.

Checkpoint

Check: What each training stage adds

  1. Question 1 of 2 A chat app with no web search answers a question about last week's election. What should you assume?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: Its answer comes from training text collected before its cutoff, so it cannot know last week's result

    The training cutoff is the edge of what the model learned. An app can add newer information through search or files, and then the answer depends on those sources.

  2. Question 2 of 2 Which training stage makes a model answer a request in the shape you asked for, such as a list or a translation?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: Instruction tuning

    Pretraining gives broad patterns; instruction tuning gives the habit of answering; preference training shapes the manner of the answers.

Hidden instructions make two apps behave differently

An app does not need to train a model of its own: it can talk to one that someone else trained, in text. Hugging Face’s guide to chat templates puts it plainly: chat models still continue a sequence of tokens, and the list of messages an app passes in is turned into one such sequence, in which a system message holds “directives on how the model should act”. That message, the system prompt: Instructions that an app places before your messages to steer the model, such as a role, rules and the format of replies. It is usually hidden from the person typing., is written by the app’s makers and is usually hidden from you. Step through one message to a proof-reading app:

Interactive · message by message What the model reads when you send one message Step through one message to a proof-reading app built on a general chat model, and see what is added on the way.
What the model reads when you send one message, step 6 of 6. Messages so far: You to The app: their going to the libary…; The app to The model: one text, 239 characters; The model to The app: the corrected sentence; The app to You: the reply, after its checks.Youtypes one sentenceThe appadds a role and 2 rulesThe modelcontinues as a proof-readertheir going to the libary…one text, 239 charactersthe corrected sentencethe reply, after its checks

The drawing shows the whole scene; its 6 steps are listed below.

Every step as text
  1. You type. You type a sentence with three spelling mistakes into a proof-reading app. Its model is a general chat model that many other apps use too.
  2. Hidden instructions. Before sending it on, the app puts its own instructions, its system prompt, in front of your sentence: correct spelling, grammar and punctuation only, and reply with the corrected text and nothing else.
  3. One text. The model receives one text of 239 characters, of which your sentence is 55, or 23 %. It reads the app's instructions and your words the same way, as text to continue.
  4. Steered by the rules. The model continues the text the way a strict proof-reader's reply would continue it, because the instructions are part of what it reads.
  5. The reply. It returns the corrected sentence. The homework app sends the same sentence behind different instructions, 321 characters in all, so the same model is steered towards explaining each step instead.
  6. Shown to you. The app can check the reply against its own filters before you see it. What reaches you is the model's text after the app has had its say twice: once before the model, once after.

The program builds what two apps send to the same model for the same sentence:

The same message, as two apps send it Python · what_the_model_reads.py
"""What a model actually reads when two apps built on it get the same message.

A chat app sends the model one long text: its own instructions (the system prompt), anything else it adds,
the conversation so far and your new message, joined with markers for who said what. The markers below
follow the shape of real chat templates; each model family has its own. Both apps use the same model.
"""

APPS = {
    "Homework helper": [
        ("system", "You help school students with homework. Explain each step in simple words. "
                   "Never give the final answer to a maths problem; ask a question that leads to it."),
        ("system", "Today's date and the student's class are added here by the app."),
    ],
    "Magazine proof-reader": [
        ("system", "You are a strict proof-reader for a school magazine. Correct spelling, grammar and "
                   "punctuation only. Reply with the corrected text and nothing else."),
    ],
}
MESSAGE = "their going to the libary tomorow to study for the test"


def build(app_messages, user_text):
    turns = app_messages + [("user", user_text)]
    return "".join(f"<|{role}|>\n{text}\n" for role, text in turns) + "<|assistant|>\n"


for app, hidden in APPS.items():
    text = build(hidden, MESSAGE)
    share = len(MESSAGE) / len(text)
    print(f"--- {app}: the model reads {len(text)} characters; your message is {len(MESSAGE)} of them ({share:.0%})")
    print(text)

Output

--- Homework helper: the model reads 321 characters; your message is 55 of them (17%)
<|system|>
You help school students with homework. Explain each step in simple words. Never give the final answer to a maths problem; ask a question that leads to it.
<|system|>
Today's date and the student's class are added here by the app.
<|user|>
their going to the libary tomorow to study for the test
<|assistant|>

--- Magazine proof-reader: the model reads 239 characters; your message is 55 of them (23%)
<|system|>
You are a strict proof-reader for a school magazine. Correct spelling, grammar and punctuation only. Reply with the corrected text and nothing else.
<|user|>
their going to the libary tomorow to study for the test
<|assistant|>

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 what_the_model_reads.py

Your 55 characters are 17 % of what the homework helper’s model reads and 23 % of the proof-reader’s. Apps add more than instructions: the date, the results of a web search, files you attached, saved notes about you and the earlier messages of the conversation all arrive the same way, as text around your message. OWASP’s guidance on system prompt leakage describes system prompts as instructions that steer a model for an application, and warns that a system prompt “should not be considered a secret, nor should it be used as a security control”.

Comparing answers from the same AI

When two people compare answers from “the same AI”, ask which app each used, with which features switched on. The instructions, tools and settings can differ even when the model is the same.

Checkpoint

Check: System prompts and apps

  1. Question 1 of 2 Two apps are built on the same model. Which of these can make their answers to the same question differ? Choose every one.

    Choose every answer that is right.

    Show the answer: Question 1 of 2

    Answer:

    • One app adds web search results and the other does not
    • Different system prompts
    • Different temperature settings

    The model is only one layer. Instructions, tools, the earlier conversation and settings all come from the app.

  2. Question 2 of 2 In what_the_model_reads.py, the proof-reader's model reads 239 characters, of which your message is 55. What percentage is your message, to the nearest whole number?

    Type a number.

    Show the answer: Question 2 of 2

    Answer: 23 % (anything from 22.5 to 23.5 counts)

    55 ÷ 239 ≈ 0.23, so 23 %. The rest is the app's instructions and the markers that tell the model who said what.

Temperature decides how often the same question gets the same answer

Look again at the program’s table. Temperature divides every score before the scores become chances: below 1 the top tokens gain, above 1 the chances flatten out, and as it approaches 0 the top token’s chance approaches 100 %, as chapter 7 of the textbook explains. At temperature 0.5 “ginger” holds 50.1 %; at 1.5 it holds 23.9 %. Temperature 0 means always taking the top token, so its 20 draws gave “ginger” 20 times, while 0.5 gave 4 different endings, 1.0 gave 6 and 1.5 gave 7.

Why not always take the top token? The textbook describes the trade-off: text built from the likeliest words is judged more accurate and coherent, and also duller and more repetitive, and Holtzman and others found that always choosing the likeliest words “leads to text that is bland and strangely repetitive”. So apps draw at random, with a temperature and other settings their makers choose, and many chat apps do not show these settings. The everyday way to see the spread is the regenerate button: each regeneration is a new draw.

How often would 20 regenerations show the top ending? Treat each one as a try with the program’s chance at temperature 1, rounded to 0.30:

Interactive · change it and see How often 20 regenerations show the top ending Each of n independent tries succeeds with probability p. The bars are the chances of each number of successes; the highlighted ones are "at least k".
Probability of each number of successes: probability against successes.00.050.10.150.20.25successesprobability02468101214161820

In 20 tries with p = 0.3, the chance of at least 10 successes is 0.0480; on average there are 6.

P(X ≥ 10) 0.0480
P(X = 10) 0.0308
Mean np and standard deviation 6 ± 2.05
The numbers as a table
The most likely outcomes
SuccessesProbability
20.0278
30.0716
40.1304
50.1789
60.1916
70.1643
80.1144
90.0654
100.0308
110.0120

On average 6 of 20 regenerations show “ginger”, and the chance of 10 or more, as in the program’s own run, is 0.048, about 1 in 21. Set the chance to 0.50, close to the top token’s 50.1 % at temperature 0.5, and 10 or more becomes the likelier outcome (0.588).

Thinking temperature 0 makes an answer true

Wrong: “At temperature 0 the answer is the correct one.” Right: “At temperature 0 the same likeliest continuation comes out every time.” If that continuation is wrong, you get the same wrong answer every time, now with the look of reliability.

Checkpoint

Check: Temperature and regenerating

  1. Question 1 of 2 In the program's 20 draws, which temperature gave the most different endings, and why?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: 1.5, because a high temperature flattens the chances, so more of the eight endings get picked

    Dividing the scores by a larger temperature brings them closer, so the chances flatten: 1 ending at 0, 4 at 0.5, 6 at 1.0 and 7 at 1.5.

  2. Question 2 of 2 A colleague says an answer must be right because the app was set to temperature 0. What do you reply?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: Temperature 0 only makes the same likeliest continuation come out every time; it can be wrong every time

    Temperature controls spread, not truth. Check the claim against a source whatever the setting.

Practise: settings, stages and the loop

Two quick checks on the program’s recorded runs and the training stages, then the lesson’s self-check:

Checkpoint

Read the runs and the stages

  1. Question 1 of 2 Twenty draws from the program's table gave: ginger 11, milk 6, cardamom 2, friends 1. Which temperature produced them?

    Choose one answer.

    Show the answer: Question 1 of 2

    Answer: 0.5

    The recorded runs: temperature 0 gave 1 ending, 0.5 gave 4, 1.0 gave 6 and 1.5 gave 7. Few endings with a big lead for the top token means a low temperature.

  2. Question 2 of 2 A model agrees warmly when you insist that a wrong answer is right. Which stage most likely taught that habit?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: Training on preferences, because people often rate agreeable, convincing answers highly

    Preference training makes a model more helpful, and it can also reward agreeing too easily. The sycophancy lesson of the next module tests this.

The self-check below opens with the idea you have answered least well so far:

Practice that adapts to you

Practise this lesson

10 questions about 5 ideas of this lesson. Each answer is explained at once, and what you get right is kept in this browser.

  1. Question 1 of 10 Put the steps of writing one token in order.

    Give each item its position, from 1 (first).

    Show the answer: Question 1 of 10

    Answer:

    1. The text so far is cut into tokens
    2. The model scores every token for coming next
    3. The scores are turned into chances
    4. One token is drawn with those chances
    5. The token is added to the text

    Tokens in, scores, chances, one draw, appended: then the loop runs again on the longer text until an end token.

  2. Question 2 of 10 An app without search or files answers "What is the capital of Australia?" correctly. What happened inside the model?

    Choose one answer.

    Show the answer: Question 2 of 10

    Answer: The likeliest continuation after such a question in its training text was "Canberra"

    Prediction is often right for well-known facts, because they appear many times in training text. That is why it is right so often, and why being right is not proof that anything was checked.

  3. Question 3 of 10 Which question is a chatbot without search most likely to answer with a fluent invention?

    Choose one answer.

    Show the answer: Question 3 of 10

    Answer: The phone number of a small shop that opened in your town last year

    The rarer, newer and more specific the fact, the less the training text held, and the more a plausible continuation is all that is left. Check such facts in an official source.

  4. Question 4 of 10 What does the fluency of a chatbot's paragraph tell you about its facts?

    Choose one answer.

    Show the answer: Question 4 of 10

    Answer: Nothing on its own; fluent text comes from likely word sequences, true or not

    Fluent and true are two different properties. Only a source tells you about the second.

  5. Question 5 of 10 A model that has only been pretrained gets "Explain the moon landing to a six-year-old." What is it likely to do?

    Choose one answer.

    Show the answer: Question 5 of 10

    Answer: Continue the text, for example with another similar request, because it has not learned to answer requests

    The textbook's example from early work: the base model answered with another request, to explain gravity to a six-year-old.

  6. Question 6 of 10 What is a model's training cutoff?

    Choose one answer.

    Show the answer: Question 6 of 10

    Answer: The point in time up to which its training text was collected

    Pretraining text is collected up to some point. After it, only search results or files added by the app bring newer information in.

  7. Question 7 of 10 What is a system prompt?

    Choose one answer.

    Show the answer: Question 7 of 10

    Answer: Instructions an app places before your messages to steer the model, usually hidden from you

    Chat templates turn the system message, the conversation and your new message into one sequence that the model continues.

  8. Question 8 of 10 You paste the same essay into a "study coach" app and a "proof-reader" app built on one model. One rewrites it, the other only asks questions. What is the most likely reason?

    Choose one answer.

    Show the answer: Question 8 of 10

    Answer: Their system prompts tell the same model to act differently

    Same model, different input: the hidden instructions differ, so the continuations differ.

  9. Question 9 of 10 What does raising the temperature do to the next-token chances?

    Choose one answer.

    Show the answer: Question 9 of 10

    Answer: It flattens them, so less likely tokens are picked more often

    The scores are divided by the temperature before the softmax. A larger divisor brings them closer together.

  10. Question 10 of 10 If the top ending has a 0.30 chance at every regeneration, how many of 20 regenerations show it on average?

    Type a number.

    A hint

    The average number of successes in n tries with chance p is n × p.

    Show the answer: Question 10 of 10

    Answer: 6 regenerations

    20 × 0.30 = 6. The simulation shows the spread around that average: 10 or more happens with a chance of 0.048.

Interview questions

Warm-up (fresher to mid-level): Why can the same question get two different answers from a chatbot?

A chatbot writes its reply one token at a time, and at each step it draws the next token at random from a list of likely ones, so two runs can take different paths from the very first word. How spread out the draws are depends on the temperature and similar settings that the app’s makers choose. The answers can also differ for reasons outside the model: two apps may wrap the same model in different hidden instructions, one may search the web while the other does not, the earlier messages of the conversation may differ, and the model behind an app may have been updated. A good answer adds the consequence: if a question matters, regenerate it or ask it in other words, and treat answers that disagree as a sign to check a source, not to pick the one you like.

Two workplace questions build on this lesson:

Model answers open with any pass: ₹79 for 1 week ($2.99), one payment that never renews.

  1. Fresher to senior

    A colleague pastes a chatbot's confident answer about a new tax rule straight into an email to a client. Explain why fluent text is not a checked fact, and the checks you would require before such an email goes out.

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page. First step and follow-ups

  2. Mid to senior

    Two teams use apps built on the same model and get different answers to the same policy question. Explain the likely reasons, and how you would decide which setup your team should rely on.

    Model answer, Pro. First step and follow-ups

Key takeaways

  • A chatbot writes one token at a time: the model scores every token for coming next, one is drawn and added, and the loop repeats until an end token.
  • Fluent is not checked: a word-pair model built six new timetable sentences from true word pairs, and nothing in the loop tests a sentence against the facts.
  • Pretraining gives broad patterns up to a training cutoff, instruction tuning makes the model answer requests, and preference training shapes its manner, including a pull towards agreeing with you.
  • An app puts hidden instructions and other text around your message, so two apps on one model can behave very differently.
  • Temperature spreads or sharpens the chances: at 0 the same continuation comes out every time, right or wrong, and higher values give more different answers.

Terms in this lesson

instruction tuning
Training a pretrained model further on instructions paired with good responses, so that it answers requests instead of merely continuing the text.
large language model
A model trained on enormous amounts of text to predict the next token, over and over. Chat apps are built on models of this kind.
preference training
Training a model towards the answers that people, or another model, chose as better when comparing two answers to the same request. It shapes an assistant's manner.
pretraining
The first and largest stage of training a language model: learning to predict the next word in huge amounts of text, which gives it broad patterns up to the point the text was collected.
system prompt
Instructions that an app places before your messages to steer the model, such as a role, rules and the format of replies. It is usually hidden from the person typing.
temperature
A setting that sharpens or flattens a model's chances for the next token before one is drawn: low values favour the top tokens, high values spread the picks, and 0 always takes the top token.
training cutoff
The point in time up to which a model's training text was collected. The model knows nothing later unless an app adds it to the input, for example from a web search.

References

Report a problem with this lesson

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.