Mission: the tensor playground
First mission of the deep-learning arc, and it runs on machinery you already own: start from the twenty-line autograd, prove every addition against a referee, then push it until it does real work.
The job: grow the twenty-line autograd from lesson 03 into a
one-neuron learner — and prove every gradient you add is correct
with a numeric check (the referee in the starter: nudge the input
by ±ε, measure the slope, compare to what your backward claims).
The stages:
- Gradient check harness — the starter runs it on
w*w + w. Note it already exercises a subtlety:wappears twice, and accumulation (+=) is what makes the gradient come out 5, not 4 or 1. You get chapter 42's accumulate rule for free. - New ops — add
relu()(gradient: pass-through if positive, zero otherwise) and subtraction. Numeric-check each. - A neuron —
pred = relu(w*x + b), squared-error loss against a target,.backward(), and a few hand-steppedw.data -= lr * w.gradupdates (zero the grads between steps — you know why now). Watch the loss fall: chapter 39's training loop, running on machinery you built. - Stress case — check relu's gradient exactly at 0 input, and a chain where one Value feeds two branches; the numeric referee settles both.
- One improvement — a
zero_grad()method, atanhop, or a two-input neuron: pick one, note why.
What goes in is you; what comes out is someone who has
implemented forward, backward, accumulation, and gradient
checking. After this,
loss.backward() in torch is a bigger version of code you wrote.