Interactive edition
Build a Large Language Model (From Scratch)
An interactive study companion to the book by Sebastian Raschka (Manning Publications, 2024). Every chapter is rebuilt as labeled diagrams, step-through animations of the forward and backward pass, live attention and tokenizer widgets, and quizzes — the same GPT, built from scratch, made visual.
New here? Start at the top and read straight through, or jump to any chapter below. Use ← / → to move between sections; the sidebar tracks what you've read.
Foundations
What a large language model is, why the transformer changed everything, and the two-stage recipe — pretraining then fine-tuning — that the rest of the book builds end to end.
Part I — Text Data & Attention
Turning raw text into tensors a network can learn from, then the heart of the transformer — tokenization, byte-pair encoding, embeddings, and self-attention built up from dot products to multi-head causal attention.
Part II — Building & Pretraining a GPT
Assembling the full GPT: layer norm, GELU feed-forward blocks, shortcut connections and the transformer block, then pretraining it on unlabeled text with a cross-entropy loss, sampling strategies, and loading OpenAI weights.
Part III — Fine-Tuning & PyTorch Appendices
Adapting the pretrained model to do useful work — fine-tuning it as a spam classifier and as an instruction-follower — plus PyTorch fundamentals, training-loop refinements, and LoRA.