Choosing the Learning Rate and Momentum, and Line Search
On this page 7 headings
Try three learning rates on the same gradient
Again use L(w) = ½w², current w = 2 and gradient 2. Compare candidate steps from the same starting point.
A small rate improves the loss.
This candidate reaches the minimum for this particular quadratic.
Too large a rate overshoots and worsens the loss.
What changed? A trial-based line search compares candidate losses. Rate 1 wins here; that does not make it a universally good learning rate.
Quick check: Would you choose η = 3 for this step?
No. It raises the loss from 2 to 8.
Swipe long formulas, tables or code sideways to see the rest.
Start here The learning rate decides how big every step is. Too small and training crawls; too big and it jumps around wildly. This page gives practical tips to pick , ways to shrink it over time (annealing), a schedule for momentum, and line search — trying several at every step.
Idea: gentle slopes give tiny gradients, so multiply them by a large to make the steps bigger.
Lecture example — On gentle regions this helps. But on steep regions, the already large gradient is blown up even more. The parameters jump far past the minimum and the loss jumps around.
What we’d like is a learning rate that adjusts itself to the gradient — big where the slope is gentle, small where it is steep. Such adaptive algorithms come next in the course (AdaGrad, RMSProp, Adam).
- Tune on a log scale: try 0.0001, 0.001, 0.01, 0.1, 1.0.
- Run a few epochs with each; find the one that works best.
- Do a finer search around it. If 0.1 was best, now try 0.05, 0.2, 0.3.
Disclaimer from the lecture: these are heuristics — there is no clear winning strategy.
Start with a reasonable and reduce it as training goes on.
Step decay
- Halve the learning rate after every 5 epochs, or
- Halve it after an epoch if the validation error is higher than it was at the end of the previous epoch.
Exponential decay , where and k are hyperparameters and t is the step number.
(The slide prints this as “”; the standard exponential decay formula is .)
1/t decay , where and k are hyperparameters and t is the step number.
Worked numbers
t Exponential 1/t decay Step decay (halve every 5) 0 0.1 0.1 0.1 1 0.1 5 0.05 10 0.025
A schedule suggested by Sutskever et al., 2013:
where is chosen from {0.999, 0.995, 0.99, 0.9, 0}.
What it does: starts at 0.5 and grows every 250 steps:
| t | ⌊t/250⌋ + 1 | (before the min) |
|---|---|---|
| 0–249 | 1 | |
| 250–499 | 2 | |
| 500–749 | 3 | |
| 750–999 | 4 | |
| 1000–1249 | 5 |
So momentum is small at the start (careful) and larger later (confident), capped at .
In practice a line search is often done to find a better at each step.
def do_line_search_gradient_descent(max_epochs):
w, b, etas = -2, -2, [0.1, 0.5, 1, 2, 10]
for i in range(max_epochs):
dw, db = 0, 0
for x, y in zip(X, Y):
dw += grad_w(w, b, x, y)
db += grad_b(w, b, x, y)
min_error = 10000 # some large value
for eta in etas: # try every candidate
temp_w = w - eta * dw
temp_b = b - eta * db
if error(temp_w, temp_b) < min_error:
best_w, best_b = temp_w, temp_b
min_error = error(best_w, best_b)
w, b = best_w, best_b # keep the best one- Update w using different values of .
- Keep the updated value that gives the lowest loss.
- So at each step we use the best from the available choices.
Worked numbers (first step from , lecture data; checked in code) Loss after the step: 0.41488. Line search keeps here, because we start on a very flat region.
Plus: convergence is faster than vanilla gradient descent with a fixed . Minus: many more computations in each step (one loss evaluation per candidate ).
Lecture example — line search in action Blue: gradient descent with fixed . Black: gradient descent with line search. Line search converges faster. It shows some oscillations too, but these are different from momentum/NAG oscillations — they come from picking when it happens to give the lowest loss for that one step.
In one line: Tune on a log scale, shrink it over time (step, exponential or 1/t decay), grow momentum over time, or use line search to pick the best at every step at extra cost.
Exam words: learning rate, log-scale search, annealing, step decay, exponential decay, 1/t decay, hyperparameter, validation error, Sutskever momentum schedule, , line search.
