MML204

Gradient Descent

⏱8 min readπŸ‘οΈEye-Care Reading Mode

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 ww. It can be random.

Step 2: Measure the slope. The slope of the loss at the current ww is called the gradient, written βˆ‡L\nabla L or dLdw\frac{dL}{dw}. 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 ww in the opposite direction of the gradient:

w←wβˆ’Ξ±β‹…dLdww \leftarrow w - \alpha \cdot \frac{dL}{dw}

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 Ξ±\alpha, called the learning rate. Too big and you overshoot. Too small and it takes forever.

Gradient Descent

w:-0.5000
Loss:6.7513
βˆ‡L:-4.8939
Steps:0
Ξ±:0.10
Learning Rate (Ξ±)0.10
0.011.5
Presets:

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 Ξ±=0.05\alpha = 0.05 (slow), it takes many small steps. With Ξ±=0.5\alpha = 0.5 (fast), it converges quickly.
  • Press "Break it" to set Ξ±=1.2\alpha = 1.2. 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: ww, Loss, gradient βˆ‡L\nabla L, 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 wβˆ’Ξ±β‹…βˆ‡Lw - \alpha \cdot \nabla L moves ww to the right. At the minimum, the gradient is zero and the ball stops.


Notes & Formula

The update rule:

Gradient Descent Update Rule

w←wβˆ’Ξ±β‹…βˆ‡wL(w)w \leftarrow w - \alpha \cdot \nabla_w L(w)

SymbolMeaning
wThe parameter (weight) being updated
Ξ±Learning rate β€” a small positive number, e.g. 0.01 to 0.3
βˆ‡LGradient of the loss with respect to w β€” the slope
L(w)Loss function β€” the number we want to minimize
←Assignment: replace the old value with the new one
πŸ’‘

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

πŸŽ“
Feynman Teaching Card

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)!

✍️
Active Recall Practice

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.

Saved locally on your device

Resources & GitHub

🎯

Mastered this concept?

Tick this box when you feel confident explaining it.

πŸ“
Study Notes & Files1 file

Topic Resources

GitHub↗
πŸ“

Gradient_Descent_Summary.md

Markdown Note

1.0 KB Β· Modified Latest

Was this clear?