Interactive companion · Build a Large Language Model (From Scratch)

Build a GPT, one idea at a time.

Go from raw text to a working assistant: tokenizers, attention, a full GPT, pretraining, loading real GPT-2 weights, and two kinds of fine-tuning. Every concept comes with a short explanation, a widget to play with, a notebook where you write the code, and a quiz that checks you really got it.

Start with Chapter 1 → Browse chapters Glossary

The map

Three stages, nine steps. Click a step to see what you will build.

How to use this course

Every chapter follows the same loop.

1 · Understand

Short, original explanations organized like the book's sections. Each starts with why, then how, with diagrams and math.

Chapter page

2 · Play

Widgets that isolate one idea at a time: change the input, temperature, mask or rank, and watch what happens. Each comes with a "Try this" prompt.

In the page

3 · Build

Implement every component yourself in TODO cells. Automatic checks give instant ✅/❌ with targeted hints.

Jupyter lab notebook

4 · Prove

Chapter quizzes with explanations, spaced-repetition flashcards, the book's exercises and harder stretch challenges.

Quiz · cards · lab

Chapters, in study order

Appendices sit where you need them. The capstone puts it all together.

Your progress

Stored only in this browser.

ChapterSectionsQuiz bestCards masteredCards due

Setup in two commands

See README.md for details.

This website

python3 -m http.server -d web 8000
# open http://localhost:8000

The lab notebooks

source .venv/bin/activate
jupyter lab --port 8888   # from the project root

"Open the lab" links on chapter pages point to localhost:8888.

Book references

Sections are cited like , so you can read the original alongside. All text, diagrams and code here are original.