Jacobians and vector–Jacobian products
This page translates the backward calculation into matrix notation. You can understand the main sequence without it. Use it when a lecture writes J, VJP, or a row of derivatives and skips the intermediate arithmetic.
One derivative for each output–input pair
Section titled “One derivative for each output–input pair”A Jacobian is a table of partial derivatives: one row per output, one column per input. If a function has n inputs and m outputs, its Jacobian has shape .
Take . Its Jacobian is
At (x,y) = (2,3), this is . An input change predicts output changes
The actual changes are 0.03 and 0.0702. The second output has a small product term that the first-order prediction omits.
A row of loss derivatives moves backward
Section titled “A row of loss derivatives moves backward”Now let the final scalar be . At u = 5 and v = 6, its derivatives form the row .
Multiply that row by :
For x, the two paths contribute . For y, they contribute . This is the same “multiply along, add across” rule in a matrix product.
A vector–Jacobian product, or VJP, takes a row of downstream derivatives and returns a row of upstream derivatives. Implementations can compute this product directly without constructing the full Jacobian.
Why a transpose sometimes appears
Section titled “Why a transpose sometimes appears”So far the loss derivatives are rows. Many texts store the gradient as a column instead. Transpose the relation:
Same entries, different orientation. Check the author’s convention and matrix dimensions before multiplying.
What about a layer Wx + b?
Section titled “What about a layer Wx + b?”For column vectors , , and downstream gradient :
| Derivative | Calculation | Shape |
|---|---|---|
| With respect to the input | ||
| With respect to the matrix | ||
| With respect to the bias |
An entry of the weight gradient is : downstream derivative at unit i times input j. In the small network, this builds the matrix with rows (−0.95, −1.9) and (0.475, 0.95).
For an elementwise activation, each coordinate multiplies its incoming derivative by its local slope. ReLU uses 1 for positive inputs and 0 for negative inputs, with an explicitly chosen backward convention at zero.
Forward mode and reverse mode
Section titled “Forward mode and reverse mode”A Jacobian–vector product computes : the outputs’ response to one input direction. A VJP computes a row times J: how one weighted combination of outputs depends on the inputs.
For a scalar loss and many parameters, reverse mode obtains the whole gradient with one backward sweep. Forward mode is useful for an individual input direction, and obtaining the full Jacobian by forward mode need not involve multiplying full matrices. Which mode is economical depends on the quantities you need.