Skip to content
GATEiit

GATE IN · Engineering Mathematics

Backpropagation for neural networks

Reverse-mode automatic differentiation for feedforward neural networks: forward pre-activations, activation derivatives, local error deltas δ, vectorized weight/bias gradients, and gradient vanishing.

Before you start

Concept notes

1. Forward Layer Computation, Activations and Loss Functions

In an L-layer feedforward neural network, layer l transforms the previous layer's activation vector a(l−1) (a(0)=x):

z(l)=W(l)a(l−1)+b(l),a(l)=σ(z(l))

Activation Definition σ(z) Derivative σ′(z)
Sigmoid 11+e−z σ(z)(1−σ(z)) (max 0.25 at z=0)
Hyperbolic tangent tanh⁡(z) 1−tanh⁡2(z) (max 1 at z=0)
ReLU max⁡(0,z) 1 if z>0, 0 if z<0

Common scalar losses on output y^=a(L) and target y: half-MSE L=12∥y^−y∥22 (giving ∇y^L=y^−y) and binary cross-entropy L=−[yln⁡y^+(1−y)ln⁡(1−y^)].

Input a⁽ˡ⁻¹⁾ × weights W⁽ˡ⁾ Layer l z = W a + b, σ(z) Layer l+1 Output ŷ Loss L(ŷ,y) Scalar error Forward Pass: compute activations z⁽ˡ⁾ and a⁽ˡ⁾ → ← Backward Pass: δ⁽ˡ⁾ = ((W⁽ˡ⁺¹⁾)ᵀ δ⁽ˡ⁺¹⁾) ⊙ σ'(z⁽ˡ⁾) Parameter gradient at every layer: ∂L / ∂W⁽ˡ⁾ = δ⁽ˡ⁾ (a⁽ˡ⁻¹⁾)ᵀ, ∂L / ∂b⁽ˡ⁾ = δ⁽ˡ⁾
Forward activations are cached along the network and reused in reverse order to propagate sensitivity deltas δ⁽ˡ⁾ back to every weight.

2. The Four Vectorized Backpropagation Equations (Reverse-Mode Chain Rule)

Define the local error signal δ(l)≡∂L∂z(l). By the multivariable chain rule, all parameter gradients follow four equations:

  1. Output layer error: δ(L)=∇a(L)L⊙σ′(z(L)) (where ⊙ denotes elementwise Hadamard product).
  2. Hidden layer error propagation: δ(l)=((W(l+1))Tδ(l+1))⊙σ′(z(l)) Notice the weight matrix is transposed when routing errors backward.
  3. Weight gradient: ∂L∂W(l)=δ(l)(a(l−1))T (outer product of error at layer l and incoming activation).
  4. Bias gradient: ∂L∂b(l)=δ(l).

Once gradients are found, gradient descent updates W(l)←W(l)−η∂L∂W(l).

3. Logistic Sigmoid + Binary Cross-Entropy Gradient Simplification

Pairing a sigmoid output y^=σ(z) with MSE loss gives δ(L)=(y^−y)σ(z)(1−σ(z)): whenever y^ saturates near 0 or 1, σ′(z)≈0 slows learning even if error ∣y^−y∣≈1 is huge.

Pairing sigmoid (or softmax for multi-class) with cross-entropy loss cancels σ(1−σ):

∂LCE∂y^=y^−yy^(1−y^)  ⟹  δ(L)=∂LCE∂y^⋅y^(1−y^)=y^−y

The gradient is directly proportional to the prediction residual y^−y, completely eliminating output-layer saturation.

4. Vanishing Gradients, Exploding Gradients and Dead ReLUs

