For a mini-batch of examples stacked as rows in , a two-layer network computes , and , where , , , and is the all-ones vector. Given the batch-averaged loss gradient , what are the gradients with respect to , and how do matrix dimensions verify the transposes?
Deep learning, Backpropagation
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.
What's being asked
Whether you can vectorise backpropagation across a row-major mini-batch and use tensor shapes to verify every transpose.
Key idea
Summing over the examples in a batch is a matrix product along the axis: , , , and .
Steps
- Note the scaling: because , the factor is already inside , so do not divide by a second time.
- Output layer weights and bias: matching gives . Summing rows of gives .
- Hidden activations and pre-activations: , whose shape is . Multiplying element-wise (denoted ) by the activation derivative gives .
- First layer weights and bias: matching gives , and .
Common mistakes
- Dividing by again when is already the gradient of the mean loss.
- Using column-major formulas () on row-major data , which fails shape checks.
- Averaging the bias gradient with on top of , instead of summing rows.
How long your answer should be
Half a page; 4–5 minutes.
Last checked on 4 December 2026.
Read this
Previous in Deep learning: Consider a small ReLU network with input , hidden layer with , , and scalar output with (no biases). For target and squared loss , what are the exact gradients and ?
Next in Deep learning: How do you express the derivatives of and purely in terms of and , what are their maximum values, and why is generally preferred over in hidden layers?