How does Andrej Karpathy use learning rate decay in training neural networks?

Andrej Karpathy says learning rate decay is used to start with a high learning rate and then shrink it as training progresses. The point is to move quickly early on, then slow down near the end when the network is stabilizing so it can pick up finer details. He presents it as a practical training trick in a slightly more advanced binary classification example.

“You'll notice that in the update here, the learning rate is scaled as a function of number of iterations, and it shrinks. This is something called learning rate decay. So, in the beginning, you have a high learning rate, and as the network sort of stabilizes near the end, you bring down the learning rate to get some of the fine details in the end. And in the end, we see the decision surface of the neural net, and we see that it learns to separate out the red and the blue area based on the data points.”
— Andrej Karpathy, Educational talk, 2021-11 · at 2:20:32
Andrej Karpathy: Andrej Karpathy on Neural Networks: Building Micrograd

Key takeaways

  • Use a larger learning rate early in training.
  • Reduce the learning rate later to refine the solution.
  • Training often benefits from different settings at different phases.

Context

In the final part of his 2021 micrograd lecture, Karpathy compares the toy example to a more realistic batched classification demo. The quote above is taken word for word from the recording's transcript.

In the transcript

…and don't make too much of a difference in the simple examples that we looked at so far. There's something called L2 regularization used here. This has to do with generalization of the neural net and controls the overfitting in machine learning setting, but I did not cover these concepts and concepts in this video, potentially later. And the training loop you should recognize: so forward, backward with zero grad.

You'll notice that in the update here, the learning rate is scaled as a function of number of iterations, and it shrinks. This is something called learning rate decay. So, in the beginning, you have a high learning rate, and as the network sort of stabilizes near the end, you bring down the learning rate to get some of the fine details in the end. And in the end, we see the decision surface of the neural net, and we see that it learns to separate out the red and the blue area based on the data points.

Uh, so in particular, I wanted to show—I wanted to find and show you the backward pass for tanh in PyTorch. So here in micrograd, we see that the backward pass for tanh is one minus t squared, where t is the output of the tanh of x, times that grad, which is the chain rule. So, we're looking for something that looks like this. Now, I went to PyTorch,…

Read the full transcript of Educational talk, 2021-11

Topics

What others said about neural networks

More questions about Andrej Karpathy

All Andrej Karpathy answers · All Andrej Karpathy recordings

How this answer was made: the quote is checked word for word against the transcript of the recording and confirmed as the speaker's own words; the summary above it was drafted with AI from that transcript and quality-checked. Methodology and corrections.

Search every transcript
Open the full search page →