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 ?
Deep learning, Backpropagation
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.
What's being asked
Whether you can run a forward pass and a matrix backpropagation pass by hand on a ReLU network, including blocking gradients through inactive ReLU units.
Key idea
Compute in the forward pass, then propagate backwards using and , where is element-wise multiplication and is the indicator vector ( where , otherwise).
Steps
- Forward pass: , so .
- Output and loss: , and .
- Output gradient: , so .
- Backpropagate through ReLU: . Since and , the ReLU mask is , giving .
- Weight gradient: .
Common mistakes
- Propagating through the second hidden unit even though .
- Taking instead of , which gives the transpose of .
- Forgetting the factor in the loss derivative and multiplying by .
How long your answer should be
Half a page; 4–5 minutes.
Read this
Previous in Deep learning: What is the general message-passing neural network (MPNN) update for node , and how do you prove that relabelling nodes with any permutation matrix makes a node-level GNN layer permutation-equivariant while global sum or mean pooling makes a graph-level readout permutation-invariant?
Next in Deep learning: 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?