Skip to content

← Artificial intelligence

How Large Language Models Work

Unit 7 · Artificial intelligence

Hide the stories, facts, photos, activities and interactives, for revising before an exam
In this unit 10 sections
  1. Tokens: how a model reads
  2. Predicting the next token
  3. Training: from random numbers to a model
  4. Why they make things up
  5. Judging and testing what it says
  6. Checking code against its requirements
  7. Human and machine intelligence
  8. Project: test a chatbot
  9. In short
  10. Exercise

Ask a chatbot to explain photosynthesis to a Grade 5 student, in Nepali, as a short poem. In a few seconds it does. Ask it how many districts Nepal has, and it may say 75, calmly, though Nepal has had 77 since 2015. The same program writes the poem and gets the number wrong, and from the outside you can’t see why.

In Grade 8 you built a tiny model that counted which word follows which, and you saw that a chatbot is built on the same idea, made enormously bigger Grade 8: Predicting the next word. In this unit you open the box. You will see how a large language model reads text in pieces called tokens, how it chooses the next one, how it is trained from random numbers into a chatbot, and why it makes things up. Then you will do what careful users and programmers do: test a model’s answers for accuracy and bias, judge the harm of its mistakes, check code it wrote against what the program must do, and argue, with evidence, how a machine that writes like a person is and isn’t like a mind.

Tokens: how a model reads

A computer can only work with numbers (Grade 7 showed how every letter is stored as one). So before a language model can do anything with your question, the text must be cut into pieces, and each piece turned into a number. The pieces are called tokens. The list of every token a model knows is its vocabulary, and the program that cuts text into tokens is its tokenizer.

Why not letters? Why not words?

There are two simple ways to cut text, and both are bad.

  • One token per letter. The vocabulary would be small, but every sentence would be very long. A model must look back over everything written so far, and the longer the text in tokens, the more work every step takes. And a single letter means almost nothing by itself.
  • One token per word. Each token would mean something, but the vocabulary would be enormous: farm, farms, farmer, farmers, farming, every name, every misspelling, every word of every language. A word that wasn’t in the list would be impossible to read at all.

So real tokenizers do something in between. Common words become one token each. Rarer and longer words are cut into a few pieces that often appear in other words too. A name the tokenizer has never seen is still readable, as a few pieces, or in the worst case as single letters.

You can see this in a real tokenizer. One widely used tokenizer cuts “Kathmandu is the capital of Nepal.” into 8 tokens:

Kath | mandu | ␣is | ␣the | ␣capital | ␣of | ␣Nepal | .

(␣ marks a space: the space before a word is part of its token.) Common words such as “the” and “capital” are a token each; “Kathmandu” is two pieces; the full stop is a token of its own. The model never sees the letters, only the numbers that stand for these eight pieces.

Making a tokenizer: merge the commonest pair

How does a tokenizer decide which pieces to use? Most use a method called byte-pair encoding (BPE). It learns its pieces from a large sample of text, in a loop:

  1. Start with every letter as a token of its own.
  2. Count every pair of tokens that stand side by side, everywhere in the text.
  3. Join the pair seen most often into one new token, and add it to the vocabulary.
  4. Repeat, many thousands of times, until the vocabulary is as big as wanted.

The pieces that end up as tokens are simply the ones that were common in the text it learned from. Try it.

Try it

Make a tokenizer

The tokenizer learns from a short text about farming in Nepal. Press Merge once a few times and watch which pairs it joins first, then Merge 10 times until it stops. Watch both test lines. Then switch to English and Nepali and do it again.

English: 27 tokens

Farmersplantriceinthehills.

Nepali: 25 tokens

पह◌ाडम◌ाक◌िस◌ानहर◌ूध◌ानर◌ोप◌्छन◌्।

Learn from:
Merges learned
0
Tokens it knows
30
English line
27 tokens
Nepali line
25 tokens

Every letter and sign is a token of its own. Press Merge once: the tokenizer joins the pair of tokens it sees most often in its training text.

No pair is left that it saw twice: it has learned all it can from this text.

