Machine Learning Foundations · Chapter 11 · ~15 min · Advanced
Neural Networks from Scratch: Perceptrons to Backprop
Demystify deep learning from mathematical first principles. Master the artificial neuron, understand why non-linear activations prevent deep layers from collapsing, and derive the calculus chain rule behind reverse-mode backpropagation.
- Formulate the artificial neuron z = W^T x + b and non-linear activation functions
- Prove why stacking linear layers without activations collapses into a single layer
- Break neuron symmetry using He/Xavier Gaussian random initialization
- Trace gradient backpropagation step-by-step using the multivariable chain rule
Neural Networks from Scratch: Perceptrons to Backprop: learn it visually
Demystify deep learning from mathematical first principles. Master the artificial neuron, understand why non-linear activations prevent deep layers from collapsing, and derive the calculus chain rule behind reverse-mode backpropagation.
1The Perceptron: Biology Meets Linear Algebra
In 1958, Frank Rosenblatt created the Perceptron, inspired by biological neurons in the brain:
Inputs x represent dendrite signals, weights w represent synaptic strengths, bias b is the firing threshold, and σ is the non-linear activation.
Wrong idea: Stacking 100 linear layers without non-linear activations
Multiplying linear equations collapses mathematically: W3(W2(W1 · x)) = (W3 · W2 · W1) · x = W_combo · x, equivalent to a simple single-layer regression.
Real system: Non-linear activations (ReLU, GELU, Sigmoid)
Applying non-linear activation functions bends coordinate spaces, enabling networks to become Universal Function Approximators for arbitrary manifolds.
What happens mathematically if you build a deep neural network with 50 hidden layers but completely omit all non-linear activation functions?
2Activation Functions: ReLU, Sigmoid, and Tanh
Non-linear activation functions introduce the curvature needed to learn complex decision boundaries:
f(z) = max(0, z)
The modern default. Derivative is 1 for z > 0, completely avoiding vanishing gradients in deep feedforward architectures.
f(z) = 1 / (1 + e-z)
Squashes outputs into (0, 1). Ideal for binary probability outputs, but suffers from severe vanishing gradients in hidden layers.
f(z) = (ez - e-z) / (ez + e-z)
Zero-centered outputs in (-1, +1). Historically popular in recurrent neural networks and early hidden layers.
Why did ReLU replace Sigmoid as the dominant hidden-layer activation function in modern deep networks?
3Backpropagation: The Multivariable Chain Rule
How does an error at the final output neuron propagate backwards to update weights in the first layer? Through the Calculus Chain Rule:
By caching intermediate values computed during the forward pass, backpropagation sweeps in reverse from the output layer to the input layer in exactly one single pass!
4Hands-On: 3-Layer Forward & Backprop Visualizer
Interact with the live 3-layer network below. Adjust the inputs x₁ and x₂, click 1. Forward Pass to propagate activations, then click 2. Step Backward to watch gradients flow in reverse:
Interactive 3-Layer Perceptron: Forward Propagation & Backprop Chain Rule
5Bug Hunt: Fix Zero-Weight Symmetry & Broken ReLU Derivative
An AI engineer built a 2-layer perceptron from scratch in NumPy. However, training immediately froze because weights were initialized to all zeros (W = np.zeros) and the backward pass neglected to multiply by the derivative of the ReLU activation function.
Repair the weight initialization and backward activation gradients:
🎯 Find and fix the bugs in the code above, then press Run & verify to test your solution.
Need a hint?
- Break symmetry with Gaussian random weights:
W1 = np.random.randn(n_hidden, n_in) * 0.01. - Multiply by ReLU derivative in backprop:
dz1 = da1 * (z1 > 0).
6Chapter Knowledge Challenge
Test your mastery of neural network architectures, forward passes, and backprop derivatives:
What catastrophic problem occurs if all weights in a multi-layer neural network are initialized to 0.0?
What is the derivative of the ReLU activation function f(z) = max(0, z) when z > 0?
7Recap
- An Artificial Neuron computes
z = WTx + band passes it through an activation function. - Non-Linear Activations (ReLU, Sigmoid) enable networks to approximate complex non-linear manifolds and prevent multi-layer linear collapse.
- Random Weight Initialization breaks neuron symmetry so hidden units specialize into distinct feature detectors.
- Backpropagation leverages the chain rule of calculus to compute exact partial derivatives for millions of parameters in a single reverse sweep.
Ready for Chapter 12? Mark this chapter as complete to proceed: