Gradients
A gradient collects partial derivatives into a vector.
For a function:
the gradient is:
At (3, 4), this becomes:
Meaning
The gradient points in the direction where the function increases fastest.
The negative gradient points in the direction where the function decreases fastest.
This is why gradient descent uses:
The symbol eta is the learning rate.
The minus sign matters. The gradient points uphill for the loss. Gradient descent moves in the opposite direction because training tries to reduce the loss.
The gradient is not automatically the update. The optimizer chooses how to use it. Plain gradient descent uses the negative gradient scaled by a learning rate, but later methods may rescale, average, clip, or adapt that signal.
Gradient as a Vector
Since the gradient is a vector, earlier vector ideas apply:
- direction matters
- length matters
- scaling changes the step size
- dot products can measure directional change
The length of the gradient tells how sensitive the function is locally. A long gradient means a small movement can change the function a lot. A zero gradient means the first-order local signal is flat.
ML Reading
If a loss depends on many weights, the gradient has one component per weight.
Each component answers a local question:
If this weight changes slightly, while the others are held fixed for this measurement, how does the loss change?
Let f(x, y) = x^2 + y^2.
What is grad f(3, 4)?
Compute it first, then check your number.
Hint
Use [2x, 2y].
Solution
The gradient formula is [2x, 2y]. Substitute x = 3 and y = 4:
grad f(3, 4)
= [2(3), 2(4)]
= [6, 8]
The two entries are the local sensitivities in the x and y directions.
If grad L(w) = [6, 8], which direction does gradient descent move before
scaling by the learning rate?
Compute it first, then check your number.
Hint
Gradient descent uses the negative gradient.
Solution
The gradient points uphill for the loss. Plain gradient descent moves in the opposite direction before applying the learning rate:
-[6, 8] = [-6, -8]
So the unscaled descent direction is [-6, -8].
If grad L = [2, -5], which weight has the larger local sensitivity by
magnitude: the first or second?
Answer it first, then check.
Hint
Compare absolute values, not signs.
Solution
The second component has magnitude 5, while the first has magnitude 2, so
the second weight has the larger local sensitivity.
If grad f = [0, 0], does the first-order local signal point uphill in any
direction?
Answer it first, then check.
Hint
A zero vector has no direction.
Solution
No. A zero gradient means the first-order local slope is flat in every direction, though later optimization chapters will discuss what that can mean.
Enter 1 if the gradient is the local uphill sensitivity signal, while a
descent update usually moves in the negative-gradient direction.
Compute it first, then check your number.
Hint
Ask whether training wants to increase or decrease the loss.
Solution
Enter 1. The gradient points toward steepest local increase. To reduce loss,
plain gradient descent moves in the opposite direction.
Before Moving On
A gradient is the vector form of local sensitivity.