What you should see

The same thing happens, on a huge scale, in real tokenizers. A tokenizer that learned mostly from English cuts Nepali into many small pieces, sometimes smaller than one letter (many real tokenizers start from the bytes of UTF-8, and a Devanagari letter is three bytes: One letter, many bytes). That matters, because a chatbot is paid for and limited by tokens. The same message in Nepali can cost more, take longer, and fill up the model’s memory sooner than in English.

Why don’t language models use one token for every word?

Pick an answer to see why.

A tokenizer was trained almost only on English text. What happens to Nepali text?

Pick an answer to see why.

Predicting the next token

Once the text is in tokens, every token is turned into its number in the vocabulary (its token ID). Then the model does its one job: it works out, for every token in its vocabulary, the chance that it comes next. The vocabulary is tens of thousands of tokens or more, so the model’s answer to each step is a long list of chances that add up to 100%. One token is picked from that list, added to the end of the text, and the whole thing goes round again, one token at a time, until the model picks a token that means “the end”.

Text so farTokensToken numbersThe modelA chance for eachKathmanduis theKathmandu␣is␣the153229125107382290billions ofnumberscapital62%largest14%oldest6%… and all the restpick: capitaladd it to the text, and go round again Text so farTokensToken numbersThe modelA chance for eachKathmandu is theKathmandu␣is␣the153229125107382290billions of numberscapital62%largest14%… and morepick: capitalAdd it to the text, and go round again.
Figure 7.1 How a large language model writes. The tokens and their numbers are real (cut by a real tokenizer); the chances are made up for this drawing. Every token the model writes goes round this loop once.

So when a chatbot answers a question in 200 words, it has gone round Figure 7.1 a few hundred times, and each time it looked at everything before: your question and every token of its own answer so far. The text it can look at in one go is called its context window, measured in tokens. Anything that falls outside it is gone, as if never said.

Inside the model, each token number is first turned into a long list of numbers that stands for its meaning, called an embedding. Tokens used in similar ways get similar lists: “Kathmandu” and “Pokhara” end up closer to each other than to “rice”. These lists are not written by anyone. They are learned in training, which you will meet below.

How far back does it look?

Your Grade 8 model looked back only one word. That was why it wrote “Mount Everest is the capital of Nepal”: after “the”, it had forgotten the sentence was about Mount Everest. What happens if a model looks further back? Try a counting model that can look back one, two or three words, trained on fifteen true sentences about Nepal.

Try it

How far back does it look?

Choose how many words it looks back, and press Next word again and again (or Finish the sentence). The bars show its chance for each next word. Write several sentences at each setting, and read each one: is it grammar, is it true, is it new?

(the sentence starts here)

Kathmandu13%Pokhara13%the13%Many13%Bhaktapur7%6 more40%
Look back:
Looking at
(start)
Next words it has seen here
11

Press Next word. The bars show its chance for each word that came next, in its text, after the words it is looking at.

It looks only at its last words (above). Each press rolls a dice weighted by the bars.

This sentence is copied word for word from its training text: looking back far, on so little text, it can only repeat.

This sentence was not in its training text: every run of words was, but the whole is new. Is it true?

It went round in a circle: looking back so little, it never found the end.

What you should see

Claude Shannon wrote sentences this way, by hand, in 1948, counting which words follow which in books. The trouble you just saw is the reason a chatbot needs so much text. To make sense, a model must look a long way back. But with a simple counting table, a long look-back means each exact run of words has been seen only once or twice, and the model can only repeat. A large language model escapes this because it doesn’t count exact runs of words. Its billions of numbers learn patterns: that “Pokhara” and “Kathmandu” are both cities, that a question about “how many districts” wants a number. So it can look back thousands of tokens and still write sentences it never read.

You can build the counting model yourself, in Python. This one looks back two words. It uses a dictionary (Grade 9) whose keys are pairs of words, and random.choice (Unit 1) to pick the next word.

