Jacobians: from local changes to neural-network backpropagation
In From derivatives to backpropagation, we followed individual numbers through a computation graph. Each operation supplied local derivatives. During the backward pass, we multiplied those derivatives by incoming gradients and added contributions wherever paths met.
A neural-network layer usually processes many numbers together. One input can affect several outputs, and each output can depend on several inputs. How do we organize all those derivatives, and what do they tell us about the layer?
The Jacobian is a matrix of first-order partial derivatives. We’ll build one from a two-input, two-output function, use it to predict small changes, and see why its rank can vary from point to point. Then we’ll connect that geometric picture to the matrix chain rule and explain why backpropagation usually needs products with Jacobians rather than the full matrices.
From partial derivatives to a matrix
A partial derivative measures how one output responds to one input while the other independent inputs stay fixed. With several outputs, we repeat that question for each output–input pair.
Consider a function with two inputs and two outputs:
For the first output, changing acts through the square, while changing acts through addition. For the second output, those roles reverse:
| Output | With respect to | With respect to |
|---|---|---|
Arrange this table into a matrix, keeping outputs as rows and inputs as columns:
This is the Jacobian matrix. For a function , it has rows and columns. The entry in row , column is .
A derivative rule and its value at a point
The expression above is a rule for constructing the Jacobian at any input. At , it gives:
The function gives the current outputs. The Jacobian tells us how those outputs respond to changes around the current inputs. For example, its first column says that a small increase in changes at rate and at rate , holding fixed.
Its second column answers the corresponding question for : the rates are and . A column therefore collects one input’s effect on all outputs. A row collects all inputs’ effects on one output.
Where the gradient fits
These familiar objects organize the same kind of information:
| Function | Derivative information |
|---|---|
| One input, one output | A scalar derivative |
| Several inputs, one scalar output | A gradient vector |
| Several inputs, several outputs | A Jacobian matrix |
The Jacobian also covers the first two cases. For a scalar loss , its Jacobian has one row. If we write gradients as column vectors, then:
The superscript means transpose: swap rows and columns. We’ll consistently use column vectors for gradients below.
The Jacobian predicts local changes
For a scalar function, we used . The vector version is:
Matrix multiplication combines the effects of the input changes. At , suppose we change the inputs by :
For the first output, the two first-order effects cancel: . For the second, they combine to .
Evaluating the original function at the new inputs gives the exact change:
The small discrepancy comes from the squared changes. For this function, expanding the two squares gives:
The Jacobian captures the first-order terms. It does not describe every finite change exactly.
Why diagrams zoom into a small region
A nonlinear transformation can bend an entire grid. Near a chosen point, its behavior can be approximated by a linear transformation of small displacements. The full approximation is:
Notice the two parts: locates the transformed center, and the Jacobian transforms the displacement from that center. Multiplying an arbitrary point by the Jacobian alone does not reproduce the original nonlinear function.
The explorer below compares the actual transformed grid with the Jacobian’s prediction. Both plots use coordinates relative to their respective centers. Reduce to see the prediction improve; the axes zoom with the radius so the shapes remain visible.
Rank = 2
A curved grid and its local matrix
The explorer’s uses:
Here and name the two input coordinates. At :
A small horizontal displacement therefore produces an approximate output displacement:
Moving right in the input space also moves downward in the output space near this point. The first column of the Jacobian describes that response. The second column describes the response to moving vertically.
This is why a diagram may highlight just one small rectangle within a curved grid: it is comparing the nonlinear map with its local linear approximation at that rectangle’s center.
Shape counts variables; rank counts independent responses
The number of inputs and outputs determines the Jacobian’s shape. Its rank measures how many independent directions of output change its linear approximation can produce:
More precisely, these first-order output changes lie in the Jacobian’s column space, whose dimension is its rank. Two inputs do not necessarily provide two independent output directions: their effects might point along the same line.
Return to our polynomial example:
For this matrix, a nonzero determinant means rank . When , its rank is . It cannot have rank because its off-diagonal entries are always .
| Current input | Jacobian | Rank |
|---|---|---|
At , both columns are identical. Changing either input alone produces the same first-order output direction. A change cancels in the linear approximation:
This direction lies in the Jacobian’s null space. But the exact output change is , so zero first-order change does not imply zero finite change.
Select in the explorer. The Jacobian maps the small square to a line, while the actual transformed grid still has curvature. The rank describes the linear approximation at this point; it does not establish that an entire neighborhood of the nonlinear function collapses to a line.
This connects Jacobians to matrix rank: the linear-algebra definition stays the same, but the matrix itself can change as we move through the input space.
The chain rule becomes matrix multiplication
Now connect several transformations:
Suppose and are scalars, while and each contain two values. The diagram below connects each local partial derivative to the input–output connection it describes. Select an entry in a Jacobian to highlight that connection.
| out ↓ / in → | x |
|---|---|
| a₁ | |
| a₂ |
| out ↓ / in → | a₁ | a₂ |
|---|---|---|
| b₁ | ||
| b₂ |
| out ↓ / in → | b₁ | b₂ |
|---|---|---|
| p |
(1 × 2)(2 × 2)(2 × 1) = (1 × 1)
The number of outputs determines the rows, and the number of inputs determines the columns:
| Transformation | Jacobian | Shape |
|---|---|---|
A small change passes through the layers as:
Combining these gives the matrix chain rule:
Each Jacobian is evaluated at the input to its own transformation: , , and . The intermediate values come from the forward pass. The chain rule gives an exact derivative where these functions are differentiable, even though predicting a finite change with it is generally an approximation.
Multiplication adds the paths automatically
Use a concrete example:
At , the forward pass gives , , and . The local Jacobians are:
Therefore:
The collects the two paths from to : one contributes , and the other contributes . Matrix multiplication performs the same multiply-along-paths, add-between-paths calculation as our scalar engine. Expanding confirms that at .
Backpropagation needs Jacobian products
During training, we usually have one scalar loss and many parameters. For an operation , suppose the backward pass has already calculated how the final loss responds to each output .
A layer’s input can affect several outputs, each of which can affect the final loss. To calculate that input’s gradient, backpropagation must account for every one of these routes. The Jacobian organizes the local derivatives needed for this calculation: one column records how a particular input affects all the outputs. We multiply those entries by the corresponding output gradients and add the contributions:
Writing the gradients as columns turns this into:
If has shape , its transpose has shape . Multiplying it by the output gradients produces the input gradients. The transpose does not reverse the forward function or invert its matrix; it organizes how output sensitivities combine for each input.
For the numerical example above, treat as the scalar objective and start with . Because , the incoming gradient for the middle layer is:
That layer computes and . The input affects both outputs, so its gradient must include both routes. The input affects only :
| Input | Contribution through | Contribution through | Total input gradient |
|---|---|---|---|
Each contribution multiplies an incoming output gradient by a local derivative. The Jacobian-transpose product performs both rows of this calculation together:
Finally, pass these gradients through at :
This is why Jacobians appear in explanations of backpropagation: they organize all the local derivative contributions needed to move a gradient through a vector operation. Our scalar engine accumulated the same contributions one edge at a time.
Why engines don’t usually build the matrices
An operation can compute the required product from its derivative rule and saved values. It need not materialize every entry of its Jacobian. PyTorch describes this as a vector–Jacobian product. In row-vector notation it is ; our column-vector notation writes its transpose, .
Consider an elementwise operation . Its Jacobian is diagonal, with entries . Given an incoming gradient , the backward rule is simply:
A vector of length needs such multiplications; there is no reason to allocate a dense matrix full of off-diagonal zeros.
For a dense layer , the input Jacobian is . With incoming column gradient , its backward rules are:
These formulas describe one example; contributions from multiple examples are combined according to the loss’s reduction. They also show why input gradients and parameter gradients are distinct: the same operation has derivatives with respect to each of its inputs, including its weights and biases.
Input changes forward, loss sensitivities backward
The two directions use the same local derivative information for different questions:
| Calculation | Question |
|---|---|
| How does a small input displacement affect the outputs? | |
| How do output sensitivities to the loss combine into input sensitivities? |
Propagating a tangent vector forward computes a Jacobian–vector product. Propagating a loss gradient backward computes the corresponding vector–Jacobian product. Neither is the ordinary forward pass, which evaluates the function’s values.
Our earlier engine implements the backward calculation through scalar edges. A tensor engine groups many of those contributions into operations on arrays. The Jacobian connects the two descriptions: its columns explain local changes geometrically, its rank describes independent first-order responses, and its products express the chain-rule calculation used in backpropagation.
Follow-up: using Jacobians to interpret a language model
Sida Liu’s My Attempt to Explain the Jacobian Lens: A Single Jacobian Already Works applies these ideas to model interpretability. It follows how maps a small change along an intermediate activation direction to a change in the final activation, and how traces an output direction’s sensitivity back to the intermediate layer. The note also tests whether a Jacobian measured on one passage can help read activations from unrelated passages—a useful next step from understanding local derivatives to investigating what a trained model represents.