esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

What Is Gradient Descent?

How a model learns by taking small steps downhill on its loss, what the learning rate does, and where the method falls short, for your AI interview.

In short

Gradient descent is an iterative method for finding the weights and bias that minimise a model's loss. The model repeatedly measures how wrong its guesses are, steps its weights a little downhill, and stops when more steps no longer help.

12 min readBeginnerVery common · estimateFacts checked 26 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

I'd say gradient descent is how a model learns. The model measures how wrong it is, works out which way the loss goes down, and takes a small step that way. Then it repeats. The learning rate sets the step size. Too small and training crawls. Too big and it bounces past the lowest point. For linear models the loss is shaped like a bowl, so this finds the best possible model for the given data.

What is gradient descent, in plain words?

A model learns by changing its numbers, the weights and bias, until its mistakes are as small as they can get. Gradient descent is the method that makes those changes, one small step at a time.

Picture a hiker caught in thick fog on a hillside who wants the valley floor. They can't see far, but they can feel the slope under their boots. They take a small step downhill, feel again, and repeat until the ground levels out. Gradient descent does the same with the loss, the score for how wrong the model is.

The real case is an insurer's model that guesses repair costs from labour hours. Its one weight is too low, so every guess comes out cheap. Gradient descent nudges that weight up a little each round, checking the loss after every nudge, until the guesses match past claims.

Key words

Weight
A number the model multiplies an input by. Training changes it.
Bias
A number added to the result, which shifts every prediction up or down.
Loss
A score for how wrong the predictions are. Lower is better.
Gradient
The slope of the loss. It shows which way the loss goes up.
Learning rate
How big each step is. You choose it before training starts.

How does gradient descent work, step by step?

The model starts with its weights and bias close to zero. Then it repeats the same four steps, and each round aims to lower the loss.

  1. 1

    Measure the loss

    Run the model with the current weight and bias, then score how far its guesses are from the real values.

  2. 2

    Find the slope

    Work out the slope of the loss at this weight. The slope, or gradient, shows which way the loss goes up.

  3. 3

    Step the other way

    Move the weight a small amount against the slope, so the loss goes down. The step size is the learning rate times the slope.

  4. 4

    Repeat until it flattens

    Go back to the first step. Stop when more rounds no longer lower the loss. That point is convergence.

One round of gradient descent

Start with guesses

weights and bias near zero

Measure the loss

how wrong the guess is

Each round

Find the slope

which way the loss rises

Step the other way

a small move, sized by the rate

Loss stops falling

the model has converged

  1. 1The starting guess is scored for loss.
  2. 2The loss tells us where to look for the slope.
  3. 3The slope sets the direction of the step.
  4. 4Once the loss check shows no more gains, training stops here.
  5. 5Otherwise the new weights go back to the loss check.
One round runs left to right, then loops back. The model measures the loss, finds the slope, and steps against it. The loop stops once the loss stops falling.

Here is one round with made-up numbers. The repair model starts with weight 0. Its loss slope there is minus 2,805, and the learning rate is 0.01. The new weight is 0 minus 0.01 times minus 2,805, which is 28.05. In the run below, six rounds take the weight to 71.07 and the loss from 106350.0 down to 441.0.

Python
# A made-up repair-cost guess: cost = w * labour_hours. Gradient descent finds w from past claims.
HOURS = [2, 3, 5, 6]
COST = [160, 230, 380, 450]

def loss(w):
    # Mean squared error: the average of the squared misses.
    return sum((w * h - c) ** 2 for h, c in zip(HOURS, COST)) / len(HOURS)

def slope(w):
    # Slope of the loss at w: positive means going up, so step the other way.
    return sum(2 * (w * h - c) * h for h, c in zip(HOURS, COST)) / len(HOURS)

w = 0.0
learning_rate = 0.01
print(f"start: weight={w:.2f} loss={loss(w):.1f}")
for step in range(1, 7):
    w = w - learning_rate * slope(w)
    print(f"step {step}: weight={w:.2f} loss={loss(w):.1f}")

Output

start: weight=0.00 loss=106350.0
step 1: weight=28.05 loss=42225.6
step 2: weight=45.72 loss=16774.6
step 3: weight=56.85 loss=6673.1
step 4: weight=63.87 loss=2663.8
step 5: weight=68.29 loss=1072.6
step 6: weight=71.07 loss=441.0

What does the learning rate do?

The learning rate sets how big each step is. Too small, and training takes many rounds to get anywhere. Too large, and each step jumps past the lowest point, so the loss bounces around or climbs.

What the learning rate does

Learning rate

the step size you choose

Three settings

Too small

tiny steps, slow progress

Just right

steps sized to the slope

Too large

steps overshoot the lowest point