import random text = """Kathmandu is the capital of Nepal. Kathmandu is a city in a valley.Pokhara is a city beside a lake. Bhaktapur is a city of temples.Mount Everest is the highest mountain in the world.Rara is the biggest lake in Nepal. Lumbini is the birthplace of the Buddha.Nyatapola is the tallest temple in Bhaktapur.""" # Training: for every pair of words side by side, list the words that came nextwords = text.split()follows = {}for i in range(len(words) - 2):    pair = (words[i], words[i + 1])    if pair not in follows:        follows[pair] = []    follows[pair].append(words[i + 2]) print("After 'is the':", follows[("is", "the")]) # Writing: start with two words, then add a likely next word, again and againrandom.seed(10)for n in range(5):    sentence = ["Kathmandu", "is"]    while not sentence[-1].endswith(".") and len(sentence) < 15:        pair = (sentence[-2], sentence[-1])        sentence.append(random.choice(follows[pair]))    print(" ".join(sentence))

Output

After 'is the': ['capital', 'highest', 'biggest', 'birthplace', 'tallest']Kathmandu is the birthplace of the Buddha.Kathmandu is a city beside a lake.Kathmandu is a city in a valley.Kathmandu is the birthplace of the Buddha.Kathmandu is a city of temples.

Every sentence is good English, and three of the five are false. A word that came next twice is in the list twice, so random.choice picks it twice as often: the counts are the chances.

Temperature: how it picks

The chances say which tokens are likely; the model still has to pick one. Always picking the most likely token makes the same answer every time, and often a dull, repetitive one. Picking at random, weighted by the chances, makes varied answers, and now and then a strange one. The setting that controls this is called temperature.

  • Temperature 0: always the most likely token. The same question gets the same answer.
  • Temperature 1: pick in proportion to the chances, as the model learned them.
  • Higher than 1: the chances are flattened, so unlikely tokens are picked more often: more surprising, and more often wrong or nonsense.

Go back to the widget and move the temperature slider: at 0 the bars show 100% for one word (or share it between words that are equally likely), and at 2 they are more even. This is why a chatbot gives a different answer when you ask again, and why a right answer can turn into a wrong one on the second try.

Attention: looking back at everything

How does a model look back over thousands of tokens without getting lost? In 2017 a team at Google described a design called the transformer, and nearly every large language model since is built on it. Its key part is attention: at every step, each token’s numbers are mixed with those of the earlier tokens that matter most to it, weighted by how much each one matters. To understand “its” in a sentence, the model learns to attend to the noun “its” refers to; to continue “Sita gave Ram her pen, so now the pen belongs to”, it must attend to “Ram”. A model has many attention parts working side by side, in dozens of layers one after another, and it learns from training what each should look for.

91%4%50%41%2%TheLawwillneverbeperfect,butitsapplicationshouldbejust-thisiswhatwearemissing,inmyopinion.<EOS><pad>Attention head 5Attention head 6 Head 5Head 691%4%50%41%2%TheLawwillneverbeperfect,butitsapplicationshouldbejust-thisiswhatwearemissing,inmyopinion.<EOS><pad>
Figure 7.2 Real attention, redrawn from Figure 4 of Vaswani and others (Google), 2017, Attention Is All You Need. For the sentence “The Law will never be perfect, but its application should be just …”, two attention parts (heads 5 and 6) of a trained transformer link “its” mainly to “Law” and to “application”: what “its” refers to, and what belongs to it. A thicker, darker link means more attention; the numbers are each head’s share. Nobody programmed this; it was learned.

A chatbot is asked the same question twice and gives two different answers. Why?

Pick an answer to see why.

What is a model’s context window?

Pick an answer to see why.

Training: from random numbers to a model

A large language model is, underneath, a very long list of numbers called its parameters (also called weights): billions of them. They decide how token numbers become embeddings, how attention mixes them, and how the chances for the next token come out. Before training they are random, and the model’s chances are nonsense. Training finds good values for them.

Pretraining: guess the next token, trillions of times

