§ Gradients · Interactive Graduate Primer
Tensor by Tensor · expanded

The gradient vector

Learn how changing several inputs changes one output. Begin with partial derivatives, then explore gradient descent, backpropagation, and optimizers. The later sections include proofs and deeper mathematical detail.
A first reading path

Start with sections 2–4, then section 7. Return to the directional-derivative proof after you understand a gradient-descent update. An optimizer is a rule for updating the model’s adjustable numbers.

For L(a, b) = a² + 2b², the gradient at (1, 2) is [2, 8]. The first entry measures change along a while b stays fixed. The second measures change along b while a stays fixed. With step size 0.1, subtract [0.2, 0.8] to reach (0.8, 1.2). The loss falls from 9 to 3.52.

Check: why subtract the gradient?

The gradient points toward the steepest local increase under the usual Euclidean length measure. Subtracting it moves toward a local decrease when the step is small enough. A large step can still overshoot and increase the loss.

4. The Gradient

Introduction

At the point 2, 1, a two-input function has partial derivatives 4 and 3. Collecting them gives gradient 4, 3, a vector of length 5 that summarizes the local slope.

Learning goal

Build a gradient from partial derivatives and read its direction, magnitude, and field across points.

Before you start

Partial derivatives, two-dimensional vectors, vector length calculations, and reading simple coordinate plots.

Lesson plan

  1. Calculate one partial derivative for each input at the same point.
  2. Collect the values into a gradient and calculate its length.
  3. Use the field explorer to compare gradient vectors across the surface.

The gradient collects one partial derivative per input. For the same function at (2,1), it is [4,3]. The vector's shape matches the input shape because it gives one local sensitivity for each input coordinate.

Definition
$$\nabla f(x) = \begin{bmatrix}\partial_1 f(x)\\\vdots\\\partial_n f(x)\end{bmatrix} \in \mathbb{R}^n.$$

The map $x \mapsto \nabla f(x)$ is a vector field. Two geometric facts follow from the formalism in §6: the gradient is orthogonal to level sets, and it points in the direction of steepest local increase with magnitude equal to that rate.

4.1 Gradient field explorer

The canvas below draws level curves of $f(x,y)=(x-1)^2+4(y+2)^2$ and the gradient vector field. Hover (or drag) to read off the gradient and its magnitude at any point.

Interactive · Gradient field with hover inspection
Move the pointer over the canvas.
Level curves Gradient vector ∇ at hover