This part built every piece of a deep learning framework separately: a Tensor's forward pass through layers, a loss function, backprop computing every gradient, and last chapter's Adam turning gradients into steps. A real framework just wires those pieces into one loop. Does wiring them to a slightly smarter optimizer change how fast the same XOR network — the one a single perceptron couldn't touch — actually learns?
Same XOR points from Chapter 2, same tiny network shape: 2 inputs, 4 hidden neurons, 1 output. Click train and watch the shaded decision region fold around the two "on" corners — except this time the optimizer behind every step is AdamW, not plain gradient descent.
AdamW is Adam plus one change: weight decay applied directly to the parameter, decoupled from the gradient-based moment estimates.
- — Chapter 9's bias-corrected running averages of the gradient and its square.
- — the parameter being updated: any single weight or bias in the network's Tensor.
- — the learning rate.
- — the weight decay coefficient, shrinking every parameter a little on every step.
- Everything except one term is Adam, unchanged
is exactly Chapter 9's Adam update — nothing new there.
- The new piece: decoupled weight decay
is added straight onto the update, applied to the raw parameter — not folded into the gradient the way plain L2 regularization would be. That decoupling is the "W" in AdamW.
- One update rule, every parameter in the network
The same formula runs once per weight and bias — 17 parameters total in this tiny network, billions in a real one — each keeping its own , , and , all driven by the one gradient backprop computed for it.
Watch the four individual outputs. AdamW's adaptive step size means the two that need to climb toward and the two that need to fall toward move faster and more evenly than plain gradient descent managed on this exact same network in Chapter 2 — the per-parameter scaling matters even on a network this small.
From this network's fixed random start, before any training:
- Pick one parameter: the weight from hidden neuron 1 to the output
. A full backward pass through all four XOR points gives its gradient: .
- At the very first step, the moving averages start from zero
, so:
- exactly.
- exactly.
The bias correction perfectly cancels the very first factor on both averages.
- That collapses the ratio to just the gradient's sign
— same "first step ignores magnitude" behavior Chapter 9 found for RMSProp and Adam.
- Add the weight decay term and take the step
With and : update , so .
Train the network until its loss on XOR drops below 0.01.
Forward pass, loss, backprop, and an optimizer step, run in a loop until the loss is small enough — that's every framework's training loop, from this four-line XOR network to a model with billions of parameters. Swapping AdamW in for plain gradient descent didn't change any of the pieces this part built by hand; it only changed how the last piece, the update rule, turns a gradient into a step. Part IV starts asking what happens when the pieces themselves get more specialized, starting with images.