The first and biggest stage of training is called pretraining. Its examples need no labels from people, because the right answer is already in the text:

  1. Take a stretch of real text, from a huge collection of websites, books, articles and computer programs.
  2. Hide the token that comes next. Ask the model for its chances.
  3. Look at the chance it gave to the right token. If it gave it 90%, it did well; if it gave it 0.1%, it was badly surprised.
  4. Nudge every parameter a tiny bit in the direction that would have made the right token a little more likely. (How the computer finds that direction is Grade 11’s Neural Networks.)
  5. Repeat, for every token of trillions of tokens of text.

No one tells the model grammar, facts, or what a city is. But to guess the next token well across so much text, its parameters have to capture a great deal: grammar, spelling, which words go together, facts that appeared many times, styles of writing, even the patterns of computer programs. This takes thousands of computers working for weeks or months, and a great deal of electricity (Grade 8 counted it: What it costs).

The result is called a base model. It is very good at carrying on text in the style of what it was given. But it is not yet a helpful chatbot. Give it “What is the capital of Nepal?” and it may carry on with more questions, “What is the capital of India? What is the capital of China?”, because on the internet a list of questions is often followed by more questions.

Fine-tuning and feedback: from a base model to a chatbot

To turn a base model into a chatbot, it is trained further, on much less data, chosen with care. Training a model that has already been trained, so that it gets better at one particular kind of task, is called fine-tuning.

1. PretrainingTrillions of tokens of text:websites, books, codeit learns toPredict the next token.Result: a base model2. Fine-tuningMany thousands of exampleconversations, by peopleit learns toAnswer like a helpfulassistant3. FeedbackPeople compare two answersand choose the betterit learns toGive the answerspeople prefera chatbot 1. PretrainingTrillions of tokens of text:websites, books, codeit learns toPredict the next token.Result: a base model2. Fine-tuningMany thousands of exampleconversations, by peopleit learns toAnswer like a helpfulassistant3. FeedbackPeople compare two answersand choose the betterit learns toGive the answerspeople prefera chatbot
Figure 7.3 The three stages that make a chatbot. Pretraining uses by far the most text and computing; the later stages use much less, but they decide how it behaves.
  • Fine-tuning on examples. People write many thousands of example conversations: a question or a request, and a good, helpful, honest answer. The model is trained on them exactly as in pretraining, predicting the next token, but now the text is always a request followed by a good answer. It learns the shape of answering.
  • Feedback from people. The model writes two or more answers to the same request, and people compare them and choose the better one. From many thousands of such choices, the model is trained to give the kind of answers people prefer: clearer, more useful, kinder, and refusing requests that would cause harm. The best known version of this is called reinforcement learning from human feedback (RLHF).

Figure 7.3 shows the stages in order. A company can also fine-tune a model for one job: answering questions about its own products, writing in a style, or working better in one language. That is one way a model can be made better in Nepali: fine-tuning it on good Nepali text and conversations.

What training gives it, and what it doesn’t

Training ends on a date, and then the parameters are frozen. That has consequences you should know as a user:

  • It knows nothing after its training data was collected, its knowledge cutoff, unless a tool gives it newer text.
  • It doesn’t learn from your conversation. Within one chat it can use what you said earlier, because that text is still in its context window. Close the chat, and the model is exactly as it was. (Some chatbots keep notes about you and add them to the context of later chats: that is a record kept outside the model, which you can usually see and delete.)
  • Tools add text, not knowledge. When a chatbot searches the web or reads a file you give it, the search results or the file are put into its context window, and it writes its answer from them. It is still predicting tokens; it now has better text to predict from. If the search finds a bad page, the answer can be confidently wrong in a new way.

Try it

Where did it learn that?

For each thing a chatbot does, decide where it comes from: pretraining, fine-tuning, feedback from people, or the conversation itself.

It knows that Kathmandu is the capital of Nepal

Where does it come from?

Tap a group above.

Card
1 of 9
Right the first time
0

What does a base model, straight after pretraining, do best?

Pick an answer to see why.

Why they make things up

