← All Posts
Deep Learning · OptimizersChapter 00 · Refresher

Taylor Series Refresher: Descent Directions and Contour Tangents

Review the 1D and multivariate Taylor expansions, and use the Taylor formula to prove why the negative gradient is a descent direction and why the gradient is perpendicular to the contour tangent.

Every gradient-based optimizer in deep learning rests on one local approximation: if you nudge the parameters $w$ by a small step $\Delta w$, how does the loss $L(w+\Delta w)$ change? The Taylor series expansion answers that question and directly proves two geometric facts used across the entire series: why $-\nabla L(w)$ is a descent direction, and why $\nabla L(w)$ meets every constant-loss contour at a $90^\circ$ angle.

1. The 1D Taylor expansion: local height, slope, and curvature

For a smooth single-variable loss $L(w)$, the Taylor expansion around the current weight $w$ approximates the loss after a step $\Delta w$ as a sum of powers of $\Delta w$:

$$L(w+\Delta w)=\underbrace{L(w)}_{\text{current loss}}+\underbrace{L'(w)\,\Delta w}_{\text{1st-order (linear slope)}}+\underbrace{\frac{1}{2}L''(w)\,(\Delta w)^2}_{\text{2nd-order (curvature)}}+\underbrace{\mathcal{O}\bigl((\Delta w)^3\bigr)}_{\text{higher-order terms}}.$$

Subtracting $L(w)$ from both sides isolates the change in loss $\Delta L = L(w+\Delta w)-L(w)$:

$$\Delta L=L(w+\Delta w)-L(w)=L'(w)\,\Delta w+\frac{1}{2}L''(w)\,(\Delta w)^2+\mathcal{O}\bigl((\Delta w)^3\bigr).$$

When the step $\Delta w$ is small (for example, $|\Delta w|=10^{-3}$), its square $(\Delta w)^2=10^{-6}$ is a thousand times smaller than $|\Delta w|$. Grouping the squared and higher powers into $\mathcal{O}\bigl((\Delta w)^2\bigr)$ leaves the first-order Taylor approximation:

$$\Delta L=L(w+\Delta w)-L(w)=L'(w)\,\Delta w+\mathcal{O}\bigl((\Delta w)^2\bigr)\approx L'(w)\,\Delta w.$$

Worked 1D check: Let $L(w)=w^2$ at $w=3$ (so $L(3)=9$, slope $L'(3)=2(3)=6$, curvature $L''(3)=2$) and take a small step $\Delta w=-0.1$ to $w+\Delta w=2.9$:

$$\begin{aligned}\text{Exact change:}\quad \Delta L&=L(2.9)-L(3)=8.41-9.00=-0.59,\\[4pt]\text{Taylor terms:}\quad \Delta L&=\underbrace{6(-0.1)}_{\text{1st-order }=-0.60}+\underbrace{\frac{1}{2}(2)(-0.1)^2}_{\text{2nd-order }=+0.01}=-0.59.\end{aligned}$$

2. Multivariate Taylor expansion for $d$ parameters

In a neural network, $w=(w_1,\dots,w_d)^\top\in\mathbb{R}^d$ is a column vector of $d$ parameters and $\Delta w=(\Delta w_1,\dots,\Delta w_d)^\top\in\mathbb{R}^d$ is the parameter update vector:

Expanding $L(w+\Delta w)$ around $w$ adds each coordinate’s linear slope contribution $\frac{\partial L}{\partial w_j}\Delta w_j$, which writes compactly as the dot product $\nabla L(w)^\top\Delta w$:

$$\begin{aligned}L(w+\Delta w)&=L(w)+\sum_{j=1}^d\frac{\partial L}{\partial w_j}\Delta w_j+\frac{1}{2}\Delta w^\top H\,\Delta w+\mathcal{O}(\|\Delta w\|^3)\\[4pt]&=L(w)+\nabla L(w)^\top\Delta w+\frac{1}{2}\Delta w^\top H\,\Delta w+\mathcal{O}(\|\Delta w\|^3).\end{aligned}$$

Subtracting $L(w)$ gives the fundamental multivariate Taylor change formula:

$$\Delta L=L(w+\Delta w)-L(w)=\nabla L(w)^\top\Delta w+\mathcal{O}(\|\Delta w\|^2).$$

3. Why the negative gradient $-\nabla L(w)$ is a descent direction

A direction vector $d\in\mathbb{R}^d$ is called a descent direction at $w$ if moving a small step $\Delta w=\eta d$ (with learning rate $\eta>0$) strictly decreases the loss: $L(w+\eta d)<L(w)$, or $\Delta L<0$.

Plugging $\Delta w=\eta d$ into the Taylor expansion formula gives:

$$\Delta L=L(w+\eta d)-L(w)=\eta\,\nabla L(w)^\top d+\mathcal{O}(\eta^2).$$

When $\eta>0$ is sufficiently small, $\mathcal{O}(\eta^2)$ is negligible compared to $\eta$, so the sign of $\Delta L$ is completely determined by the dot product $\nabla L(w)^\top d$:

$$\nabla L(w)^\top d<0\implies L(w+\eta d)<L(w)\quad(\text{for small }\eta>0).$$

Now substitute the negative gradient $d=-\nabla L(w)$ (so $\Delta w=-\eta\nabla L(w)$) into the Taylor expansion. We get two results at once—an algebraic proof that $-\nabla L(w)$ is always a descent direction whenever $\nabla L(w)\ne 0$, and a geometric proof via the angle $\theta$ between $\nabla L(w)$ and $d$ that it is the steepest descent direction:

$$\begin{aligned}\text{1. Algebraic proof (sum of squares):}\quad \Delta L&=L\bigl(w-\eta\nabla L(w)\bigr)-L(w)\\&=\nabla L(w)^\top\bigl(-\eta\nabla L(w)\bigr)+\mathcal{O}(\eta^2)\\&=-\eta\sum_{j=1}^d\underbrace{\left(\frac{\partial L}{\partial w_j}\right)^2}_{\ge\,0}+\mathcal{O}(\eta^2)\\&=-\eta\|\nabla L(w)\|^2+\mathcal{O}(\eta^2)<0\quad\bigl(\text{for }\nabla L(w)\ne 0\text{ and small }\eta>0\bigr),\\[10pt]\text{2. Geometric proof (dot-product angle $\theta$):}\quad \Delta L&\approx\eta\,\nabla L(w)^\top d=\eta\,\|\nabla L(w)\|\,\|d\|\underbrace{\cos\theta}_{\text{min }=-1\text{ at }\theta=180^\circ}.\end{aligned}$$

4. Using the Taylor formula to prove $\nabla L(w)$ is perpendicular to the contour tangent

A contour line (or level set) of the loss is the set of parameter points that share the exact same loss value:

$$\text{Contour through }w:\quad L(w)=c\quad(\text{constant}).$$

Let $t\in\mathbb{R}^d$ be a unit tangent vector to the contour at $w$. If we take an infinitesimal step $\Delta w=\epsilon t$ of length $\epsilon$ along the contour tangent, we remain on the contour to first order, which means the loss does not change ($\Delta L=0$). Plugging $\Delta w=\epsilon t$ into the multivariate Taylor expansion proves that $\nabla L(w)$ and $t$ must meet at $90^\circ$:

$$\begin{aligned}\Delta L=L(w+\epsilon t)-L(w)&=\epsilon\,\nabla L(w)^\top t+\mathcal{O}(\epsilon^2)=0\\[6pt]\implies\lim_{\epsilon\to 0}\frac{L(w+\epsilon t)-L(w)}{\epsilon}&=\nabla L(w)^\top t=0\\[6pt]\implies\|\nabla L(w)\|\,\|t\|\cos\theta&=0\implies\cos\theta=0\implies\theta=90^\circ.\end{aligned}$$

Because $\nabla L(w)^\top t=0$ for every tangent vector $t$ to the contour at $w$, both the gradient $\nabla L(w)$ (pointing uphill, $\theta=0^\circ$) and the negative gradient $-\nabla L(w)$ (pointing downhill, $\theta=180^\circ$) are always perpendicular ($90^\circ$) to the contour tangent $t$.

At any point w on a constant-loss contour L(w) = constant, the gradient vector nabla L(w) and the contour tangent vector t satisfy nabla L(w)^T t = 0, so they meet at a 90-degree angle.
Scroll the figure horizontally on small screens.
Plugging a contour-tangent step $\Delta w=\epsilon t$ into the Taylor expansion $\Delta L=\epsilon\,\nabla L(w)^\top t+\mathcal{O}(\epsilon^2)=0$ forces $\nabla L(w)^\top t=0$, so $\nabla L(w)$ and $-\eta\nabla L(w)$ are perpendicular ($90^\circ$) to the contour tangent $t$.

Worked 2D check: Consider the elliptical bowl $L(w_1,w_2)=w_1^2+2w_2^2$ at the point $w=(2,1)^\top$, which lies on the contour $L(w)=2^2+2(1)^2=6$. Parameterize a curve $w(\epsilon)=(2-\epsilon,\,1+\epsilon)^\top$ passing through $(2,1)^\top$ at $\epsilon=0$ with tangent vector $t=w'(0)=[-1,\,1]^\top$:

$$\begin{aligned}\text{1. Loss along }w(\epsilon):&\quad L(2-\epsilon,\,1+\epsilon)=(2-\epsilon)^2+2(1+\epsilon)^2=6+\underbrace{0\cdot\epsilon}_{\text{1st-order }=0}+3\epsilon^2,\\[4pt]\text{2. Gradient at }(2,1):&\quad \nabla L(w)=\begin{bmatrix}2w_1\\4w_2\end{bmatrix}_{(2,1)}=\begin{bmatrix}4\\4\end{bmatrix},\\[4pt]\text{3. Taylor dot product:}&\quad \nabla L(w)^\top t=\begin{bmatrix}4&4\end{bmatrix}\begin{bmatrix}-1\\1\end{bmatrix}=4(-1)+4(1)=0\implies\theta=90^\circ.\end{aligned}$$