A churn network maps four features x ∈ ℝ⁴ through a = W₁x + b₁ (W₁ is 3 × 4), h = ReLU(a) and z = W₂h + b₂ (W₂ is 2 × 3). Writing the Jacobian with entry (i, j) = ∂zᵢ/∂xⱼ, what is ∂z/∂x?
Show the answer and explanation
Correct answer: B, W₂·diag(1[a > 0])·W₁, of shape 2 × 4: Jacobians multiply in chain order with the outer layer on the left, ReLU adds a 0/1 diagonal, and biases add no term of their own.
Explanation Calculus & Gradients
The multivariable chain rule multiplies Jacobians in the order the functions are composed, with the outermost function on the left:
∂z/∂x = (∂z/∂h)·(∂h/∂a)·(∂a/∂x) = W₂ · diag(1[a > 0]) · W₁
| Factor | Jacobian | Shape |
|---|---|---|
| z = W₂h + b₂ | W₂ | 2 × 3 |
| h = ReLU(a), elementwise | diag(1[a > 0]) | 3 × 3 |
| a = W₁x + b₁ | W₁ | 3 × 4 |
| Product | ∂z/∂x | 2 × 4 |
Key facts: the Jacobian of y = Wx + b with respect to x is simply W (outputs × inputs); the bias adds no term because it does not depend on x, though b₁ still shifts a and so decides which units are active. An elementwise activation has a diagonal Jacobian; for ReLU the entries are 1 for active units and 0 for inactive ones (at exactly a = 0 frameworks use 0). So the network's Jacobian is piecewise constant: it changes whenever the activation pattern changes.
Why the others fail: W₁ᵀ·diag(1[a > 0])·W₂ᵀ is the transpose of the Jacobian. It is what backpropagation multiplies by the upstream gradient (∂L/∂x = Jᵀ·∂L/∂z, a vector-Jacobian product), but it is not ∂z/∂x in the stated convention. ReLU has slope 0, not 1, for negative inputs, so it cannot be dropped. And its derivative is an indicator, not the pre-activation value itself.
Interview tip: check shapes first: a 2-output, 4-input map must have a 2 × 4 Jacobian, and inner dimensions must match (2×3 · 3×3 · 3×4). Saying that backprop computes Jᵀv without ever forming J shows you understand why it is efficient.