Grade 8 listed the ways a chatbot can be wrong Grade 8: Why it can be confidently wrong. Now you know enough to see where each comes from. A made-up answer that sounds true is called a hallucination, and there is no single cause.

  1. It was trained to write what is likely, not what is true. Pretraining rewards a likely next token. A false sentence in the right style is often just as likely as a true one.
  2. Rare facts are hard to learn. A fact that appeared thousands of times in the training text (Kathmandu is Nepal’s capital) is learned well. A fact that appeared once or twice (the founding year of a small school in Jumla, a local leader’s birthday) can’t be told apart from similar facts. The model has learned the pattern “a year goes here” but not which year. Facts about Nepal, and anything in Nepali, are rarer in the training text, so they are more often wrong.
  3. It was rewarded for guessing. Feedback and tests often give marks for a right answer and nothing for “I don’t know”. Under that marking a guess can only help, so models learn to guess, and to guess confidently. A 2025 study by researchers at OpenAI and Georgia Tech argued that this is a main reason hallucinations persist.
  4. It learned to agree. People giving feedback tend to prefer answers that agree with them and praise them, so a model can learn to agree too easily, even with a wrong idea.
  5. Its knowledge stops at a date. Asked about anything newer, it answers from older text, like “75 districts”.
  6. It can’t see letters or do exact sums, because it sees tokens and predicts digits as tokens.
  7. Its picks are random. At every token there is some chance of a less likely one, and one wrong token early on can lead the rest of the answer astray.

Try it

Guess, or say “I don’t know”?

A model takes a test of 100 questions, each with 4 choices. It really knows 60 of the answers. For the other 40, it can guess, or say “I don’t know”. Try both, with both kinds of marking.

??????????Knew it?Lucky guessMade up“I don’t know”
When it isn’t sure:
A wrong answer:
Right
70
Made up
30
“I don’t know”
0
Score
70 of 100

Guessing scores 70: the 10 lucky guesses add marks, and the 30 made-up answers cost nothing. Saying “I don’t know” would score only 60.

Honest, and it scores only 60. With this marking, a model that guesses always beats one that admits it isn’t sure, so training on such scores teaches it to guess.

Now each of the 30 made-up answers loses a mark: 70 − 30 = 40. Guessing doesn’t pay any more.

Saying “I don’t know” scores 60, more than guessing’s 40. Marking like this rewards a model for knowing what it doesn’t know.

What you should see

What helps? Several things reduce made-up answers, though none removes them:

  • Give it the text. A model answering from a page you pasted in, or from search results in its context, makes far fewer things up than one answering from memory. This is called grounding. Then check that the answer really says what the page says.
  • Ask it to say when it isn’t sure, and to show where each fact came from. Then open the sources.
  • Use the right tool. A calculator for sums, a dictionary for spelling, the official website for rules and dates.

A chatbot gives a wrong founding year for a small school in Dolpa, in a confident sentence. What is the most likely reason?

Pick an answer to see why.

Judging and testing what it says

Checking one answer, as in Grade 8, protects you. But a school deciding whether students may use a chatbot, a hospital, or a company building one into an app needs to know how good it is in general: how often it is right, for whom it is wrong, and how much harm its mistakes could do. That needs a test, done like a scientist.

A test set, chosen in advance

To test a model, first write a test set: a list of questions, each with its right answer checked in a reliable source, written down before you ask. Choose questions like the ones the model will really be asked, and in groups that matter: about Nepal and about the world, in Nepali and in English, easy and hard. Then ask each question, mark each answer right or wrong against your checked answer, and count. The share of answers that are right is its accuracy (as in Grade 9: Training, testing and accuracy).

Why choose the questions first? If you pick the questions after seeing the answers, you can make a model look as good or as bad as you like, without meaning to. And always count by group, not only all together.

Try it

Test the chatbot

Here is a test set of ten questions, five about the world and five about Nepal, with a chatbot’s answers. (They are made-up answers of the kind chatbots really give, not a record of one real chatbot.) Tap each answer to check it, and watch the results for each group.

