Jacobians and Hessians: derivatives as tables
A function with many outputs has a whole table of derivatives, the Jacobian. A function's second derivatives form another, the Hessian, which describes curvature.
1. The idea
The gradient is the derivative of a function with one output. A layer has many outputs, so its derivative is a table: the Jacobian J, with one row per output and one column per input, Jᵢⱼ = ∂fᵢ/∂xⱼ. For a linear layer f(𝐱) = W𝐱 the Jacobian is W itself. Backpropagation through a stack of layers multiplies Jacobians, which is the chain rule written with matrices.
Second derivatives describe curvature. For a function with one output and n inputs, the Hessian H is the n × n table of every ∂²f/∂xᵢ∂xⱼ, and it is symmetric. Its eigenvalues say how curved the function is in each direction: all positive at a minimum, mixed signs at a saddle point.
In deep learning the Hessian is mostly a thinking tool: with a million parameters it has a trillion entries, far too many to store. Second-order optimizers approximate it, and “sharp” and “flat” minima are statements about its eigenvalues.
2. Try it: what shape is the derivative?
Set how many numbers go in and come out, or pick an example. The grids are the shapes of the derivatives.
3. The math
4. The code (python)
import numpy as np
W = np.array([[1.0, -2.0, 0.5],
[0.0, 3.0, 1.0]]) # a layer: 3 inputs, 2 outputs
def layer(x):
return W @ x
x = np.array([1.0, 2.0, -1.0])
h = 1e-6
J = np.column_stack([(layer(x + h * e) - layer(x)) / h for e in np.eye(3)])
print(J.shape, np.allclose(J, W)) # (2, 3) True
H = np.array([[2.0, 1.0],
[1.0, 4.0]]) # the Hessian of x^2 + xy + 2y^2
print(np.linalg.eigvalsh(H).round(3)) # [1.586 4.414]
print(1_000_000 ** 2) # 10000000000005. You’ll see this in
- Reference notes: linear algebra and matrix calculus Jacobians and Hessians, more formally
- Reference notes: convexity, optimization and duality
- Core Course chapter 10: optimizers methods that adapt to curvature without a Hessian
6. Check yourself
Finished this chapter?
What changed in ML architectures this week
New models worth knowing, benchmark moves, and one architecture explained in plain words. Free, once a week, unsubscribe anytime.