notesonly.in

One notebook for every subject — open it anywhere.

Log in

Neural Networks and Backpropagation With easy examples.

Training a neural network means tuning millions of weights so predictions match the training data. Backpropagation makes this possible: it computes, for every weight, how much a tiny change would alter the final error — efficiently, by applying the chain rule of calculus backwards, layer by layer, from output to inputs.

Backpropagation turned neural networks from a curiosity into the engine of modern AI. Before it, there was no practical way to train networks with hidden layers; with it, gradient descent tunes enormous networks on images, text, and sound. Every deep learning breakthrough rests on it computing gradients at scale.

Key Concepts

  • Forward pass: pushing inputs through the network to produce a prediction.
  • Loss: a single number measuring prediction error, such as squared error.
  • Gradient: the partial derivatives of the loss with respect to every weight; points toward steepest error increase.
  • Chain rule: the derivative of a composition equals the product of the derivatives of its parts.
  • Backward pass: propagating error derivatives from the output layer back to earlier layers.
  • Learning rate: the update step size; too large diverges, too small crawls.
  • Gradient descent: repeatedly stepping each weight opposite its gradient to reduce the loss.
  • Epoch: one full pass over the training data.

Formulas

  • Chain rule for one weight: dL/dw = (dL/d prediction) times (d prediction/dz) times (dz/dw), where z = w times x + b is the neuron's weighted sum. Each factor is easy; their product is the exact gradient.
  • Gradient descent update: w_new = w_old − learning_rate times gradient. Assumes a differentiable loss and a small, stable learning rate; it finds local, not global, optima.

Worked Example

Train one neuron with linear activation (prediction = z), squared-error loss L = (y − prediction) squared, input x = 2, target y = 3, weight w = 0.5, bias b = 0. Forward pass: z = 0.5 times 2 = 1, so prediction = 1; L = (3 − 1) squared = 4. Backward pass: dL/d prediction = −2 times (3 − 1) = −4; d prediction/dz = 1; dz/dw = x = 2, so the weight gradient = −4 times 1 times 2 = −8. Also dz/db = 1, so the bias gradient = −4. Update with learning rate 0.05: w = 0.5 + 0.4 = 0.9; b = 0 + 0.2 = 0.2. New forward pass: prediction = 0.9 times 2 + 0.2 = 2.0; new L = (3 − 2) squared = 1. The loss fell from 4 to 1 in one exact step — that is learning.

Common Misconceptions

  • Backpropagation is biologically realistic. It is an efficient gradient algorithm; brains do not do reverse-mode differentiation.
  • Networks learn instantly. Real training needs many epochs over many examples.
  • A bigger learning rate means faster learning. Too big a step overshoots and the loss explodes.

Real-World Applications

  • Training all deep models: every vision and language network is trained this way.
  • Fine-tuning: small gradient steps adapt big pretrained models to new tasks.
  • Reinforcement learning: gradients tune the networks choosing game moves and robot actions.
  • Autoencoders: compressing and reconstructing data for denoising and anomaly detection.

Backpropagation computes each weight's exact effect on the error by chaining derivatives backwards; gradient descent then steps every weight against its gradient. Forward pass, chain-rule gradients, update, lower loss — repeated billions of times, this loop trains every neural network in the world.