Gradient Descent
What is it?
Gradient descent is an algorithm that finds the minimum of a function by taking small steps in the direction that decreases the function the most.
In machine learning, that function is the loss β a number that measures how wrong the model is. Gradient descent adjusts the model's parameters to make the loss as small as possible.
Why we need it
A model has numbers inside it called parameters (or weights). The goal of training is to find the parameter values that make the model's predictions as accurate as possible.
There are billions of possible combinations of parameter values. We cannot try them all. We need a smarter way to search.
Gradient descent is that smarter way. It tells us: at any point, which direction makes the loss go down? Take a small step that way. Repeat.
Almost every machine learning model β from linear regression to GPT β is trained using gradient descent or a variation of it.
Explained in detail
Imagine you are standing on a hilly landscape in thick fog. You cannot see far. You want to reach the lowest valley. What do you do?
You feel the slope under your feet, and step downhill.
You are the ball. The hill is the loss function. The valley is the best set of parameters. At each step you check: which way is downhill? Then you move a little in that direction.
Here is how the math works, step by step.
Step 1: Start somewhere. Pick a starting value for the parameter . It can be random.
Step 2: Measure the slope. The slope of the loss at the current is called the gradient, written or . A positive gradient means the loss is going up to the right, so we move left. A negative gradient means the loss is going up to the left, so we move right.
Step 3: Take a step. Move in the opposite direction of the gradient:
Step 4: Repeat. Keep taking steps until the gradient is nearly zero β that means we are at a minimum.
The size of each step is controlled by , called the learning rate. Too big and you overshoot. Too small and it takes forever.
Gradient Descent
The orange ball rolls down the loss curve. The red line shows the gradient (slope) at the current point. Set the learning rate and watch it converge β or diverge.
What to try
- Press Play and watch the orange ball roll down toward the minimum. The dashed orange trail shows where it has been.
- Change the learning rate slider. With (slow), it takes many small steps. With (fast), it converges quickly.
- Press "Break it" to set . Watch the ball bounce and diverge instead of converging. This is what happens when the learning rate is too large.
- Press Step to move one step at a time and read the live values: , Loss, gradient , and the number of steps taken.
The red line shows the gradient (the slope of the loss curve at the current point). When the ball is to the left of the minimum, the gradient is negative β so the update moves to the right. At the minimum, the gradient is zero and the ball stops.
Notes & Formula
The update rule:
The gradient points uphill. So subtracting it moves us downhill. That is why the minus sign is there.
Common mistake: confusing the gradient (slope) with the loss (height). The gradient tells you which way to step; the loss tells you how far you still have to go.
Quiz
π§©
Ready to test yourself?
12 questions Β· explanations shown after
Teach & Solidify
Teach This: Gradient Descent
Core Intuition
Gradient descent iteratively updates parameters in the opposite direction of the gradient to roll down the loss landscape toward the minimum error.
Key Concepts to Explain
- 1The gradient βL points uphill; subtracting Ξ± Β· βL guarantees moving downhill.
- 2The learning rate Ξ± controls step size: too small takes forever, too large diverges.
- 3At a minimum, the slope is zero (flat), so updates naturally slow down and stop.
β οΈ What Most Students Get Confused About
Confusing the gradient (slope/direction) with the loss value (elevation/current error)!
Explain Gradient Descent in your own words
Imagine you are explaining this idea to a friend or classmate with no math background. Writing it out forces your brain to bridge gaps in your intuition.
Resources & GitHub
Resources & Study Materials
Deepen your understanding with author-prepared study notes, derivation proofs, and curated educational lectures.
Visual exploration of high-dimensional loss landscapes and gradient steps.
Rigorous treatment of gradient-based optimization, conditioning, and Jacobian matrices.
Mathematical summary of the negative gradient update, step-size conditions, and convergence rules.
Mastered this concept?
Tick this box when you feel confident explaining it.
Topic Resources
Gradient_Descent_Summary.md
Markdown Note1.0 KB Β· Modified Latest
Was this clear?