3.2.2 · D1Training Deep Networks

Foundations — Mini-batch gradient descent

2,122 words10 min readBack to topic

This page assumes nothing. Every letter, arrow, and squiggle in the parent note is built here from the ground up, each one leaning on the one before it. Read top to bottom.


0. What is a "model" and what are its "settings"?

Before any math, a picture of what we are even adjusting.

A neural network is a machine: you feed in some input (say the pixels of a photo) and it produces an output (say "cat" or "dog"). Between input and output sit a large pile of numbers — the knobs. Turn the knobs and the machine's behaviour changes. Training = turning the knobs until the machine is usually right.

Figure — Mini-batch gradient descent

Why the topic needs : everything in training is about changing . It is the variable we optimise. We write (theta as a subscript) to say "the guess depends on the knobs."


1. Measuring a single mistake: the loss

We can only improve if we can measure how wrong we are. That measurement is called the loss.

Figure — Mini-batch gradient descent

We often shorten to just — "the loss on example ."


2. Summation and average: the total objective

We don't care about one example; we care about all of them. That needs a way to add many things.

To turn a total into an average, divide by how many there are:

Why the topic needs : is the mountain we are trying to walk down. Its height at position is "how wrong the model is overall." Training = find the valley bottom of .


3. A landscape you can walk on: gradient

Now the key move. depends on the knobs , so imagine as a location and as the altitude there. Training is descending this landscape. To descend, we need to know which way is downhill. That direction-finder is the gradient.

Figure — Mini-batch gradient descent

4. The step: learning rate and the update rule

Knowing the downhill direction, we take a step. How big a step? That is the learning rate.

Figure — Mini-batch gradient descent

5. Randomness: sample, mean, variance

Mini-batch GD estimates the true average gradient from a random pile. To reason about "estimate" we need three ideas from probability.


6. Time and passes: epoch


Prerequisite map

Model f and knobs theta

Loss ell of one example

Sum and average gives objective J

Gradient nabla J points downhill

Update rule with learning rate eta

Random sample batch B of size m

Expectation and variance

Per example gradient g i

Batch estimator g B

Mini batch gradient descent

Read it as: knobs and loss build the objective ; gives a gradient; the gradient plus a step size gives the update rule; sampling plus expectation/variance turn the full gradient into a batch estimate; both streams meet at mini-batch GD.


Equipment checklist

Hide the answers, say each out loud, then reveal.

What does stand for and what picture goes with it?
The bundle of all adjustable knob-settings inside the model; picture a giant list of numbers we turn during training.
What does mean?
The model , set up with knobs , applied to input — i.e. the model's guess for .
What is and why is it a number, not a yes/no?
The loss (wrongness) on example ; a smooth number tells us how wrong and hence which way to improve, which yes/no cannot.
Expand in words.
Add up the losses of examples 1 through N into one bucket.
Why divide the total loss by to get ?
To make it an average, so the value doesn't secretly grow just because the dataset is bigger.
What does the gradient point toward, and which way do we walk?
Toward steepest uphill of the loss; we step the opposite (downhill) direction.
In , what are and the minus sign doing?
is the stride length (learning rate); the minus makes us step downhill, against the uphill gradient.
What is a mini-batch and what does tell you?
A small random handful of examples; says the batch is orders of magnitude smaller than the whole dataset.
What do and measure?
Expectation = long-run average of a random quantity; variance = how much it spreads around that average.
What is one epoch, and how many steps does it contain?
One full pass over all examples; it contains batch updates.

Connections