Learning and architectures / 5 of 7

Gradient descent in practice

8 minOpening your notebook…

What you’ll learn

  • Explain the main idea of “Gradient descent in practice” in your own words.
  • Trace a concrete example and identify the assumptions behind it.
  • Apply the principle in a practice problem and recognize a common failure.

The idea, intuitively

Training often uses minibatches to estimate gradients from a subset of examples. This is cheaper than processing the entire dataset for every update, but introduces noise into the optimization trajectory.

Treat a neural network as a computation graph, not a mysterious black box. Follow a tiny input through each operation and keep track of tensor shapes. Distinguish the forward pass, gradient computation, and optimizer update. These three stages are connected but solve different parts of the learning problem.

Under the hood

Stochastic gradient descent subtracts a scaled gradient. Momentum accumulates directional history. Adaptive methods rescale updates per parameter. Learning-rate schedules and gradient clipping can improve stability.

wt+1=wt−ηgtw_{t+1}=w_t-\eta g_t
gₜ is the gradient used at step t. The rate η scales how far to move in the opposite direction.
A useful caution

An epoch is a pass through the training data; it is not the same as one optimizer step.

A worked example

For a quadratic bowl, a small rate approaches the minimum smoothly. A high rate crosses the valley repeatedly and can move farther away.

How to use this way of thinking

Build intuition with a small calculation before scaling dimensions. Check whether the architecture can represent the desired relationship, then whether optimization can learn it, then whether the learned solution generalizes. A failure in any one of these stages needs a different response.

See the mechanism

Educational simulationRuns in your browser with simplified rules and example settings.
Try this

Start at −3. Take a step at 0.5, then take several steps at 1.1. Compare the loss in the two runs and use the step history to explain the difference.

Opening the experiment…

Try it yourself

With 1,000 examples and batch size 100, how many full-batch updates occur in one epoch?

Key takeaways

  • The gradient of the data objective
  • An epoch is a pass through the training data; it is not the same as one optimizer step.
  • Check the assumptions with a small example before applying this idea to a larger system.

Check your understanding

0/2 checked

Use feedback to learn. Quiz scores and lesson completion are tracked separately.

1What does a minibatch gradient approximate?
2True or false: One epoch always equals one optimizer step.
Go to lesson completion

Further reading

Original papers and reference material for this school. External resources may be in English and require internet access.

Dive into Deep Learning (opens a new tab)PyTorch: automatic differentiation (opens a new tab)

Finish this lesson

Mark this lesson complete when you’re ready to continue.

Start with a question

Introduction to AIAI FoundationsA brief history of AIAI FoundationsTypes of AIAI FoundationsAI, ML, and deep learningAI FoundationsUnderstanding generative AIAI FoundationsEthics, limitations, and responsibilityAI FoundationsLinear algebra for learning systemsMathematics for AIVectors, matrices, and similarityMathematics for AICalculus: measuring changeMathematics for AIDerivatives and gradientsMathematics for AIProbability and statisticsMathematics for AIOptimization and objectivesMathematics for AI
K to open · Escape to close