The Book
ML from Scratch
Volume 1 · Foundations
Learn machine learning by building it.
- Author
- N Sai Harshith Varma
- Pages
- 373
- ISBN
- 979-8-1852-8008-9
- Edition
- First edition, 2026

01Why I wrote this
I'm Harshith Varma, a Data Scientist at Confluent. I'm not someone who knows everything about machine learning. I'm someone who wants to understand everything about machine learning. Most ML resources teach you what to do — import this, call this function — but not why it works. That gap in my own understanding is what pushed me to start deriving every algorithm from scratch instead of treating ML as a toolbox. My goal isn't for you to finish this book. It's for you to reach the point where you can look at any machine learning model and think: "I understand why this works." You don't need a PhD to read this book. You only need a willingness to ask "why?" one more time than most people do. Welcome to the journey. Let's build machine learning from scratch.
02Who this book is for
Twenty chapters, four parts: Math Foundations, Build a Neural Net, PyTorch, and Training. Read them in order. Every chapter builds something the next one uses. Every chapter carries the same three code layers, in the same order: pure Python (every multiplication shown), NumPy (vectorized), then PyTorch (what you'd write at work). Four recurring callouts do the rest of the teaching — Insight for the key idea, Warn for practical failure modes, Challenge for a do-it-now exercise, and Personify, where a concept explains itself in first person. Every interactive widget on the companion website (ml.harshithvarma.in) becomes a static figure in the book, plus a pointer back to the live version. The figures are honest — you can read this book cover to cover offline. But the widgets let you move the sliders yourself, and moving the sliders is how the intuition sticks.
03Volumes & roadmap
- Vol. 1
Foundations
Available · Chapters 1–20The first twenty chapters. Gradient descent through a trained digit classifier — every derivation shown, every line of code earned.
- Math Foundations
- Build a Neural Net
- PyTorch
- Training
- Vol. 2
Deep Learning: From CNNs to GPT
Drafted · Chapters 21–48Convolution through a working GPT you train and talk to. Fully drafted; not yet through the full review gate or published.
- CNNs & Vision
- RNN & LSTM
- NLP
- Attention & Transformers
- Build GPT
- Vol. 3
Sections 10–14 (planned)
Planned · Chapters 49–75Scope is set; chapters have not been drafted yet.
- Fine-Tuning & RLHF
- Mixture of Experts
- Diffusion Models
- Reinforcement Learning
- Inference & Serving
04Table of contents — Volume 1
Math Foundations
01Gradient Descent
A blindfolded walk down a mountain.
02Sigmoid & ReLU
A dimmer switch and a light switch.
03Softmax
The pollster who turns opinions into percentages.
04Cross-Entropy Loss
The grading rubric that punishes confident lies.
05Linear Regression (Forward)
A ruler laid across a point cloud.
06Linear Regression (Training)
Two doors, one room.
Build a Neural Net
07Single Neuron
A doorman, a clipboard, and one decision.
08Backpropagation
Reading the day backwards, one local slope at a time.
09Multi-Layer Backpropagation
The org chart learns to take blame.
10Backprop Ninja
A lab assistant with a ruler, watching you work.
11MLP from Scratch
Six lessons of parts. Today you bolt them into a car.
12Weight Initialization
The sound guy fumbles the volume knobs before the band walks on.
PyTorch
13PyTorch Basics
A scribe who sits beside you and writes down every move.
14Layer Normalization
The per-track sound mixer in every transformer block.
15Batch Normalization
The teacher who grades on the curve: one exam question at a time.
16RMS Normalization
The step we found we didn't need.
Training
17Training Loop
Forward. Loss. Backward. Step. Repeat a million times.
18Training Diagnostics
The stethoscope lesson.
19Dead ReLU Detector
The electrician's checklist for a chandelier that looks fine but isn't.
20Digit Classifier
The first vehicle rolls off the assembly line.
05Read a preview
The full Volume 1 manuscript — the same file behind the Download PDF button above, ready to read in your browser's own PDF viewer.
Open full PDF (opens in a new tab)06Companion learning site
Every derivation and figure in this book started life as an interactive lesson. The live site covers all 14 sections and 75 lessons with runnable widgets — read the book, then go move the sliders.
ml.harshithvarma.in (opens in a new tab)07Frequently asked questions
No. The book assumes curiosity, not expertise — you need to read Python and remember some calculus. It rewards attention rather than spoon-feeding, but nothing here requires formal training beyond that.