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.

45 Minutes·Core·Foundational·0/4

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.

  1. 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.)
  2. 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.)
  3. 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.)
  4. 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 the at the end comes to carry the fact that something sat on it. (Module 6.)
  5. Process each token on its own. A small network applied to each token separately transforms what attention gathered. (Module 7.)
  6. Repeat. Steps 4 and 5 form one block. A model stacks dozens of blocks, each adding to a running vector per token. (Module 7.)
  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.)
  8. 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).

Architecture Flowchart
Diagram: Prompt text; Tokenizer: text to token ids; Embedding lookup: ids to vectors; Stack of blocks: attention, then a per-token network, repeated; Output layer: one score per vocabulary token; Softmax: scores to probabilities; Decoding: choose the next token

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.

Figure 0.2
Predict, 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 model works one character at a time (real models use subword tokens, Module 9) and reads at most the last 16 characters. Two blocks, vectors of 16 numbers, about 5,800 parameters, trained on CPU for 8,000 steps: validation loss 1.887 nats per character, against 3.33 for guessing uniformly. Module 7 opens up every stage.
Predict, then try

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 2π2\pi radians.
  • Summation notation. means x1+x2+x3x_1 + x_2 + x_3. 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

PartModulesWhat it covers
0 · Orientation0This page
I · Foundations1–5The maths and machine learning the rest is built from
II · The Transformer6–8Attention, the block, and the three families of model
III · Building an LLM9–14Tokens, pretraining, training at scale, generation, evaluation, and what the model learns
IV · The Modern Architecture15–19The LLaMA-style block and the designs that followed it
V · From Model to Assistant20–22Fine-tuning, preference learning, and reasoning models
VI · Deployment23–24Serving and quantization
VII · Beyond Text25–28Vision, vision-language models, OCR and speech
VIII · Capstone29Build, 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.

Check

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?

Check

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?

Extend

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.