Gradients, Jacobians & Hessians

Slopes, tables of slopes, and curvature: the calculus behind training.

🟡 intermediate5 min readcalculus
These are three ways of measuring how a function changes. The gradient is a list of slopes, one per input, pointing where the loss rises fastest, so gradient descent steps the opposite way. The Jacobian is the same idea for a function with several outputs, a full table of slopes, and it is what backpropagation chains together layer by layer. The Hessian measures how the slopes themselves change, which is the curvature: whether you sit in a bowl, on a ridge or at a saddle.

First and Second Derivatives in Multivariable Calculus

In single-variable calculus, we have f′(x)f'(x) (slope) and f′′(x)f''(x) (curvature).

Multivariable calculus extends these concepts to vectors and matrices:

┌──────────────────────────┬──────────────────────────┬──────────────────────────┐
│  1. GRADIENT ∇f(x)       │  2. JACOBIAN MATRIX J    │  3. HESSIAN MATRIX H     │
├──────────────────────────┼──────────────────────────┼──────────────────────────┤
│ Function: f: R^n -> R    │ Function: f: R^n -> R^m  │ Function: f: R^n -> R    │
│ First derivatives        │ First derivatives        │ Second derivatives       │
│ Dimensions: n × 1 Vector │ Dimensions: m × n Matrix │ Dimensions: n × n Matrix │
│ Direction of steepest ascent| Maps input to output change| Measures surface curvature|
└──────────────────────────┴──────────────────────────┴──────────────────────────┘

1. The Gradient Vector ∇f(x)\nabla f(x)

For a scalar loss function f(x1,x2,…,xn)f(x_1, x_2, \dots, x_n):

∇f(x)=[∂f∂x1,∂f∂x2,…,∂f∂xn]T\nabla f(x) = \left[ \frac{\partial f}{\partial x_1}, \frac{\partial f}{\partial x_2}, \dots, \frac{\partial f}{\partial x_n} \right]^T

2. The Jacobian Matrix JJ

When a function takes nn inputs and outputs mm values (f:Rn→Rmf: \mathbb{R}^n \to \mathbb{R}^m):

Jij=∂fi∂xj=[∂f1∂x1…∂f1∂xn⋮⋱⋮∂fm∂x1…∂fm∂xn]m×nJ_{ij} = \frac{\partial f_i}{\partial x_j} = \begin{bmatrix} \frac{\partial f_1}{\partial x_1} & \dots & \frac{\partial f_1}{\partial x_n} \\ \vdots & \ddots & \vdots \\ \frac{\partial f_m}{\partial x_1} & \dots & \frac{\partial f_m}{\partial x_n} \end{bmatrix}_{m \times n}

Backpropagation Chain Rule

For composed layers y=f(g(x))y = f(g(x)):

Jy,x=Jy,g⋅Jg,x(Matrix Multiplication of Jacobians!)J_{y, x} = J_{y, g} \cdot J_{g, x} \quad \text{(Matrix Multiplication of Jacobians!)}

3. The Hessian Matrix HH

Contains all pairwise second-order partial derivatives of scalar loss f(x)f(x):

Hij=∂2f∂xi∂xj=[∂2f∂x12…∂2f∂x1∂xn⋮⋱⋮∂2f∂xn∂x1…∂2f∂xn2]n×nH_{ij} = \frac{\partial^2 f}{\partial x_i \partial x_j} = \begin{bmatrix} \frac{\partial^2 f}{\partial x_1^2} & \dots & \frac{\partial^2 f}{\partial x_1 \partial x_n} \\ \vdots & \ddots & \vdots \\ \frac{\partial^2 f}{\partial x_n \partial x_1} & \dots & \frac{\partial^2 f}{\partial x_n^2} \end{bmatrix}_{n \times n}

By Schwarz's Theorem, if functions are smooth, HH is a Symmetric Matrix (Hij=HjiH_{ij} = H_{ji}).

Curvature Interpretation

Say this out loud

The Gradient is an n x 1 vector of first derivatives pointing in the direction of steepest ascent for a scalar loss. The Jacobian is an m x n matrix of first derivatives for vector-valued layer outputs, underpinning the chain rule in backpropagation. The Hessian is an n x n symmetric matrix of second derivatives measuring local loss surface curvature and saddle points.

Follow-ups to expect

Check yourself

Question 1 of 3

What are the tensor dimensions of the Jacobian matrix J for a vector-valued function f: R^n -> R^m?

More in Math & Statistics

See all →
Bayes’ Theorem4 minCentral Limit Theorem4 minLaw of Large Numbers4 min