What happens

Many slow rounds

loss falls, but it takes ages

Loss falls fast

then it flattens out

Loss bounces

it never settles

  1. 1The rate is set to a small value.
  2. 2The rate is set to a good value.
  3. 3The rate is set to a large value.
  4. 4Each step is tiny, so progress is slow.
  5. 5Each step lands near the lowest point.
  6. 6Each step jumps past the lowest point.
Three settings of one number lead to three very different runs. Only the middle one lowers the loss quickly and then levels out. The small rate is slow, the large one makes the loss bounce, and both show clearly on a loss curve.
  • “However, if the learning rate is too high, the model never converges, but instead bounces around the weights and bias that minimize the loss.”

    Google's machine learning crash course

The right rate depends on the problem, so there is no single safe number. You tune it on your own data and watch the loss curve.

Tip

Asked how to pick a learning rate, don't name a magic number. Say the ideal rate depends on the model and the data, then say how you would check it with the loss curve.

Batch, mini-batch or stochastic: how many examples per step?

The three versions differ in how many examples they look at before each update. Batch size is the number of examples the model processes before it updates its weights and bias.

  • Full batch

    All examples per step

    Steady, because each step uses the whole dataset. But with hundreds of thousands of examples, it isn't practical.

  • Stochastic (SGD)

    One example per step

    Each step reads one example, so the loss curve stays noisy, even late in training.

  • Mini-batch

    A small group per step

    A compromise between the other two. It uses a small group per step, so it is steadier than one example.

With stochastic gradient descent, each iteration uses a single example. That means the noise can show up across the whole loss curve.

Where does gradient descent fall short?

For linear regression the picture is friendly. Its loss surface is shaped like a bowl, so following the slope leads to the best possible model for the given data. Google's crash course puts it this way:

  • “Linear models have convex loss functions, ensuring that gradient descent will always find the global minimum, resulting in the best possible model for the given data.”

    Google's machine learning crash course

  • “Stochastic Gradient Descent is sensitive to feature scaling, so it is highly recommended to scale your data.”

    scikit-learn's guide to SGD

Three limits matter in practice. The bowl guarantee is stated for linear models, so don't claim it for every model. Neural networks have losses that are not bowls. There, gradient descent can settle in a local low point or stall on a flat saddle, so no guarantee holds. And stochastic gradient descent is sensitive to the scale of the inputs, as scikit-learn notes. If one feature runs into the thousands while another is a decimal, the steps lurch, so scale the data first.

Tip

If a model won't converge, check the learning rate and the feature scales before you blame the method.

How would you fix a loss curve that zigzags?

A repair-cost model trains, but its loss zigzags up and down and never settles. Walk through the fixes in this order.

  1. 1

    Lower the learning rate

    Start here. A rate that is too high can make the loss bounce, so check it first. Rerun and watch the curve.

  2. 2

    Scale the features

    If one input runs into the thousands and another into decimals, the steps lurch. Scale them to similar ranges, then rerun.

  3. 3

    Try mini-batch

    If each step reads a single example, some noise is expected. A small batch of examples evens it out.

  4. 4

    Stop on the flat part

    Once the loss flattens, more rounds add little. Stop there and check the result on data the model has not seen.

What does the interviewer want to hear?

A strong answer covers

  • A plain definition: repeat small steps that lower the loss, against its slope.
  • The four steps: measure the loss, find the slope, step, repeat.
  • The learning rate: too small is slow, too large overshoots.
  • Batch, mini-batch and stochastic: how many examples per step.
  • The bowl guarantee for linear models, and why it does not carry over.
  • Feature scaling and the loss curve as the first checks.

Common traps

  • Trap"It always finds the best model."

    BetterIt finds the lowest loss it can reach. For linear models that is the best possible model for the given data.

  • Trap"A bigger learning rate always trains faster."

    BetterOnly until it overshoots. Past that point the loss bounces and never settles.

  • Trap"You set the weights, and gradient descent checks them."

    BetterGradient descent changes the weights itself, a little each round. You set the rate and the start.

Can you spot the problem?

Spot the cause

A claims team's training run shows a loss that rises every round. Which setting is the most likely cause?

Quick check

A linear model's loss falls smoothly for 200 rounds, then stays flat. What does that most likely mean?

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q416SGD vs Adam?Coming soon
  2. Q418What is backpropagation?11 min
  3. Q419MSE vs cross-entropy loss?11 min
  4. Q413Overfitting vs underfitting?10 min
  5. Q414L1, L2 and dropout regularisation?13 min

Learn it in depth

Last updated on 26 November 2026

Building a model your team has to trust?

I design and build AI products and agents, and the system behind them. Book a short call and tell me what you need to build.