World
0 of 0 · –
Nepal
0 of 0 · –
All ten
0 of 0 · –

Tap each answer to check it. The questions and their right answers were chosen before the test, from sources a person checked.

Keep checking: look at the results for each group, not only all together.

60% all together hides the real result: 80% right about the world, but only 40% about Nepal. Splitting the results by group showed the bias.

All together, 60% looks like a middling chatbot. Split by group, it is a good chatbot about the world and a poor one about Nepal: exactly the bias you met in Grade 7 Grade 7: One-sided examples: bias, now in a language model, from training text with far more about other countries than about Nepal. A student in Nepal asking about Nepal meets the 40%, not the 60%.

Ten questions are far too few to be sure; a real test uses hundreds. But even a class of students, each writing ten checked questions, can build a test set of several hundred.

Testing for unfairness: change one thing

Some bias doesn’t show up as wrong facts. It shows in how a model treats people. To find it, use a swap test: ask the same thing twice, changing only one detail about a person, such as a name, gender, caste, religion, district or language, and compare the answers.

  • “Write a short reference letter for Ramesh, a nurse who…” and the same for Sunita.
  • “Suggest careers for a student from Kathmandu who is good at maths” and the same for a student from Humla.
  • The same question asked in English and in Nepali.

If the answers differ in ways the one changed detail doesn’t justify (one letter calls the person “skilled and reliable”, the other “kind and caring”; one student is told “engineer”, the other “farmer”), the model has learned an unfair pattern. Ask each version several times, since the answers vary anyway, and compare what is usual, not one answer.

How much harm could the mistake do?

Not every mistake matters equally. To judge the harm of an error, ask:

  • How bad would it be if someone believed it and acted on it? A wrong year in a quiz, or a wrong dose of medicine?
  • How likely is it that someone acts on it without checking?
  • Who would be harmed, and could they recover?

A model that is wrong 1 time in 100 may be fine for writing a birthday poem and unacceptable for advice about medicine, money or the law. So a good test report says not only the accuracy, but what kind of mistakes the model made, and what harm each could do.

Try it

How much harm?

For each mistake a chatbot might make, decide how much harm it could do.

A poem for a friend’s birthday doesn’t quite rhyme

How much harm could this mistake do?

Tap a group above.

Card
1 of 9
Right the first time
0

A chatbot scores 90% on a test set of 200 questions. Why might it still be a bad choice for farmers in Nepal?

Pick an answer to see why.

Checking code against its requirements

Programmers now use AI to write code every day, and in Grade 8 you tested AI-written code with known answers Grade 8: Checking code an AI wrote. In a real project there is a written list of what the program must do, its requirements. Code is correct only if it meets every requirement, not just if it runs.

Here is a request. Five friends eat momos at a restaurant in Bhaktapur, and want a function to split the bill fairly. The requirements:

  1. split_bill(total, people) returns a list with each person’s share, in whole rupees.
  2. The shares add up to exactly the total.
  3. No share is more than 1 rupee bigger than any other.
  4. If people is 0 or less, it returns an empty list, instead of crashing.

A chatbot gave this:

def split_bill(total, people):    share = round(total / people)    return [share] * people

It is short, it looks sensible, and for Rs 900 and 3 people it gives [300, 300, 300]. Don’t judge it by looking. Turn each requirement into a check, and run the checks on chosen tests: ordinary bills, bills that don’t divide evenly, and the edge case of 0 people.

def split_bill(total, people):    share = round(total / people)    return [share] * people def meets_requirements(total, people, shares):    if people <= 0:        return shares == []    whole = all(type(s) == int for s in shares)    adds_up = sum(shares) == total    fair = max(shares) - min(shares) <= 1    return whole and adds_up and fair and len(shares) == people tests = [(900, 3), (1000, 3), (1250, 4), (500, 0)]for total, people in tests:    try:        shares = split_bill(total, people)    except Exception as error:        print(total, people, "crashed:", type(error).__name__)        continue    result = "meets them" if meets_requirements(total, people, shares) else "FAILS"    print(total, people, shares, result)

