Module 00 · Orientation
Start Here: What an LLM Does
From a Prompt to a Next-Token Probability, Watching the Loop Run, Prerequisites, Tracks, and How the Labs Work
By the end you can describe in one paragraph what happens between typing a prompt and seeing the next word, and know how to use the course.
A large language model does one thing: given some text, it gives a probability to every possible next piece of text. Chat assistants and code completion are built by calling that operation over and over. This course takes it apart, one piece of mathematics at a time, until you can follow every number from your prompt to the word that comes back.
This module gives you the whole picture first, so every later module has a place to fit. Nothing here needs to make full sense yet; each step has a module of its own.
0.1 From a Prompt to a Next-Token Probability
Take the prompt The cat sat on the. Here is what happens before the model offers mat.
- Split the text into tokens. A tokenizer cuts the text into pieces from a fixed list, its . Common words are usually one token each; rare words are split into several. Each token is then replaced by its position in the list, a whole number. (Module 9.)
- Turn each token into a vector. The model keeps a table with one row of numbers per vocabulary entry, and looks up the row for each token. A token is now a list of a few hundred or a few thousand numbers. (Module 1.)
- Mark where each token sits. On its own, the model cannot tell the first word from the last, so position information is mixed in. (Modules 6, 7 and 15.)
- Let the tokens look at each other. In each attention layer, every token works out which earlier tokens matter to it and pulls in information from them. This is how
theat the end comes to carry the fact that somethingsat onit. (Module 6.) - Process each token on its own. A small network applied to each token separately transforms what attention gathered. (Module 7.)
- Repeat. Steps 4 and 5 form one block. A model stacks dozens of blocks, each adding to a running vector per token. (Module 7.)
- Score every possible next token. The last token's final vector is compared with every vocabulary entry, giving one score each, and the scores are turned into probabilities that add up to 1. (Modules 4 and 7.)
- Choose one. A decoding rule picks the next token from those probabilities, appends it to the text, and the whole process runs again for the token after. (Module 12.)
The model's numbers come from : showing it enormous amounts of text and nudging every number so that it gives higher probability to the token that actually came next (Modules 2, 4 and 10). An assistant is made from that raw predictor by further training on examples of good answers and on people's preferences (Modules 20 to 22).
In words. Tokens become vectors, the vectors pass through a stack of blocks, the output layer scores every vocabulary entry, softmax turns scores into probabilities, and a decoding rule picks one. The chosen token is appended and the loop runs again.
0.2 Watching the Loop Run
The figure below runs the whole loop with a real, very small model, trained on Shakespeare, in your browser. It works one character at a time rather than one subword token, and it is far too small to write well, but it has learned enough to make sensible guesses. Its four panels follow the stages of section 0.1 for the current text, and the buttons run the loop: score, choose, append, repeat.
A small model trained on Shakespeare runs in your browser. It reads the text, scores every possible next character, and one is chosen and appended. Press the buttons to run the loop.
The prompt is "to be or not to". Before pressing anything, guess the model's favourite next character. Then switch Choose to most likely and press Append 20: what do you expect the text to do?
In words. A prompt box and the text written so far, with the model's characters in red and the last sixteen characters, all the model can read, shaded. Below, four panels show the current step: the characters as numbered tokens, their vectors, the vectors after two blocks with the same shape, and the five likeliest next characters. Append one or append twenty runs the loop, choosing either the likeliest character or a random one weighted by probability, with a temperature slider.
0.3 What You Need, and How the Course Is Organized
What You Should Already Know
- High-school algebra, including the rules for exponents and logarithms: and .
- Sine and cosine, and angles in radians. A full turn is radians.
- Summation notation. means . Module 1 goes over it again.
- Basic Python: functions, lists and loops, enough to read short code samples.
Helpful but not required: derivatives from a first calculus course (Module 2 teaches what the course uses), and some NumPy or PyTorch (Modules 1 and 4 introduce the calls the course uses).
You do not need linear algebra beyond vectors, probability, machine learning, reinforcement learning or anything about GPUs. Each is taught just before it is needed.
The Parts and the Two Tracks
| Part | Modules | What it covers |
|---|---|---|
| 0 · Orientation | 0 | This page |
| I · Foundations | 1–5 | The maths and machine learning the rest is built from |
| II · The Transformer | 6–8 | Attention, the block, and the three families of model |
| III · Building an LLM | 9–14 | Tokens, pretraining, training at scale, generation, evaluation, and what the model learns |
| IV · The Modern Architecture | 15–19 | The LLaMA-style block and the designs that followed it |
| V · From Model to Assistant | 20–22 | Fine-tuning, preference learning, and reasoning models |
| VI · Deployment | 23–24 | Serving and quantization |
| VII · Beyond Text | 25–28 | Vision, vision-language models, OCR and speech |
| VIII · Capstone | 29 | Build, upgrade, measure and ship a tiny GPT |
Every module is marked Core or Elective. The core track is Modules 0 to 15, 21 to 23, and the capstone. Electives go deeper on one topic and can be taken in any order once the modules they build on (named in each header) are done.
How Each Module Works
- A header with the goal, the modules it builds on, its track and an estimated time.
- Sections that start with small numbers you can check by hand, then give the general formula.
- Figures you can change. Most carry a Predict, then try box: commit to a guess before touching the figure. The prediction is what makes the figure teach.
- Exercises in three tiers: Check (recall), Apply (compute by hand) and Extend (reason further, or write code). Numeric answers are checked in the page, and every exercise has a worked solution.
Reading the Notation
Click any equation for a plain-English explanation of each part. Symbols such as or show a gloss on hover; a toggle at the top of each module turns these marks off. The glossary lists every symbol and term in the order you meet them.
0.4 How the Labs Work
Wherever a claim can be tested, it is, and the result appears in one of three boxes:
- Measured: run as an experiment on the course's reference implementation. The box names the experiment.
- Not measured: from a paper or model card, not reproduced here.
- Caveat: what a result does not show, such as a measurement on a model too small to generalize from.
The reference implementation is tiny-transformers, a small, readable transformer written for this course. Every lab panel shows the code it ran and the command to rerun it on your machine. Small labs run in your browser with a Run button; labs that train a model run in the terminal.
Companion Notebooks
Modules 1 to 29 each have a companion notebook that runs free on Colab's CPU in a minute or two: the button at the top of each module opens it, and sections it covers carry a Run this section badge. The notebooks rebuild the module's ideas in code you can change.
A good habit throughout: when you read a number, ask which kind of box it came from.
In which order do these happen when a model produces the next token: (a) softmax over the vocabulary, (b) embedding lookup, (c) tokenization, (d) the stack of blocks?
A sentence in a module says a technique "roughly doubles generation speed", inside a Not measured box. What does that tell you about the number?
Generation produces one token per pass through the model. A model writes a 300-token answer. How many passes through the full stack of blocks does that take, at minimum, and what does that suggest about where the cost of generation goes?
Core Academic References
- Vaswani et al. (2017): Attention Is All You Need. NeurIPS 2017. arXiv:1706.03762
- Radford et al., OpenAI (2019): Language Models are Unsupervised Multitask Learners (GPT-2). Technical Report.