Skip to content
nonconvexcard

Implement backpropagation from scratch

CodingIntermediate⏱ 3 hoursDeep Learningbackpropagationimplementationgradient check

Problem

Implement a small MLP with forward and backward passes by hand (no autodiff), and verify it.

  1. Check the analytic gradient against central finite differences.
  2. Measure the wall-clock ratio of backward to forward passes.
  3. Demonstrate vanishing gradients with a deep sigmoid network, and fix it with He initialisation plus ReLU.
  4. Add a residual connection and measure the gradient norm at the first layer as depth grows.

Implement it, then check the implementation against something you can verify independently.

Write it

Solve it here5 tests · Python runs in your browser
⌘/Ctrl + ↵ to run · limit 30s · draft saved in this browser
5 tests will run against your code. The first run downloads the Python runtime — several megabytes, once per browser.

Solution

Opening this before you have a real attempt on paper is the fastest way to feel like you understand something you cannot reproduce.

Related problems

All problems
SolvedProblemFieldTypeDifficultyTime
XOR is not linearly separableDeep LearningProofFoundation15 min
Derive the backpropagation recursionDeep LearningProofIntermediate30 min
Gradient magnitude through a deep chainDeep LearningProofIntermediate30 min
Implement kernel ridge regression runClassical MLCodingIntermediate1 hour
Implement multi-head attention from scratch runDeep LearningCodingIntermediate3 hours