§ Gradients · Interactive Graduate Primer
Tensor by Tensor · expanded

Beyond gradient descent

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.

13. Gradients Beyond Supervised Training

Introduction

Gradients are not limited to fitting labels. They can change an input for an adversarial example, follow a diffusion score, improve a policy from reward, or differentiate through another learning step.

Learning goal

Identify and explain what quantity is differentiated in four learning settings beyond ordinary supervised model training.

Before you start

Gradients, loss functions, probability as a concept, and the basic supervised-training loop.

Lesson plan

  1. Follow an input gradient used to construct a fast adversarial perturbation.
  2. Compare score and reward gradients in diffusion and policy optimization.
  3. See why meta-learning may require a gradient through an earlier gradient update.

The supervised label is not required. What matters is a differentiable scalar objective. Language-model loss, reconstruction loss, and policy objectives define different goals, but each still supplies a local signal for parameters.

  • Adversarial examples. FGSM perturbs inputs by $\varepsilon\cdot\text{sign}(\nabla_x L)$.
  • Saliency and attribution. $\|\nabla_x L\|$ (or Integrated Gradients) identifies influential inputs.
  • Diffusion models. A score network approximates $\nabla_x\log p(x)$; samples are drawn by Langevin dynamics.
  • Reinforcement learning. The policy-gradient theorem: $\nabla_\theta J=\mathbb{E}[\nabla_\theta\log\pi_\theta(a|s)\,R]$.
  • Meta-learning (MAML). Gradients of gradients through an inner training step.
  • Natural gradient. Replace the Euclidean metric with the Fisher information: $\theta\leftarrow\theta-\eta F^{-1}\nabla L$. Basis of K-FAC.