explain this in plain english: Making better use of gradients We now know several ways…
- User
explain this in plain english:
Making better use of gradients We now know several ways to alter the learning rate η to improve how quickly our model learns and allow it to learn more accurate solutions. We did this by defining different learning rate schedules L(·; ·), which look at the long term. Think of L(·; ·) as setting the desired speed for the journey. But detours, potholes, and other obstacles in the short term may require a change in speed. This is why we also want to modify the gradient g with a function G(·). We focus on gradient update schemes on their own first and then combine them with learning rate schedules to get improved results. First, we talk about some broad motivations and then dive into the most common approaches. All three approaches are one-line changes to your code with PyTorch (they are built in) and can dramatically improve the accuracy of your models. Remember that we are using gt to indicate the tth gradient that we are receiving to update the network. Because we are doing stochastic gradient descent in batches, this is a noisy gradient. Even with the noise in gt, there is valuable information in gt that we are not fully utilizing. Consider the jth parameter’s gradient gt j. What if it’s consistently almost the same value every time? Mathematically, that would be a situation where gt j ≈ gt j−1 ≈ gt j−2 ≈ gt j−3 ≈ : : : This tells us the jth parameter needs to be moved in the same direction each time. Figure 5.11 shows such a situation. We don’t necessarily want to increase the learning rate η, because other dimensions may have different behavior. Every network parameter gets its own gradient value, and networks can have millions of parameters. So if the gradient at index j is consistently the same, maybe we should be increasing how far we step (i.e., increase learning rate η) for just index j. We would need to ensure that this was done only with respect to index j, because the gradient for a different index i might not be as consistent. So, we would like to have a global learning rate η and individualized learning rates ηj for all of the parameters. While the global learning rate stays fixed (unless we use a learning rate schedule), we let some algorithms adjust each of the ηj values to try to improve convergence. Most gradient update schemes work by rescaling the gradient gt, which is equivalent to giving each parameter its own personalized learning rate ηj
- Assistant
Alright, let's break this down:
-
Purpose of Learning Rate: When you're training a model, the learning rate (denoted as "η") determines how fast or slow the model learns from the data. Think of it like setting a speed for a journey; you want just the right pace to reach your destination without going too fast or too slow.
-
- User
- Assistant
- User
explain this in plain english with more details: Adam: Adding variance to momentum One of the currently most popular optimization techniques is called adaptive moment estimation, or Adam for short. Adam is strongly related to the SGD with momentum that we just described. Adam is my current favorite approach because it has default parameters that just work, so I don’t have to spend time tuning them. This is not true for SGD with momentum (normal or Nesterov flavored). We have to rename a few terms to make the math consistent with how you will read about it elsewhere: the velocity v becomes m, and the momentum weight µ becomes β1. Now we can describe the first step of Adam, which has one major change shown in red: new velocity momentum old velocity the gradient This describes the momentum update equation, but we are now down-weighting the current gradient gt by (1 − β1). This makes mt a weighted average between the previous velocity and the current gradient. More specifically, because we added the (1 − β1) term, this is now called an exponential moving average. It’s called exponential because the gradient from z steps ago gt−z has an exponentiated contribution of β1z, and it’s a moving average because it is computing a kind of weighted average where most of the weight is on the most recent items, so the average moves with the most recent data. Since we are now discussing momentum as an average or mean gradient over multiple updates, we can talk about the variance of the gradient as well. If one parameter gjt has high variance, we probably don’t want to let it contribute too much to the momentum180 CHAPTER 5 Modern training techniques because it will likely change again. If a parameter gjt has low variance, it’s a reliable direction to head in, so we should give it more weight in the momentum calculation. To implement this idea, we can calculate information about the variance over time by looking at squared gradient values. Normally, for variance, we would subtract the mean before squaring, but that is hard to do in this scenario. So we use the squared values as an approximation of the variance and keep in mind that it does not provide perfect information. Using to denote the elementwise multiplication between two vectors (a b = [a1 · b1; a2 · b2; : : :]) leads to this equation for variance of velocity v: new variance velocity variance momentum old variance velocity approximate variance We save mt and vt, but we perform one more alteration before using them. Why? Because when we are early in the optimization process, meaning t is a small value, mt and vt give us biased estimates of the mean and variance. They are biased because they are initialized to zero (i.e., m0 = v0 = ~0), so the early estimates will be too small if we use them naively
- Assistant