
This course includes our updated coding exercises so you can practice your skills as you learn.
See a demo
Overview. Build a GPT from scratch in Python: a tiny model, trained on a laptop CPU. The finished project running first, then the plan for the course, what you need, and the course code (attached here as a download).
Hands-on. Text to numbers in Python: characters, batches and a bigram baseline. Practical for this section: get_batch(): build next-token training batches.
Hands-on. Build a BPE tokenizer in Python from scratch. Practical for this section: pair_counts(), merge(), train().
Hands-on. Embeddings and self-attention in Python, step by step. Practical for this section: attend(q, k, v): one causal head.
Hands-on. Multi-head attention and the transformer block in Python. Practical for this section: block_forward(): pre-norm block.
Hands-on. Train a GPT in Python on a CPU: the training loop. Practical for this section: train_step(): one optimiser step with clipping.
Quick note: if this course has been useful so far, an honest review helps other learners decide whether it is right for them. It takes about 10 seconds, and you can update it any time as you go further. Questions or anything unclear? Ask in the Q&A, I reply to every one.
Hands-on. Sampling in Python: temperature, top-k and top-p. Practical for this section: top_p_filter(): nucleus filtering.
Hands-on. Scaling a GPT in Python: parameters, compute and the KV cache. Practical for this section: count_params(): size from shapes.
This course contains the use of artificial intelligence.
You build a small GPT from an empty file, step by step, in Python and PyTorch, and train it on an ordinary laptop CPU in minutes. No graphics card, no API key and no paid service: the training text is three public-domain novels by Jane Austen (about two million characters).
You write a character tokenizer and a byte-level BPE tokenizer from scratch and measure what the vocabulary size buys and costs (including why the same question can cost almost six times the tokens in Greek as in English); write causal self-attention in six lines and prove it matches PyTorch's built-in function; build multi-head attention, the MLP, residual connections and layer norm, and measure what happens when each one is removed; write the training loop with AdamW, warmup and cosine decay, gradient clipping and honest evaluation; sample with greedy decoding, temperature, top-k and top-p, measured on real outputs; and finish with parameter counting, compute and memory estimates, a small scaling experiment and a KV cache.
The models are tiny on purpose, and the course is honest about what they can and can't do: the character model (820,224 parameters, about 19 minutes of training) writes text in Austen's style with real names and mostly real words, and sentences that do not mean anything. Every number shown is from a real run (31 October and 8 November 2026); the code, logs, tests, practicals and cheat sheets are included. Narration is AI-voiced; the code, runs and results are real.
The course is 2 h 14 min of video in 8 sections. Section 1 is the overview and setup; the other sections are hands-on, and every program is run for real on screen. Each hands-on section comes with a one-page cheat sheet (PDF), a short quiz, a practical with starter and solution files and an assignment with a model answer; 5 coding exercises let you write the code yourself.