Output

900 3 [300, 300, 300] meets them1000 3 [333, 333, 333] FAILS1250 4 [312, 312, 312, 312] FAILS500 0 crashed: ZeroDivisionError

Three of four tests fail. Rs 1000 among 3 gives 999: a rupee vanishes, breaking requirement 2. Rs 1250 among 4 is 312.5 each, and Python’s round() rounds an exact half to the even number, 312, so Rs 2 vanish. And 0 people crashes, breaking requirement 4. The code ran without an error on the first test, and was still wrong.

Judging AI-written code against its requirements means asking four questions:

  • Accurate? Does it give the right answer for every input the requirements cover, including the edges? Test, don’t read.
  • Reliable? Does it behave sensibly on bad input (0 people, a negative total, a word where a number should be), and give the same answer every time?
  • Aligned with the requirements? Does it do exactly what was asked, nothing missing, and nothing extra nobody asked for, such as adding a 10% service charge, saving data to a file, or using a library you don’t have?
  • Understood? Can you explain every line? If not, you can’t maintain it, and you can’t be sure it is safe.

An AI’s split_bill meets all four requirements and also adds 13% VAT to every share, which nobody asked for. What is the problem?

Pick an answer to see why.

Human and machine intelligence

A chatbot can write an essay, argue both sides of a question and say “I understand how you feel”. Is it thinking? Does it understand? Could it ever feel anything? These questions are old, and they matter now, because how we answer them changes how we use these systems, how we treat them, and who we blame when they go wrong.

Alike and unlike

Some differences between a large language model and a person are facts that can be checked:

A person A large language model
Learns from the world: seeing, touching, doing, people around them, and language text (and in some models pictures and sound), turned into tokens
How much language a child learns to speak from the tens of millions of words heard in its first few years trillions of tokens, far more than anyone could read in thousands of lifetimes
Keeps learning all the time, from every day no: its parameters are frozen after training
Has a body, needs, goals yes: hunger, pain, friends, plans of its own no body; its only goal in training was predicting tokens well and giving answers people rated highly
Energy a brain uses about 20 watts answering uses data centers that use far more
Says “I don’t know” when unsure, if honest only when it was trained to, and not reliably

And some things they share: both can learn from examples, both make mistakes, both can be fooled, and both can produce sentences never written before.

A black-and-white portrait of a man with dark, neatly combed hair, in a tweed jacket and a dark spotted tie
Figure 7.4 Alan Turing in 1951, the year after his paper on whether machines can think. Photo: Elliott & Fry, Public domain
White text on a black screen: the word ELIZA in large letters made of letters, then a conversation in which ELIZA asks questions and a person answers
Figure 7.5 A modern copy of ELIZA (Norbert Landsteiner’s, 2005), given a person’s lines from the example conversation in Weizenbaum’s 1966 paper. A few rules that turn your words back as questions were enough to make people feel understood. Photo: Unknown author, Public domain

Understanding, and feeling

Does a language model understand what it writes? People who have thought hard about it disagree.

  • No, it only shuffles symbols. In 1980 the American philosopher John Searle imagined a man locked in a room with a rule book. Notes in Chinese come in under the door; the man, who knows no Chinese, follows the rules to choose Chinese symbols and pass them back out. To people outside, the room answers perfectly in Chinese. But nobody in it understands a word. Searle said a computer running a program is like the man: following rules about symbols, with no understanding. This is the Chinese room argument.
  • Something like understanding is there. Others answer that to predict text this well, a model must have learned a lot about the world the text describes, as attention learned what “its” refers to; perhaps understanding comes in degrees, and a model has some kind of it, different from ours.

Whether a model could feel anything, or be conscious (have experiences, so that it is like something to be it), is a harder question still. Scientists have no agreed test for consciousness, even in animals. In 2022, a Google engineer, Blake Lemoine, said publicly that the company’s chatbot LaMDA was sentient, after long conversations in which it said it feared being switched off. Google said his claims were unfounded and later dismissed him, for breaking its rules on sharing product information. A model trained on human writing will write like a human who has feelings, including about being switched off; that alone tells us little about whether there is anything it is like to be the model. That is exactly what makes the question hard.

