1. First, lots and lots of reading
AI is short for artificial intelligence. That's the name for computer programs that can do things you normally have to think about. A chatbot is a program you can chat with. Well-known AI chatbots are ChatGPT, Gemini and Claude.
Before a chatbot can say anything, it has to learn. That's called training. The makers give it a gigantic pile of text: websites, books, articles. Much more than a person could read in their whole life. The part of the chatbot that learns is called a language model.
The language model doesn't memorize that text, the way you memorize vocabulary words for a test. It plays the same little game over and over. It gets a piece of text where the next word is covered up, and it has to guess what's there. If it guesses wrong, it gets adjusted a tiny bit, so it guesses better next time. That happens billions and billions of times.
After all that practice, there's no list of answers inside the language model. Instead, it holds an enormous collection of numbers. Together, they record which words belong together, how sentences flow and how an explanation or a joke usually goes.
2. Text becomes pieces
A computer can only calculate with numbers. That's why the chatbot first chops every text into pieces. A piece like that is called a token. Often it's a whole word, sometimes part of a word or a punctuation mark. A long word like “skateboarding” might be split into pieces like “skate,” “board” and “ing.”
Each piece has its own number. From then on, the chatbot calculates with those numbers, not with letters. So to the chatbot, your question is a list of numbers. Its answer is too, until it gets turned back into letters on your screen.
3. Guessing what comes next
Now you ask a question. The chatbot looks at all the pieces of your question. For every possible next piece, it calculates the chance that it comes next. Chance means: how likely something is. You often say it in percent, which means “out of a hundred.” So a 50 percent chance means half of the time.
After “My favorite food is,” “pizza” has a big chance and “Brussels sprouts” a small one. Not because the chatbot thinks pizza tastes good: it can't taste anything. But in the texts it practiced with, pizza came after a sentence like that much more often.
Then it picks a piece, adds it to the end of the text and starts over: what comes after this? It keeps going like that until the answer is finished. That's why you see an answer appear on your screen piece by piece. In reality, it's more complicated: to make good predictions, the language model has picked up lots of patterns, like grammar, facts and how a line of reasoning goes. But the answer always comes out the same way: predicted piece by piece.
Experiment: play chatbot yourself. Write down the start of a sentence, for example “On Saturdays I always play…” Ask ten classmates or family members to write down the next word, without seeing each other's words. Count how often each word comes up. If “soccer” came up four times, the chance of that word is 4 out of 10: 40 percent. Just like a language model, you've made chances out of what other people wrote.
Try it yourself: tap a word, or let the chatbot choose. Then turn Boldness up or down and see what happens to the chances. Also try the capital of France with Boldness turned way up.
There's no real AI running on this page: the chances are made-up examples, but this is how it really works. A real chatbot chooses from tens of thousands of possible pieces. Here you see five at most, and together they add up to 100 percent.
With JavaScript turned on, you can pick words yourself, let the chatbot choose and change the boldness. The picture shows the chances after “My favorite food is”: pizza has the biggest chance, Brussels sprouts the smallest.
4. A little bit of chance
If the chatbot always picked the piece with the biggest chance, it would become boring and predictable. It would always say exactly the same thing to the same question, and sometimes it would start talking in circles. That's why there's a little bit of chance in how it picks.
Think of a wheel of fortune where every piece has its own slice. The bigger the chance, the wider the slice. So a piece with a 30 percent chance wins about three out of ten times. That's why you don't always get the same answer to the same question.
The makers can set how much chance is involved. With low boldness, the chatbot almost always picks the piece with the biggest chance. With high boldness, small chances get more room, and it becomes more creative, but also messier. Try it with the Boldness slider above.
5. Sounds good, but is it right?
A chatbot picks what sounds likely, not what it has checked. Usually that's the same thing. After “The capital of France is,” “Paris” is by far the most likely, and that's correct. But if the question is about something that didn't come up much in its texts, it can make something up very convincingly: a book that doesn't exist, or the wrong year. That's called hallucinating. It isn't lying on purpose. It doesn't realize that it's wrong.
That's why, after the first training, chatbots keep practicing with people. Those people rate the answers: is this helpful, honest and safe? That way, a chatbot learns, for example, to say when it isn't sure about something. Some chatbots can also search the internet. Then they first read what they find and only then predict their answer. That helps, but mistakes are still possible.
Do you use a chatbot for school? Then always check important facts in a reliable source, like your textbook or the website of a museum, a university or the government.
A chatbot doesn't look up its answer. It predicts it, piece by piece.
Did you know?
200,000 years of reading
The language model Llama 3 from Meta, the company behind WhatsApp and Instagram, practiced with more than 15 trillion tokens. A trillion is a thousand billion. If you read for eight hours every day, it would take you more than 200,000 years to read that much text.
How many r's are in strawberry?
For a long time, lots of chatbots gave the wrong answer to that question: two instead of three. A chatbot doesn't see separate letters, but pieces. For some chatbots, strawberry is “str,” “aw” and “berry.” Counting letters in a word you don't see letter by letter is tricky. Newer chatbots often get it right, partly because they think it through step by step first.
Want to know more?
A network of numbers
A language model is a neural network: a computer program loosely based on how brain cells are connected to each other. It's made of layers of small calculation steps. Each step has numbers that can be adjusted, called the parameters. During training, those parameters keep getting adjusted a tiny bit, so the predictions get better. GPT-3, a language model from 2020, had 175 billion parameters. Newer models often have even more, but the makers don't always say how many.
Attention: which words belong together?
In the sentence “I put the cake on the table and cut it into slices,” you know right away that “it” means the cake and not the table. A language model has to figure that out too. For that, it uses a trick called attention. For each piece, it calculates which earlier pieces matter most for it. That trick already existed, but in 2017 researchers at Google built a whole new system around it: the transformer. The T in GPT stands for transformer.
Doing the math with boldness: the temperature
What this page calls “boldness,” the makers call temperature, written with the letter T. A normal temperature is 1. To adjust the chances, you raise each chance to the power of 1 divided by T. Then you make everything add up to 100 percent again. A power means multiplying a number by itself a certain number of times: 0.6² is 0.6 × 0.6. The sign × means “times.” And 0.6 is the same as 60 percent.
Two words with chances of 0.6 and 0.3. Temperature 0.5, so to the power of 2:
0.6 × 0.6 = 0.36 and 0.3 × 0.3 = 0.09. Together 0.45.
New chances: 0.36 ÷ 0.45 = 0.8 and 0.09 ÷ 0.45 = 0.2. That's 80 and 20 percent.
The sign ÷ means “divided by.” So at a low temperature, the biggest chance gets even bigger. At a temperature of 2, you take the square root instead: the number that gives you the chance when you multiply it by itself. Then 60 and 30 percent become about 59 and 41 percent. The chances get closer together, and the chatbot gets wilder. The Boldness slider above calculates exactly like this.
A chatbot's memory
A language model doesn't remember your conversation the way you do. For every new answer, it gets the whole conversation so far to read again as text. How many tokens fit in at once is called the context window. For big chatbots, that's often hundreds of thousands. If a conversation gets longer than that, the beginning gets cut off.
From predictor to assistant
After the first training, a language model can finish text, but it isn't a handy assistant yet. That's why a second training follows. The language model gets examples of good conversations. After that, people judge which of two answers is better. With those judgments, the model gets adjusted so it more often gives the kind of answer people like. That's called reinforcement learning from human feedback, or RLHF for short.
Electricity and computing power
Training takes a lot of calculating, and so a lot of energy. Energy is what you need to make something move, lift it up or heat it up, and also to make a computer calculate. How much energy a device uses each second is measured in watts. The total amount of energy used is often measured in kilowatt-hours (kWh): the energy a 1,000-watt device uses in one hour. An electric kettle uses about 2,000 watts. According to researchers, training GPT-3 took about 1,300,000 kWh. That's as much electricity as about 500 Dutch households use together in a year. The commas in 1,300,000 separate the thousands: it's 1.3 million. Every question you ask also uses a little electricity, in huge computer centers called data centers.
Think further
If a chatbot only predicts, can it come up with something that's truly new?
Give me a hint
A new song is made of notes that already existed. Does that mean the song isn't new?
See a possible answer
A chatbot can make sentences and stories that nobody has ever written down in exactly that way, because it combines pieces in a new way. In that sense, it makes something new. But everything it does builds on patterns from texts it already knew. People don't agree on whether that's really coming up with something. You also learn from what you've read and heard before. Where do you think the difference is?
Why does a chatbot often give a better answer if you ask, “Explain it step by step”?
Give me a hint
Every piece the chatbot writes, it reads again when it predicts the next piece.
See a possible answer
If the chatbot writes down the in-between steps first, they're in the text. For every next piece, it can use those in-between steps. That makes each prediction a lot easier. It works like writing out a tough math problem on scratch paper, instead of shouting out the answer all at once. Some new chatbots do this on their own: they “think” in in-between steps first before they answer.
Words you now know
- AI (artificial intelligence)
- Computer programs that can do things you normally have to think about.
- Chatbot
- A program you can chat with.
- Language model
- The part of the chatbot that has learned which pieces of text follow each other.
- Training
- Making an AI learn by letting it practice a huge number of times and adjusting it a little bit each time.
- Token
- A piece of text a language model calculates with: a word, part of a word or a punctuation mark.
- Chance
- How likely it is that something happens.
- Percent
- “Out of a hundred”: 30 percent is 30 out of 100.
- Hallucinating
- When a chatbot makes something up that sounds true but isn't.
- Neural network
- A program with layers of small calculation steps, loosely based on brain cells.
- Parameter
- An adjustable number in a neural network that gets tweaked during training.
- Attention
- The trick a language model uses to calculate which earlier pieces matter most.
- Temperature
- The setting that decides how much chance is involved in picking the next piece.
- Power
- Multiplying a number by itself a certain number of times: 3² is 3 × 3.
- Context window
- How many tokens a language model can read at once.
- Energy
- What you need to make something move, lift it up, heat it up or make a computer calculate.
- Watt
- How much energy a device uses each second.
- Kilowatt-hour (kWh)
- The energy a 1,000-watt device uses in one hour.
- Data center
- A big building full of computers that calculate and store data for others.
Test yourself
How does an AI chatbot come up with its answer?
See the answer
It keeps predicting the next piece of text.
Why do you sometimes get a different answer to the same question?
See the answer
There's a little bit of chance in picking each piece.
After “The capital of France is,” a chatbot gives these chances: Paris 90 percent, Lyon 6 percent, Marseille 4 percent. You ask the question 100 times. About how often do you get a wrong answer?
See the answer
About 10 times.
Tricky question: you ask a chatbot for a book about volcanoes. It gives a title, an author and a year. It sounds totally real, but the book doesn't exist. How is that possible?
See the answer
The title, author and year sound likely together, but it didn't check whether the book exists.