Chapter 3's kernel, dense weights, and biases were all hand-picked to make one particular pipeline work on one particular image. Real networks don't get that luxury — they start from random numbers and have to earn every weight through training. This capstone does exactly that, live, in the browser.
predicted: Vertical edge (57%)
predicted: Vertical edge (55%)
predicted: Vertical edge (55%)
predicted: Horizontal edge (59%)
Four tiny 6×6 images, two classes: a vertical edge (the boundary runs top-to-bottom) and a horizontal edge (the boundary runs left-to-right). Two 3×3 filters, initialized to small random numbers, feed a small dense layer through ReLU (short for Rectified Linear Unit) and max pooling — the exact shape from Chapter 3, but every weight starts unlearned. Click train and watch the loss fall as the filters reorganize themselves into something that actually tells the two classes apart.
The architecture is unchanged from Chapter 3 — image → convolution → ReLU → pool → flatten → dense → softmax — but now there are two filters instead of one, and a real loss to minimize:
- — the loss being minimized during training.
- — the softmax probability the network assigns to the correct class.
- This is cross-entropy loss
It's the cross-entropy loss from Part II, computed over the softmax of the two output logits.
- Backprop threads through every stage
Backpropagation runs through every stage, in reverse order:
- The softmax gradient
- Back through the dense weights
- Back through max-pooling, which routes each gradient only to the position that actually won each window
- Back through ReLU, zero wherever the pre-activation wasn't positive
- Finally back into the two 3×3 kernels themselves
The same chain rule as always, just longer.
predicted: Vertical edge (57%)
predicted: Vertical edge (55%)
predicted: Vertical edge (55%)
predicted: Horizontal edge (59%)
Reset, then train one step at a time. Early on, the two random filters produce feature maps that don't separate the classes — predictions hover near 50%. After a few steps, watch one filter's weights drift toward something with a clear positive-to-negative split across a row or column — a shape it invented on its own, not copied from anywhere, because it's the shape that actually helps tell a vertical edge from a horizontal one.
- Chapter 1's hand-designed kernel
The vertical-edge kernel : every row sums to zero, and the sign flips from one side of the kernel to the other.
- What a trained filter converges to
A filter that learns to solve this task tends toward the same kind of structure — not the identical numbers, but the same shape of solution: something whose row-sums or column-sums cancel out for a constant patch, and don't cancel when a patch straddles an edge. Nobody told the network that; gradient descent found it because it's what reduces the loss.
Train the network until its loss on the digit set drops below 0.01.
predicted: Vertical edge (57%)
predicted: Vertical edge (55%)
predicted: Vertical edge (55%)
predicted: Horizontal edge (59%)
Every weight in this network — both kernels, both biases, the dense layer — was found by gradient descent, not hand-picked. That's the entire difference between Chapter 3 and this capstone: same architecture, same forward pass, but the numbers came from data instead of from a human. Part IV continues from images to sequences next: the same idea of a small, structured architecture, learned end-to-end, applied to data where order is the whole point.