AI & ML · Ebook
Building an LLM from Scratch: From Tokens to Aligned Model
by Shriira Press
4.3(4,639)102 pagesPublished 2026
A hands-on, build-it-yourself guide to constructing a large language model from the ground up — a working GPT-style model you tokenize for, architect, train, sample from, fine-tune, and align, with every component built in readable PyTorch. This is the eighth volume in a series, and its engine room: the transformer and next-token prediction you build here are the exact machinery the companion books on audio, video, and vision repeatedly invoke. Where they survey, this book implements.
Contents
- 1Preface
- 2Chapter 1 — What Is an LLM, and What We're Building
- 3Chapter 2 — Text to Tokens: Tokenization
- 4Chapter 3 — Embeddings and the Data Pipeline
- 5Chapter 4 — Attention
- 6Chapter 5 — Multi-Head Attention and Causal Masking
- 7Chapter 6 — The Transformer Block
- 8Chapter 7 — Assembling the GPT Model
- 9Chapter 8 — Pretraining: The Training Loop
- 10Chapter 9 — Generating Text: Decoding and Sampling
- 11Chapter 10 — Scaling, Efficiency, and Practical Training
- 12Chapter 11 — Fine-Tuning and Instruction Tuning
- 13Chapter 12 — Alignment: RLHF, DPO, and Preferences
- 14Chapter 13 — Evaluation, Deployment, and Limitations
- 15Appendix A — Notation and Symbols
- 16Appendix B — Further Reading
