Reading sequence

AI from Scratch

The whole path in order: linear algebra intuition, tokenizers, embeddings, attention, the full transformer forward and backward pass, optimizers, and two complete builds (autograd in NumPy, GPT-2 in PyTorch). Each part assumes the one before it.

19 parts 312 min total
  1. Linear Algebra for Machine Learning: The Visual Intuition Linear algebra for machine learning explained visually: vectors, matrices, dot products, determinants, eigenvectors, and the basis changes that make it click. 12 min
  2. Backpropagation from Scratch: Build an Autograd Engine How does backpropagation work? Build a working autograd engine from scratch in ~80 lines of Python: computation graphs, chain rule, reverse-mode autodiff. 31 min
  3. Numerical Gradient Checking: Debug Your Autograd Engine What is numerical gradient checking? The central difference formula, why you never train with finite differences, and a grad checker that catches real bugs. 14 min
  4. Byte Pair Encoding (BPE) Explained: How GPT Tokenizers Work What is byte pair encoding (BPE)? How GPT tokenizers turn text into IDs: pretokenization, merge rules, byte-level vocab, and a from-scratch build. 21 min
  5. Token Embeddings Explained: How LLMs Turn IDs Into Vectors What is a token embedding? How LLMs map token IDs to learned vectors: the embedding matrix, gather vs one-hot matmul, and a from-scratch NumPy build. 15 min
  6. Positional Encoding Explained: How Transformers Learn Order What is positional encoding in transformers? Why attention is order-blind, learned vs sinusoidal embeddings, and a from-scratch NumPy implementation. 12 min
  7. Cross-Entropy Loss Explained: From Logits to LLM Training What is cross-entropy loss? Derive softmax and negative log-likelihood, work a 3-class example, and see why MSE fails for language model classification. 9 min
  8. Adam and AdamW Explained: How LLMs Update Their Weights How does the Adam optimizer work? Derive momentum, RMSprop and bias correction, see why AdamW decouples weight decay, and walk a numeric update by hand. 11 min
  9. How GPT Actually Works: A Visual Guide to Transformers How does a GPT actually work? A visual walkthrough of transformers: tokens, word embeddings, dot products, softmax and temperature, with real GPT-3 numbers. 11 min
  10. How Attention Works in Transformers: Queries, Keys, Values How does attention work in transformers? Queries, keys, values, the attention pattern, masking, and multi-head attention, with real GPT-3 parameter counts. 13 min
  11. Transformer from Scratch: Forward Pass and Backprop by Hand One full transformer training step worked by hand: embeddings, positional encoding, attention, layer norm, cross-entropy loss, backprop, and Adam. 20 min
  12. GPT Math Explained: The Full Forward Pass Beyond Attention How does GPT math work end to end? One training step from token IDs through Q/K/V, attention, MLP, logits, cross-entropy loss, backprop, and AdamW. 10 min
  13. Build GPT-2 from Scratch in PyTorch: A Full Walkthrough How to build GPT-2 from scratch in PyTorch: tokenization, causal self-attention, transformer blocks, weight tying, and a 124M training loop that runs. 40 min
  14. DeepSeek V4 Explained: Long-Context Engineering and Math A verification-first look at DeepSeek V4 claims, plus the real math behind sparse attention, KV-cache scaling, and long-context training stability. 14 min
  15. Build a Mini LLM from Scratch in NumPy: RoPE, GQA, SwiGLU How to build a mini LLM from scratch in NumPy: RoPE, GQA, QK-Norm, SwiGLU, tied embeddings, and a 3.87M chat companion with full architecture visuals. 11 min
  16. Natural Language Inference Explained: Entailment in NLP What is natural language inference (NLI)? How models label a premise and hypothesis as entailment, contradiction, or neutral on SNLI, MNLI, and BERT. 16 min
  17. Looped Transformers Explained: Recurrent Depth and Astra What is a looped transformer? How recurrent depth reuses layers, why Nanbeige 4.2 runs a 22-layer stack twice, and why that does not hide chain of thought. 14 min
  18. DeepSeek V4 Inside: One Token Through Every Block How does DeepSeek V4 process one token? I follow the byte p in deepseek through CSA, HCA, mHC, MoE, and MTP on a toy width, with Flash-0731 sizes. 22 min
  19. Convolutional Neural Networks: CNN Math Explained How do convolutional neural networks work? CNN math explained with kernels, padding, stride, pooling, receptive fields, and a full backpropagation example. 16 min