A free, hands-on textbook on LLMs
Understand how language models do the math. Then build your own.
From a single neuron to a Transformer that writes text. No machine learning background needed: every formula comes after a worked example with real numbers, and every chapter has an experiment you can run in your browser.
What you’ll be able to do
- Explain it: What happens inside a Transformer, step by step – in your own words, with small numbers.
- Work it out: Neurons, softmax, attention and backpropagation by hand, until the formulas feel obvious.
- Build it: Your own GPT in PyTorch, written step by step: tokenizer, model, training, text generation and chat, on your own machine.
The path in seven parts
I · Understanding neural networks
- Your path to your own language model
- What does it mean for a program to learn?
- An artificial neuron you can compute by hand
- Why neurons need an activation function
- From neurons to a small network
- How do we measure a wrong answer?
- How numbers actually learn
- Learning through several layers
II · From numbers to language
- Vectors, matrices and tensor shapes
- From text to token IDs
- Language as a probability problem
- Your first real language model
- Embeddings and shared representations
- The learning goal: cross-entropy
III · Building the transformer
IV · Training and evaluating
- Data is part of the model
- Your first training loop
- Reading the loss and finding bugs
- From scores to text
V · Modern language models
- RMSNorm, RoPE and SwiGLU
- GQA, FlashAttention and the KV cache
- Precision and training memory
- From a text model to an answer model
- Evaluating answers honestly
VI · Thinking bigger
VII · Build your LLM
- Your blueprint: a GPT in eight steps
- Step 1: The tokenizer
- Step 2: Preparing the data
- Step 3: Your first neural language model
- Step 4: The GPT model
- Step 5: Training
- Step 6: Generating text
- Step 7: From storyteller to chat
- Step 8: Modernizing
- Your own project: building further
Appendix · Reference
Frequently asked questions
Do I need a maths background?
Adding and multiplying is enough to get started. Every new piece of notation is explained before you need it, and always worked through with numbers first.
Do I need a GPU?
No. All the experiments run in your browser, and the Python project trains small models on an ordinary laptop. A GPU just makes bigger runs faster.
Will I be able to build ChatGPT afterwards?
You’ll understand the same building blocks and train a small model yourself. Large systems differ mainly in the amount of data, compute and polish – the last part of the book explains how.
Does it cost anything?
No. No account, no cookies, no tracking. Your reading progress stays in your browser.