The whole secret in one sentence
At its core, a language model like ChatGPT does exactly one thing: it reads some text and estimates which word comes next. Then it appends that word and estimates again. And again. Lots of small guesses add up to a whole answer.

Sounds too simple to be true? Try it. Your turn: guess which word the model thinks is most likely.
We made up the percentages in the game. A real model has to work them out by itself, from huge amounts of example text, without anyone telling it rules like “after on there is often the”. How it manages that is the real question of this book. The answer is surprisingly down to earth: lots of very simple calculations, repeated very often.
What you will build
By the end you will have your own small language model: a program that has learned from example texts which pieces of text tend to follow each other. It is much smaller than ChatGPT, more bicycle than jet plane. But it works on the same principles, and you will understand every single part of it.
The road there has seven stages:
| Stage | What it is about | Chapters |
|---|---|---|
| I · Neural networks | How a program learns from examples, first with numbers and no text yet | 2–8 |
| II · From numbers to language | How text turns into numbers and what a first tiny language model looks like | 9–14 |
| III · The transformer | The blueprint behind ChatGPT: how words pay attention to each other | 15–17 |
| IV · Training | The model really learns, and we check whether it works | 18–21 |
| V · Modern models | The tricks of today's models, from saving memory to answering questions | 22–26 |
| VI · Thinking bigger | What large models need on top | 27–28 |
| VII · Build your LLM | You write your own language model in PyTorch, step by step | 29–38 |
Why we start with numbers
Fair warning: the first chapters are not about language yet. We start with a tiny program that is supposed to learn to triple numbers. Why the detour?
Because on the inside, a language model only computes with numbers too. Text gets translated into numbers right at the start, and after that exactly what you see in the first chapters' mini examples happens: weigh, add, measure the error, adjust. Once you have understood it with three numbers, you understand it with three billion. And we promise: every one of these chapters tells you what you will need it for later in the language model.
Math? Don't panic.
You need plus, minus, times and divided by. That's it. We always calculate with real, small numbers first. Formulas with letters and symbols live in collapsible math corners. Open them if you are curious, or just skip them. The text around them works without them.
Terms with a dotted underline can be tapped to show a short explanation. So you don't have to memorize anything or look things up elsewhere.
This is what a math corner looks like
Nice of you to look inside! This is where formulas live: shorthand for calculations that already appeared in the text with numbers. An example: “triple the input” is written in short like this:
Read it as: the output y is three times the input x. For x = 2 that gives 6. Most formulas hold no more mystery than that. And if a symbol looks unfamiliar: the formula cheat sheet in the appendix explains every one of them.
Two ways to read this book
Understand: you want to know how ChatGPT and friends work, but you don't want to program. Then read the text, play with the figures and leave the math corners and the code aside. You can skim the engineering chapters on efficiency and precision, and the build part VII.
Build: you want to train your own model in the end. Then read everything and open the math corners. In part VII you write your language model yourself, step by step, with PyTorch on your own computer. Basic Python knowledge helps there.
Both paths are completely fine, and you can switch at any time.
Three things that often get mixed up
Using a model: you type something in, the finished model answers. It learns nothing new while doing so. This is how you use ChatGPT.
Training an existing model further: you take a finished model and teach it something new with extra examples. That is called fine-tuning.
Training a model from scratch: you start with nothing but random numbers (the model can't do anything at all at first), and it learns everything from your data. That is exactly what we do here.
Honest expectations
Your model will not be ChatGPT. Big companies train in huge data centers, for months. Your model runs on your computer and learns simple patterns: short, readable texts, and later answers within a limited topic.
In return, you will know what every single part does and why. That is more than most people can say about this technology.
Practical matters
The small experiments run right here in your browser. Many chapters also have a Python lab: real Python code you can change and run right on the page, with no installation, on your own computer. Under “Experiment” you can move sliders. Think for a second about what should happen first, and you will learn twice as much. Under “Practice” there is an exercise and a quiz question. You build and train a real model yourself in part VII, with PyTorch on your own computer.
Your progress is saved in this browser. On another device you start fresh, unless you export your progress first.
Up next
We start really small: with a program that can adjust a single number. What does it even mean that such a program “learns”? That is what the next chapter is about.