How does ChatGPT actually work?
Short answer: ChatGPT works by guessing the next token, a chunk of text stored as a number, then the next, one guess at a time. It learned by guessing hidden words in a mountain of text and nudging billions of dials toward better guesses. A trick called attention lets each word use the words around it.
How it works
No maths. Here's what happens after you hit Enter:
- 1Words become numbers. Your text is chopped into chunks called tokens, and every chunk is a number. In one popular model, "strawberry" is a single chunk: number 73,700.
- 2One guess at a time. The model guesses the next token, then the next, then the next. Every answer is written that way.
- 3Training is guessing. Take a mountain of text, hide the next word, let the model guess, then nudge its billions of dials toward a better guess. Repeat trillions of times. Nobody types in the rules.
- 4Too big to do by hand. At a billion calculations a second, training the biggest models of 2024 would take well over 100 million years. Data centres do it in months.
- 5Attention. Every word looks at every other word to work out what it means here, so a mole on your skin, in the garden and in a chemistry exam stay different.
- 6The aha. All it ever does is guess the next word. But to guess that well, it had to learn about our world.
MYTHChatGPT reads your words letter by letter.
REALLYIt never sees letters, only numbered chunks. That's part of why AI used to miscount the r's in "strawberry". For spelling or counting, check its answer yourself.
People also ask
What is a token in ChatGPT?
A chunk of text, often a whole word or part of one, stored as a number. The model reads and writes tokens, not letters.
Why did AI miscount the r's in strawberry?
Partly because it doesn't see letters: in one popular model, " strawberry" is a single token, number 73,700. Counting repeated letters is also hard for these models.
Does ChatGPT look things up?
Not by itself. Without a search tool it writes from what it learned in training; it only uses sources when a tool or a document puts them in front of it.
What is attention in AI?
The Transformer's trick: every word looks at every other word to work out what it means in context. The Transformer is the T in ChatGPT.
Read the transcript
Before you hit enter, let me show you what you're talking to. Here's what really happens. Your words are chopped into chunks called tokens, and every chunk is a number. It never sees letters. In one popular model, strawberry is a single chunk, number 73,700. That's part of why AI used to miscount the R's in it. Then it does one thing. It guesses the next token. Then the next. Then the next. Every answer you've ever had from it was written like that, one guess at a time. How did it get good at guessing? Take a mountain of text. Hide the next word. Let the model guess. Check. Then nudge its dials, billions of them, a tiny bit toward a better guess. Now do that trillions of times. Nobody types in the rules. The dials find them. At a billion calculations a second, training the biggest models of 2024 would take well over 100 million years. Data centres do it in months. But why would guessing words produce something that seems to think? Imagine reading a murder mystery to the last page, where the detective finally says, "The killer is..." To guess that next word, you'd need to have followed the whole plot. That's what the Transformers trick "attention" is for. Every word looks at every other word to work out what it means here. A mole on your skin. A mole in the garden. A mole in a chemistry exam. Attention tells them apart. All it ever does is guess the next word. But to guess that well, it had to learn about our world.
Sources we checked
- Vaswani et al. (2017): Attention Is All You Need
- 3Blue1Brown: But what is a GPT?
- 3Blue1Brown: Attention in transformers
- OpenAI: tiktoken tokenizer
- Fu et al. (2024): why models miscount letters
Spotted a mistake? Email cogling.studio@gmail.com and we'll check it.
The full video
How does AI work, and will it take my job?
It only guesses the next word. To guess well, it had to learn about our world. A 21-minute film on AI and your job.
More from this video
What should I actually do about AI and my job?
A job is a bundle of tasks. AI takes tasks. Four things the evidence says to do, starting today.
Will AI take your job? What 200 years of history says
Three times a machine came for a job: weavers in 1811, telephone operators a century ago, radiologists in 2016.
How fast is AI really moving?
From a coffee break to a working day in about three years. And what the job numbers actually say.
Does AI actually think, or just predict the next word?
It picks the rhyme before it writes the line. It taught itself to say "wait". Its makers still can't fully explain it.
Where did ChatGPT come from?
ChatGPT seemed to come from nowhere. Its core trick was written down in 1948.
More explainers
Why does AI run on a gaming card?
One chatbot answer is nearly 50 trillion sums. By hand: 1.5 million years. A gaming card: under a second. Here's how a game chip ended up running AI.
Wi-Fi from a black-hole hunt
The hunt found nothing. The maths it left behind fixed Wi-Fi's echo problem.