Multiplying Jacobian factors across L deep layers produces a product ∏k=lL−1diag⁡(σ′(z(k)))(W(k+1))T:

  • Vanishing gradient: Since max⁡σ′(z)=0.25 for logistic sigmoid, multiplying L factors shrinks early-layer gradients exponentially like (0.25∥W∥)L→0 when weights are small.
  • Exploding gradient: When spectral norm ∥W∥>1 repeatedly with linear/ReLU paths, gradients grow exponentially like λmax⁡L; resolved by gradient clipping and residual skip connections.
  • Dying ReLU: If a neuron's pre-activation stays negative (z<0) across all samples, ReLU′(z)=0 cuts off both weight and bias gradients permanently unless Leaky-ReLU or proper initialization is used.

Formulas to remember

Forward affine and activation
z(l)=W(l)a(l−1)+b(l),a(l)=σ(z(l))
Sigmoid derivative
σ′(z)=σ(z)(1−σ(z)),max⁡zσ′(z)=14
Hyperbolic tangent derivative
ddztanh⁡(z)=1−tanh⁡2(z)=sech⁡2(z)
Output error signal
δ(L)=∇a(L)L⊙σ′(z(L))
Backpropagated error delta
δ(l)=((W(l+1))Tδ(l+1))⊙σ′(z(l))
Weight and bias gradients
∂L∂W(l)=δ(l)(a(l−1))T,∂L∂b(l)=δ(l)
Sigmoid + cross-entropy residual
∂LCE∂z(L)=y^−y
Gradient descent weight update
Wnew(l)=W(l)−η∂L∂W(l)

Common mistakes

  • Dropping the σ′(z(l)) Hadamard factor when propagating δ(l+1) backward through hidden layer l.
  • Using W(l+1) instead of its transpose (W(l+1))T when backpropagating errors from layer l+1 to l.
  • Adding +η∇WL instead of subtracting −η∇WL when minimizing a loss function (that moves toward gradient ascent).
  • Applying the clean δ(L)=y^−y formula to MSE loss with a sigmoid output, forgetting the missing σ′(z(L))=y^(1−y^) term.
  • Confusing layer input a(l−1) with layer output a(l) inside the weight gradient outer product δ(l)(a(l−1))T.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Complete forward-backward-update pass for a sigmoid neuron

numerical

A single logistic sigmoid neuron has inputs x=[1,−2]T, weights w=[2,1]T, bias b=0, target y=1, and loss L=12(y^−y)2. Compute y^, ∂L∂w1, and the updated w1 after one SGD step with learning rate η=0.4.

  1. Step 1: Compute forward pre-activation and output

    Try it on paper first.

Example 2: Two-layer chain rule through hidden ReLU and linear output

numerical

A 2-layer scalar network computes z(1)=w1a(0), a(1)=ReLU⁡(z(1)), and linear output y^=w2a(1) with half-MSE loss L=12(y^−y)2. Given a(0)=2, w1=3, w2=0.5, y=1, find ∂L∂w2 and ∂L∂w1.

  1. Step 1: Run forward pass

    Try it on paper first.

Example 3: Why reverse-mode backprop beats finite differences or forward AD in deep nets

conceptual

Suppose a neural network has 106 trainable weights and 1 scalar loss output L. Compare the computational cost of computing ∇WL via forward finite differences vs backpropagation.

  1. Step 1: Count forward passes required by parameter perturbation

    Try it on paper first.

Example 4: Checking parameter dimension matching in matrix backpropagation

numerical

Layer l has 4 neurons receiving input from 3 neurons in layer l−1, and feeds 2 neurons in layer l+1. State the matrix dimensions of W(l), W(l+1), δ(l), δ(l+1), and verify (W(l+1))Tδ(l+1) and δ(l)(a(l−1))T.

  1. Step 1: Write matrix and vector column shapes

    Try it on paper first.

Previous year questions

No official GATE IN question is tagged with this topic yet. The topic test below uses practice questions.

Topic test

8 questions: original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.

Mark as mastered

Loading your progress…

My revision notes

Notes written by the GATEiit team against the official GATE IN syllabus; being checked by a reviewer. Updated 2026-12-01. Spotted a mistake? Use Report an issue on any question, or contact us.