Building an LLM from Scratch: From Tokens to Aligned Model cover

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

  1. 1Preface
  2. 2Chapter 1 — What Is an LLM, and What We're Building
  3. 3Chapter 2 — Text to Tokens: Tokenization
  4. 4Chapter 3 — Embeddings and the Data Pipeline
  5. 5Chapter 4 — Attention
  6. 6Chapter 5 — Multi-Head Attention and Causal Masking
  7. 7Chapter 6 — The Transformer Block
  8. 8Chapter 7 — Assembling the GPT Model
  9. 9Chapter 8 — Pretraining: The Training Loop
  10. 10Chapter 9 — Generating Text: Decoding and Sampling
  11. 11Chapter 10 — Scaling, Efficiency, and Practical Training
  12. 12Chapter 11 — Fine-Tuning and Instruction Tuning
  13. 13Chapter 12 — Alignment: RLHF, DPO, and Preferences
  14. 14Chapter 13 — Evaluation, Deployment, and Limitations
  15. 15Appendix A — Notation and Symbols
  16. 16Appendix B — Further Reading