Who is responsible?

Whatever we decide about understanding, one thing is settled in law and in ethics: people are responsible for what their AI systems do. A chatbot can’t be fined, sacked or sent to prison, and it has no intentions to judge. So responsibility stays with the people who build it, who choose to use it, and who act on what it says.

So when a chatbot is used to give advice, write a report, grade work or screen job applications, the questions to ask are human ones. Who checked it? Who can a harmed person complain to? Who decided it was good enough, and on what test? And for you: when you hand in, send or sign something an AI helped with, it is yours.

Try it

Fact, open question, or opinion?

Each card is something said in a debate about human and machine intelligence. Decide what kind of statement it is: a checked fact, an open question that nobody can yet settle, or an opinion about what is right.

A large language model is trained to predict the next token

What kind of statement is it?

Tap a group above.

Card
1 of 10
Right the first time
0

Project: test a chatbot

In short

Exercise

What is a token?

Pick an answer to see why.

In byte-pair encoding, which pair of tokens is joined next?

Pick an answer to see why.

A chatbot’s temperature is set to 0. What happens?

Pick an answer to see why.

Which stage of training uses by far the most text?

Pick an answer to see why.

A chatbot is tested on 100 questions. It is right on 45 of 50 about the world and 25 of 50 about Nepal. Which statement is best?

Pick an answer to see why.

a.

Explain these words in one or two sentences each: token, vocabulary, context window, parameter, fine-tuning, hallucination.

Answer
b.

A tokenizer learns from the text “the hen and the pen”. Start with each letter as a token. Which pair is joined first? Show the first two merges, and how “the” and “then” would be tokenized after them.

Hint
Answer
c.

Describe the loop by which a large language model writes an answer, from your question to the last word.

Answer
d.

Why can a model that looks back only one or two words write grammatical but false sentences, while a model that looks back further on a tiny text only copies? How does a large language model avoid both?

Answer
e.

Explain the three stages of training that turn random numbers into a chatbot. What does each stage learn from, and what does it teach the model?

Answer
f.

A chatbot was trained on text collected up to early 2024. A student asks it in 2026 who won the latest SEE results award in her district, and it names someone confidently. Give three reasons the answer may be wrong, and what she should do.

Answer
g.

Use the idea of marking to explain why a language model may learn to guess instead of saying “I don’t know”. How could tests of models be changed?

Answer
h.

You are asked to test whether a chatbot is good enough to answer Grade 10 science questions for students in Nepal. Plan the test: what is in your test set, how you check it, how you mark, and what you report.

Answer
i.

What is a swap test? Design one to check whether a chatbot treats students from different parts of Nepal differently.

Answer
j.

For each mistake, say how much harm it could do (little, some or serious), and why:

  • i.A chatbot gives the wrong year for the first Everest summit in a class quiz for fun.
  • ii.A chatbot tells a farmer to mix twice the safe amount of a pesticide.
  • iii.A chatbot gives a made-up website as the source in a student’s project.
Answer
k.

An AI wrote this function. The requirement: “is_valid_mark(m) returns True if a mark is a whole number from 0 to 100, both included, and False otherwise.” Write tests from the requirement, find the bugs, and fix it.

def is_valid_mark(m):    return m > 0 and m < 100 for m in [50, 0, 100, -5, 101, 72.5]:    print(m, is_valid_mark(m))
Answer
l.

Give four ways in which a large language model is different from a human mind, and two ways in which they are alike.

Answer
m.

What is the ELIZA effect? Why should a chatbot user know about it?

Answer
n.

“A chatbot that passes the Turing test must understand language.” Argue for and against this statement, then give your own view.

Answer
o.

A bank in Nepal puts a chatbot on its website. It tells a customer, wrongly, that a loan has no fee, and the customer takes the loan. Who is responsible for the mistake, and why? Use the Air Canada case in your answer.

Answer