Machine Learning · Backpropagation

Neural Network Playground

Design architectures · Train with gradient descent · Watch decision boundaries evolve

0
Epoch
Train Loss
Accuracy
Parameters

Presets

Architecture

Training

0.01
8
10×

Visualisation

Neural Network Fundamentals

🔁 Backpropagation

The chain rule applied recursively: compute ∂L/∂w for every weight by propagating error gradients from output to input. Enables learning in networks with thousands of layers.

⚡ Activation Functions

Non-linearities that allow networks to learn complex patterns. ReLU (max(0,x)) avoids vanishing gradients in deep nets; Sigmoid squashes to (0,1); Tanh centres around zero.

📉 Loss Landscape

Cross-entropy for classification; MSE for regression. Gradient descent navigates the loss surface by following the negative gradient — the direction of steepest descent.

🏗️ Universal Approximation

A network with one hidden layer and enough neurons can approximate any continuous function (Cybenko 1989). Depth helps efficiency — each layer learns higher-level abstractions.

Activation Function Comparison

FunctionFormulaOutput RangeGradientBest ForWeakness
Sigmoid1/(1+e⁻ˣ)(0, 1)f(1−f)Output layer (binary)Vanishing gradient in deep nets
Tanh(eˣ−e⁻ˣ)/(eˣ+e⁻ˣ)(−1, 1)1−f²Hidden layers (zero-centred)Still saturates at extremes
ReLUmax(0, x)[0, ∞)0 or 1Deep networks (default)Dying ReLU (neurons stuck at 0)
Leaky ReLUmax(0.01x, x)(−∞, ∞)0.01 or 1Deep networksSlight inconsistency for negative
ELUx if x≥0; α(eˣ−1) else(−α, ∞)SmoothNegative push (self-normalising)Computationally expensive
GELUx·Φ(x)(−0.17, ∞)Soft gateTransformers (BERT, GPT)More complex to compute
Swishx·σ(x)(−0.28, ∞)SmoothDeep networks (EfficientNet)Requires parameter search
Softmaxeˣⁱ/Σeˣʲ(0, 1) summing to 1p(1−p)Multi-class outputOnly valid at output layer

Frequently Asked Questions

What is backpropagation?

Backpropagation applies the chain rule to compute ∂L/∂w for every weight — propagating error gradients backwards from output to input. Each weight is updated: w ← w − α·(∂L/∂w). One forward + backward pass is one training step. The algorithm runs in O(|weights|) time, making it tractable for millions of parameters.

Why do deep networks need non-linear activation functions?

Without non-linear activations, any stack of linear layers collapses to a single linear map: W₂(W₁x) = (W₂W₁)x. No matter how many layers, only linear decision boundaries are possible. Non-linear activations (ReLU, sigmoid, tanh) allow the network to compose non-linear transformations — proven sufficient to approximate any function by the Universal Approximation Theorem.

What causes overfitting?

Overfitting occurs when the model has too many parameters relative to training data. The network memorises training examples rather than learning general patterns, producing low training loss but high validation loss. Remedies: dropout (randomly zero activations), L2 regularisation (weight decay), early stopping, data augmentation, or reducing model size.

What is the Universal Approximation Theorem?

Cybenko (1989) and Hornik (1991) proved that a single hidden layer with enough neurons and a non-linear activation can approximate any continuous function on a compact domain to arbitrary precision. This gives theoretical justification for neural networks — though it does not say how many neurons are needed or whether gradient descent will find the solution.

Learn the Theory Behind Neural Networks

CNNs, RNNs, transformers, attention mechanisms, training techniques, and regularisation — all explained.

Read Deep Learning Guide →