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.

10 chapters 32 interactive sections 4 parts Glossary →

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.

STAGE 1 · Build (ch 2–4) text → tokens → embeddings → attention → the GPT architecture pretrain STAGE 2 · Pretrain (ch 5) loss → training loop → decoding → a foundation model (+ OpenAI weights) fine-tune STAGE 3 · Fine-tune (ch 6–7) spam classifier · 95.7% on unseen data instruction-following assistant appendices: A — the PyTorch foundations beneath it all · D — training-loop refinements · E — LoRA, fine-tuning at ~2% of the weights
The whole journey in one line: build, pretrain, specialize — every box a set of pages below.

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.

Content faithful to Build a Large Language Model (From Scratch) by Sebastian Raschka (Manning Publications, 2024), rewritten as an original web-native, interactive edition for personal study. Please support the author by buying the book. Built from a community study-notes rendering of the book (2025); notes by codewithdark.