Intuition The big picture (WHY)
A single-input, single-output function f ( x ) f(x) f ( x ) has ONE derivative f ′ ( x ) f'(x) f ′ ( x ) — one number telling you the slope. But in ML we constantly deal with functions that take a vector in and spit a vector out : f : R n → R m \mathbf{f}: \mathbb{R}^n \to \mathbb{R}^m f : R n → R m . Now "the slope" is not one number — it's a whole table of partial derivatives , one for every (output, input) pair. That table is the Jacobian matrix . It's the best linear approximation of a vector-valued function near a point — the multi-dimensional generalization of f ′ ( x ) f'(x) f ′ ( x ) .
Definition Jacobian matrix
For f : R n → R m \mathbf{f}: \mathbb{R}^n \to \mathbb{R}^m f : R n → R m with components
f ( x ) = [ f 1 ( x 1 , … , x n ) ⋮ f m ( x 1 , … , x n ) ] , \mathbf{f}(\mathbf{x}) = \begin{bmatrix} f_1(x_1,\dots,x_n) \\ \vdots \\ f_m(x_1,\dots,x_n) \end{bmatrix}, f ( x ) = f 1 ( x 1 , … , x n ) ⋮ f m ( x 1 , … , x n ) ,
the Jacobian J J J (also written J f \mathbf{J_f} J f or ∂ f ∂ x \dfrac{\partial \mathbf{f}}{\partial \mathbf{x}} ∂ x ∂ f ) is the ==m × n m \times n m × n == matrix
J i j = ∂ f i ∂ x j . J_{ij} = \frac{\partial f_i}{\partial x_j}. J ij = ∂ x j ∂ f i .
Row i i i = gradient of output f i f_i f i . Column j j j = how every output responds to input x j x_j x j .
J = [ ∂ f 1 ∂ x 1 ⋯ ∂ f 1 ∂ x n ⋮ ⋱ ⋮ ∂ f m ∂ x 1 ⋯ ∂ f m ∂ x n ] J = \begin{bmatrix}
\dfrac{\partial f_1}{\partial x_1} & \cdots & \dfrac{\partial f_1}{\partial x_n} \\[6pt]
\vdots & \ddots & \vdots \\[6pt]
\dfrac{\partial f_m}{\partial x_1} & \cdots & \dfrac{\partial f_m}{\partial x_n}
\end{bmatrix} J = ∂ x 1 ∂ f 1 ⋮ ∂ x 1 ∂ f m ⋯ ⋱ ⋯ ∂ x n ∂ f 1 ⋮ ∂ x n ∂ f m
Intuition Shape mnemonic — "rows are outputs, columns are inputs"
The Jacobian has ==m m m rows (one per output) and n n n columns== (one per input). So J ∈ R m × n J \in \mathbb{R}^{m\times n} J ∈ R m × n . Check: it must be able to multiply an input-direction vector Δ x ∈ R n \Delta\mathbf{x}\in\mathbb{R}^n Δ x ∈ R n and give an output-change Δ f ∈ R m \Delta\mathbf{f}\in\mathbb{R}^m Δ f ∈ R m . ( m × n ) ( n × 1 ) = ( m × 1 ) (m\times n)(n\times 1) = (m\times 1) ( m × n ) ( n × 1 ) = ( m × 1 ) . ✔
Intuition Derivation idea
The derivative of f f f at x x x is the number that makes the linear approximation work:
f ( x + h ) ≈ f ( x ) + f ′ ( x ) h . f(x+h)\approx f(x)+f'(x)\,h. f ( x + h ) ≈ f ( x ) + f ′ ( x ) h .
We simply demand the SAME thing for vectors: find the linear map J J J such that
f ( x + h ) ≈ f ( x ) + J h . \mathbf{f}(\mathbf{x}+\mathbf{h}) \approx \mathbf{f}(\mathbf{x}) + J\,\mathbf{h}. f ( x + h ) ≈ f ( x ) + J h .
Everything about the Jacobian falls out of this one requirement.
Step 1 — Look at one output at a time. Take component f i f_i f i . It's a scalar function of a vector, so its first-order Taylor expansion is
f i ( x + h ) ≈ f i ( x ) + ∑ j = 1 n ∂ f i ∂ x j h j . f_i(\mathbf{x}+\mathbf{h}) \approx f_i(\mathbf{x}) + \sum_{j=1}^{n}\frac{\partial f_i}{\partial x_j}\,h_j. f i ( x + h ) ≈ f i ( x ) + j = 1 ∑ n ∂ x j ∂ f i h j .
Why this step? This is just the multivariable Taylor / total-differential rule: perturbing each input x j x_j x j by h j h_j h j changes f i f_i f i at rate ∂ f i / ∂ x j \partial f_i/\partial x_j ∂ f i / ∂ x j , and small effects add up.
Step 2 — Recognize the sum as a dot product.
∑ j ∂ f i ∂ x j h j = [ ∂ f i ∂ x 1 ⋯ ∂ f i ∂ x n ] ⏟ row i h = ( ∇ f i ) ⊤ h . \sum_{j}\frac{\partial f_i}{\partial x_j}h_j = \underbrace{\Big[\tfrac{\partial f_i}{\partial x_1}\ \cdots\ \tfrac{\partial f_i}{\partial x_n}\Big]}_{\text{row }i}\,\mathbf{h} = (\nabla f_i)^\top \mathbf{h}. j ∑ ∂ x j ∂ f i h j = row i [ ∂ x 1 ∂ f i ⋯ ∂ x n ∂ f i ] h = ( ∇ f i ) ⊤ h .
Why this step? A weighted sum of h j h_j h j is exactly a matrix row times h \mathbf{h} h . That row is the gradient of f i f_i f i .
Step 3 — Stack all m m m rows. Doing this for every output simultaneously:
f ( x + h ) ≈ f ( x ) + J h , J = [ ( ∇ f 1 ) ⊤ ⋮ ( ∇ f m ) ⊤ ] . \mathbf{f}(\mathbf{x}+\mathbf{h}) \approx \mathbf{f}(\mathbf{x}) + J\mathbf{h}, \qquad
J = \begin{bmatrix}(\nabla f_1)^\top\\ \vdots \\ (\nabla f_m)^\top\end{bmatrix}. f ( x + h ) ≈ f ( x ) + J h , J = ( ∇ f 1 ) ⊤ ⋮ ( ∇ f m ) ⊤ .
Why this step? Stacking the row-approximations is the same as one matrix equation. The matrix whose rows are the gradients is the Jacobian. ∎
Worked example Example 1 — a
2 → 2 2\to 2 2 → 2 map
f ( x , y ) = [ x 2 y x + sin y ] \mathbf{f}(x,y)=\begin{bmatrix} x^2 y \\ x+\sin y\end{bmatrix} f ( x , y ) = [ x 2 y x + sin y ] . Find J J J and evaluate at ( 1 , 0 ) (1,0) ( 1 , 0 ) .
Partials:
∂ f 1 / ∂ x = 2 x y \partial f_1/\partial x = 2xy ∂ f 1 / ∂ x = 2 x y , ∂ f 1 / ∂ y = x 2 \quad \partial f_1/\partial y = x^2 ∂ f 1 / ∂ y = x 2
∂ f 2 / ∂ x = 1 \partial f_2/\partial x = 1 ∂ f 2 / ∂ x = 1 , ∂ f 2 / ∂ y = cos y \quad \partial f_2/\partial y = \cos y ∂ f 2 / ∂ y = cos y
J ( x , y ) = [ 2 x y x 2 1 cos y ] , J ( 1 , 0 ) = [ 0 1 1 1 ] . J(x,y)=\begin{bmatrix} 2xy & x^2 \\ 1 & \cos y\end{bmatrix}, \qquad J(1,0)=\begin{bmatrix} 0 & 1 \\ 1 & 1\end{bmatrix}. J ( x , y ) = [ 2 x y 1 x 2 cos y ] , J ( 1 , 0 ) = [ 0 1 1 1 ] .
Why each step? Each entry is "output i i i , differentiate w.r.t. input j j j , treat the other input as constant." Plugging ( 1 , 0 ) (1,0) ( 1 , 0 ) turns the symbolic slopes into concrete numbers — the local linear map.
Worked example Example 2 — chain rule via Jacobians (matches backprop)
Let z = W x \mathbf{z}=W\mathbf{x} z = W x (linear layer, W ∈ R m × n W\in\mathbb{R}^{m\times n} W ∈ R m × n ) then a = σ ( z ) \mathbf{a}=\sigma(\mathbf{z}) a = σ ( z ) elementwise.
J z = ∂ z ∂ x = W J_{\mathbf{z}}=\dfrac{\partial \mathbf{z}}{\partial \mathbf{x}}=W J z = ∂ x ∂ z = W . Why? z i = ∑ j W i j x j z_i=\sum_j W_{ij}x_j z i = ∑ j W ij x j , so ∂ z i / ∂ x j = W i j \partial z_i/\partial x_j = W_{ij} ∂ z i / ∂ x j = W ij .
J σ = ∂ a ∂ z = diag ( σ ′ ( z 1 ) , … , σ ′ ( z m ) ) J_{\sigma}=\dfrac{\partial \mathbf{a}}{\partial \mathbf{z}}=\operatorname{diag}\big(\sigma'(z_1),\dots,\sigma'(z_m)\big) J σ = ∂ z ∂ a = diag ( σ ′ ( z 1 ) , … , σ ′ ( z m ) ) . Why? a i = σ ( z i ) a_i=\sigma(z_i) a i = σ ( z i ) depends only on z i z_i z i , so off-diagonal partials vanish — a diagonal Jacobian.
Full map x ↦ a \mathbf{x}\mapsto\mathbf{a} x ↦ a : J = J σ J z = diag ( σ ′ ( z ) ) W . J = J_\sigma J_{\mathbf{z}} = \operatorname{diag}(\sigma'(\mathbf{z}))\,W. J = J σ J z = diag ( σ ′ ( z )) W .
Why this matters: this product-of-Jacobians is forward-mode differentiation of a neural net.
Worked example Example 3 — polar → Cartesian & the determinant
f ( r , θ ) = ( r cos θ , r sin θ ) \mathbf{f}(r,\theta)=(r\cos\theta,\ r\sin\theta) f ( r , θ ) = ( r cos θ , r sin θ ) .
J = [ cos θ − r sin θ sin θ r cos θ ] , det J = r cos 2 θ + r sin 2 θ = r . J=\begin{bmatrix}\cos\theta & -r\sin\theta\\ \sin\theta & r\cos\theta\end{bmatrix},\quad \det J = r\cos^2\theta + r\sin^2\theta = r. J = [ cos θ sin θ − r sin θ r cos θ ] , det J = r cos 2 θ + r sin 2 θ = r .
Why the determinant? For a square Jacobian, ∣ det J ∣ |\det J| ∣ det J ∣ is the local area/volume scaling factor — how much a tiny patch expands under f \mathbf f f . That's exactly the r d r d θ r\,dr\,d\theta r d r d θ factor in polar integration.
Common mistake "Jacobian and gradient are the same thing."
Why it feels right: for a scalar function they carry identical numbers. The fix: the gradient ∇ f \nabla f ∇ f is a column vector; for m = 1 m=1 m = 1 the Jacobian is its transpose (a row). More importantly, "gradient" only makes sense when output is scalar (m = 1 m=1 m = 1 ); for m > 1 m>1 m > 1 there is no single gradient, only a Jacobian.
Common mistake "The Jacobian is
n × m n\times m n × m ."
Why it feels right: people write inputs first out of habit. The fix: it's m × n m\times n m × n — rows = outputs, columns = inputs — because it must map R n → R m \mathbb R^n\to\mathbb R^m R n → R m : J h J\mathbf h J h needs h ∈ R n \mathbf h\in\mathbb R^n h ∈ R n on the right.
Common mistake "Chain rule for Jacobians is
J f J g J_f J_g J f J g ."
Why it feels right: scalar chain rule d h d x = d h d g d g d x \frac{dh}{dx}=\frac{dh}{dg}\frac{dg}{dx} d x d h = d g d h d x d g looks order-free. The fix: matrix multiplication is NOT commutative. For h = g ∘ f \mathbf h=\mathbf g\circ\mathbf f h = g ∘ f , apply outer function's Jacobian on the left : J h = J g J f J_{\mathbf h}=J_{\mathbf g}\,J_{\mathbf f} J h = J g J f . The shapes only fit in that order.
det J \det J det J exists for any Jacobian."
Why it feels right: we take determinants all the time. The fix: determinant needs a square matrix, i.e. m = n m=n m = n . For non-square J J J (most ML layers) there is no determinant.
Recall Feynman: explain it to a 12-year-old
Imagine a machine that takes a few dials as input and lights up a few bulbs as output. If you nudge one dial a tiny bit, each bulb gets a little brighter or dimmer. The Jacobian is just the table of all those "how much brighter per nudge" numbers — one number for each (bulb, dial) pair. If you know this table, you can predict what happens for any small twist of the dials without running the machine: just multiply your twist by the table.
"ROC — Rows are Outputs, Columns are inputs." And: gradient stacks into Jacobian — stack the gradient-rows of each output.
What is the shape of the Jacobian of f : R n → R m \mathbf f:\mathbb R^n\to\mathbb R^m f : R n → R m ? m × n m\times n m × n — rows = outputs, columns = inputs.
Define the ( i , j ) (i,j) ( i , j ) entry of the Jacobian. J i j = ∂ f i / ∂ x j J_{ij}=\partial f_i/\partial x_j J ij = ∂ f i / ∂ x j .
What is row i i i of the Jacobian? The transpose of the gradient of output
f i f_i f i , i.e.
( ∇ f i ) ⊤ (\nabla f_i)^\top ( ∇ f i ) ⊤ .
For a scalar function (m = 1 m=1 m = 1 ), how do Jacobian and gradient relate? The Jacobian is a row vector equal to
( ∇ f ) ⊤ (\nabla f)^\top ( ∇ f ) ⊤ ; the gradient is its transpose (a column).
State the first-order linear approximation using the Jacobian. f ( x + h ) ≈ f ( x ) + J h \mathbf f(\mathbf x+\mathbf h)\approx \mathbf f(\mathbf x)+J\mathbf h f ( x + h ) ≈ f ( x ) + J h .
Chain rule for h = g ∘ f \mathbf h=\mathbf g\circ\mathbf f h = g ∘ f in Jacobian form? J h = J g J f J_{\mathbf h}=J_{\mathbf g}\,J_{\mathbf f} J h = J g J f (outer on the left; order matters).
What does ∣ det J ∣ |\det J| ∣ det J ∣ mean, and when is it defined? Local volume-scaling factor of the map; defined only when
J J J is square (
m = n m=n m = n ).
Jacobian of z = W x \mathbf z=W\mathbf x z = W x w.r.t. x \mathbf x x ? Jacobian of elementwise a = σ ( z ) \mathbf a=\sigma(\mathbf z) a = σ ( z ) w.r.t. z \mathbf z z ? diag ( σ ′ ( z 1 ) , … , σ ′ ( z m ) ) \operatorname{diag}(\sigma'(z_1),\dots,\sigma'(z_m)) diag ( σ ′ ( z 1 ) , … , σ ′ ( z m )) .
det J \det J det J for polar map ( r cos θ , r sin θ ) (r\cos\theta,r\sin\theta) ( r cos θ , r sin θ ) ?
Scalar derivative f prime x
Vector function f R^n to R^m
Partial derivatives dfi dxj
Column j is input xj response
Linear approximation requirement
Per-output first order expansion
Row times h equals grad fi dot h
ML backprop and optimization
Intuition Hinglish mein samjho
Dekho, ek normal function f ( x ) f(x) f ( x ) ka toh sirf ek derivative hota hai — ek number jo slope batata hai. Lekin ML me functions aksar vector in, vector out hote hain: n n n inputs andar jaate hain, m m m outputs bahar aate hain. Ab ek slope se kaam nahi chalega — humein har (output, input) pair ke liye ek partial derivative chahiye. In sab partials ki jo table banti hai, wahi hai Jacobian matrix , size m × n m \times n m × n (rows = outputs, columns = inputs — yaad rakho "ROC").
Iska asli funda ye hai: Jacobian function ka best linear approximation hai kisi point ke aas-paas. Matlab f ( x + h ) ≈ f ( x ) + J h \mathbf{f}(\mathbf{x}+\mathbf{h}) \approx \mathbf{f}(\mathbf{x}) + J\mathbf{h} f ( x + h ) ≈ f ( x ) + J h . Jaise scalar case me f ( x + h ) ≈ f ( x ) + f ′ ( x ) h f(x+h)\approx f(x)+f'(x)h f ( x + h ) ≈ f ( x ) + f ′ ( x ) h , waise hi yahan f ′ f' f ′ ki jagah matrix J J J aa gaya. Har row actually ek output ka gradient hai — bas sab gradients ko upar-neeche stack kar do, Jacobian ban gaya.
ML me iski importance? Backpropagation basically Jacobians ka multiplication hi hai. Linear layer z = W x \mathbf{z}=W\mathbf{x} z = W x ka Jacobian seedha W W W hai, aur elementwise activation σ \sigma σ ka Jacobian ek diagonal matrix diag ( σ ′ ( z i ) ) \operatorname{diag}(\sigma'(z_i)) diag ( σ ′ ( z i )) hai. Chain rule ka matlab hai in Jacobians ko multiply karo — lekin dhyan rakho, order matter karta hai: outer function ka Jacobian left me aata hai, J g J f J_{\mathbf g} J_{\mathbf f} J g J f .
Do galtiyan jo sab karte hain: (1) Jacobian ko gradient samajh lena — gradient toh sirf scalar output (m = 1 m=1 m = 1 ) ke liye hota hai, aur wo Jacobian ka transpose hai. (2) Determinant har jagah lagana — det J \det J det J sirf tab valid hai jab matrix square ho (m = n m=n m = n ), aur tab ∣ det J ∣ |\det J| ∣ det J ∣ batata hai ki chhota sa area/volume kitna stretch hua.