by Truong (Jack) Luu

Building an LLM from Zero

So Simple You Can Teach It to Your Kids

Free and Open Source No GPU Required Python + PyTorch

About the Book

This is a step-by-step tutorial for building a GPT-style language model entirely from scratch using Python and PyTorch. By the end, you will have trained a model that generates Shakespeare-like text, writing every line of code yourself.

Every chapter has two parts: a Theory section that explains the concept in plain language with analogies, and a Code section with a runnable Python file you can execute immediately.

The entire book was written and tested on a ThinkPad T14 Gen 1 (Intel Core i7, 32 GB RAM, 2020). Training completes in about 20-30 minutes. No cloud account, no GPU, no special setup needed.

Who Is This For?

  • Beginners who learn by building (basic Python, no ML background needed)
  • Instructors and professors looking for classroom-ready, easy-to-setup demo materials
  • IT/IS professionals who want to understand LLMs from the ground up
  • Parents who want to teach their kids how AI actually works, hands-on

Quick Facts

Chapters16
Sections5
Model size~825K parameters
DatasetTiny Shakespeare
Training time~20-30 min (CPU)
FrameworkPyTorch (CPU only)
LicenseMIT (free)

Table of Contents

Section 1: Foundations

Ch 01What Is a Language Model?
Ch 02Tensors and PyTorch Basics
Ch 03Tokenization
Ch 04Embeddings

Section 2: The Attention Mechanism

Ch 05Self-Attention
Ch 06Multi-Head Attention
Ch 07Feed-Forward and Layer Norm

Section 3: The Transformer

Ch 08The Transformer Block
Ch 09The Full GPT Architecture
Ch 10Causal Language Modeling

Section 4: Training

Ch 11Dataset and DataLoader
Ch 12The Training Loop
Ch 13Saving Checkpoints

Section 5: Generation

Ch 14Greedy Decoding and Sampling
Ch 15Temperature and Top-k
Ch 16Putting It All Together
Sample generated output (after training):
ROMEO:
What is a man, if his chief good
And market of his time be but to
sleep and feed?

How to Cite

If you use this book in your teaching or research, please cite it as:

Luu, T. (2025). Building an LLM from Zero: So Simple You Can Teach It to Your Kids. GitHub. https://github.com/jackluucoding/build-llm-from-zero

A DOI for permanent academic citation is available via Zenodo (link will be added after first release).