Skip to content
elevatedevco

Deep Learning

Gradient descent and optimization

Learn Gradient descent and optimization: 33 practice questions and answers with an interactive quiz — from the offline AI Learning app.

Advanced33 questions33 quiz questions

Questions & Answers

Tap a question to reveal its answer. Written for self-study and interview preparation.

What is gradient descent, in one sentence?

Gradient descent is an iterative optimization algorithm that minimizes a function by repeatedly moving the parameters in the direction opposite to the gradient (the direction of steepest decrease). Each step reduces the loss until it reaches (or approaches) a minimum.

In the update rule θ = θ − α·∇J(θ), what does α represent and why must it be chosen carefully?

α is the learning rate, which controls the size of each step taken along the negative gradient. If α is too large the algorithm can overshoot and diverge, and if it is too small convergence becomes very slow.

Why do we move in the direction OPPOSITE to the gradient when minimizing a function?

The gradient points in the direction of steepest increase of the function. To minimize, we want to decrease the value, so we move in the opposite direction, which is the direction of steepest decrease.

What is the difference between batch gradient descent and stochastic gradient descent (SGD)?

Batch gradient descent computes the gradient using the entire training dataset for each update, giving a stable but slow step. SGD uses a single randomly chosen example per update, making it much faster and noisier, which can help escape shallow local minima.

What is mini-batch gradient descent and why is it the most common choice in deep learning?

Mini-batch gradient descent computes the gradient on a small subset (e.g., 32 or 64 samples) of the data per update. It balances the stability of batch descent with the speed and noise benefits of SGD, and it makes efficient use of vectorized hardware like GPUs.

What is a local minimum, and why can it be a problem for gradient descent?

A local minimum is a point where the function is lower than all nearby points but not necessarily the lowest overall (global minimum). Gradient descent can get stuck there because the gradient is zero, so the algorithm stops even though a better solution exists elsewhere.

What is a convex function, and why is gradient descent guaranteed to find the global minimum on one?

A convex function is bowl-shaped: any line segment between two points on the curve lies on or above the curve, so it has a single global minimum and no other local minima. Because there are no traps, gradient descent with a suitable learning rate will converge to that unique global minimum.

What does the learning rate being TOO HIGH typically cause during training?

A learning rate that is too high causes the parameters to overshoot the minimum on each step, so the loss may oscillate, increase, or diverge to infinity instead of decreasing. The training curve often shows the loss bouncing around or blowing up.

What is momentum in gradient descent, and what problem does it help solve?

Momentum adds a fraction of the previous update to the current one, like a ball rolling downhill accumulating velocity. It helps accelerate descent in consistent directions and dampens oscillations in narrow ravines, speeding up convergence.

Briefly, what makes the Adam optimizer popular compared to plain SGD?

Adam combines momentum with per-parameter adaptive learning rates, using running averages of past gradients and their squares. This makes it converge quickly and work well across many problems with little manual tuning of the learning rate.

What is an epoch in the context of training with gradient descent?

An epoch is one complete pass of the optimization algorithm through the entire training dataset. Training usually requires many epochs so the model sees the data repeatedly and gradually reduces the loss.

For the function f(x) = x², the derivative is f'(x) = 2x. Starting at x = 4 with learning rate α = 0.1, what is x after one gradient descent step?

The update is x_new = x − α·f'(x) = 4 − 0.1·(2·4) = 4 − 0.8 = 3.2. The point moves closer to the minimum at x = 0, as expected.

x = 4.0
alpha = 0.1
grad = 2 * x      # f'(x) = 2x
x = x - alpha * grad
print(x)          # 3.2
What does it mean for gradient descent to 'converge'?

Convergence means the parameter updates become very small and the loss stops decreasing meaningfully, indicating the algorithm has reached (or is very near) a minimum. In practice we detect it when the loss change falls below a small threshold or the gradient is near zero.

Why is feature scaling (normalization) often important before running gradient descent?

When features have very different scales, the loss surface becomes elongated, causing gradient descent to zigzag and converge slowly. Scaling features to comparable ranges makes the surface more symmetric, allowing larger, more direct steps toward the minimum.

What is a saddle point, and why is it relevant in high-dimensional optimization?

A saddle point is where the gradient is zero but the function increases in some directions and decreases in others, so it is neither a maximum nor a minimum. In high dimensions saddle points are very common and can slow gradient descent because the gradient is small near them.

What is the vanishing gradient problem in training deep networks?

In deep networks, gradients are multiplied through many layers during backpropagation, and if these values are small they shrink exponentially, becoming nearly zero in early layers. This means early layers barely update, making training very slow or stalled.

What is a learning rate schedule (decay), and why is it useful?

A learning rate schedule gradually reduces the learning rate as training progresses. Large early steps move quickly toward the minimum, while smaller later steps allow fine-tuning and stable settling into the minimum without overshooting.

What is the cost (loss) function's role in gradient descent?

The cost function measures how far the model's predictions are from the true values, producing a single number to minimize. Gradient descent uses the gradient of this cost function with respect to the parameters to decide which direction to update them.

In SGD, why are the updates 'noisy', and can this noise be beneficial?

SGD estimates the gradient from a single example (or small batch), so each estimate differs from the true full-dataset gradient, producing noisy zigzag updates. This noise can be beneficial because it helps the optimizer escape shallow local minima and saddle points.

What is the exploding gradient problem, and one common way to address it?

Exploding gradients occur when gradients grow extremely large during backpropagation, causing huge unstable parameter updates and loss that becomes NaN or infinite. A common fix is gradient clipping, which caps the gradient magnitude at a maximum threshold.

Why is the derivative/gradient being zero a necessary condition at a minimum?

At a minimum the function is locally flat, so its slope (derivative) is zero, meaning no direction of small movement decreases the value further. Gradient descent naturally stops there because the update step θ − α·∇J becomes θ when the gradient is zero.

What is the difference between a global minimum and a local minimum?

A global minimum is the lowest value the function takes over its entire domain, while a local minimum is only the lowest within some neighborhood. A function can have many local minima but the global minimum is the absolute best point.

In the Python loop below, what role does `grad` play and what is the gradient of the loss L = (w-3)²?

`grad` is the derivative of the loss with respect to w, which is 2*(w-3); it tells the direction and steepness for the update. Subtracting `lr*grad` moves w toward 3, the value that minimizes the loss.

w = 0.0
lr = 0.1
for _ in range(50):
    grad = 2 * (w - 3)   # d/dw of (w-3)**2
    w = w - lr * grad
print(round(w, 3))       # approaches 3.0
What is early stopping, and how does it relate to optimization and overfitting?

Early stopping halts training when performance on a validation set stops improving, even if the training loss could keep decreasing. It prevents the optimizer from over-minimizing the training loss to the point of overfitting, acting as a form of regularization.

Why can gradient descent be slow in long, narrow 'ravine' shaped loss surfaces?

In a ravine the surface is steep across the narrow direction but gently sloped along the long direction, so gradients point mostly across, causing the path to zigzag back and forth. This wastes steps and makes progress along the true descent direction slow; momentum or adaptive methods help.

What does 'batch size' control, and what is one trade-off of using a very large batch size?

Batch size is the number of training examples used to compute the gradient for each update. Very large batches give smoother, more accurate gradient estimates but require more memory and may generalize worse and provide fewer updates per epoch.

How does the chain rule from calculus underpin backpropagation in neural networks?

Backpropagation computes the gradient of the loss with respect to each weight by applying the chain rule, multiplying derivatives layer by layer from the output back to the input. This efficiently propagates error signals so every parameter knows how to change to reduce the loss.

What is the purpose of the gradient's MAGNITUDE (not just its direction) in an update step?

The magnitude of the gradient indicates how steep the slope is, so larger gradients produce bigger steps and smaller gradients produce smaller steps for a fixed learning rate. This naturally slows the algorithm down as it approaches a flat minimum where the gradient shrinks.

What is RMSProp, and what problem with AdaGrad does it address?

RMSProp scales the learning rate for each parameter by a running (exponentially decayed) average of recent squared gradients. This fixes AdaGrad's issue where the accumulated squared gradients grow without bound and shrink the learning rate to nearly zero, stalling learning.

If the loss curve goes down then suddenly spikes upward during training, what is a likely cause?

A sudden upward spike usually indicates an unstable step, often from a learning rate that is too high causing overshooting or from exploding gradients. Reducing the learning rate or applying gradient clipping commonly fixes it.

Why does gradient descent require the loss function to be (mostly) differentiable?

Gradient descent relies on computing the gradient (derivatives) of the loss with respect to the parameters to know which way to step. If the function is not differentiable, the gradient may not exist at some points, so the algorithm cannot determine a valid descent direction there.

What is the difference between a hyperparameter like the learning rate and a parameter like a weight?

Parameters (weights and biases) are values the model learns automatically through gradient descent during training. Hyperparameters like the learning rate are set by the practitioner before training and control how the learning process behaves, not the model's internal values.

Why is initialization of weights important for gradient descent in neural networks?

The starting point determines where on the loss surface descent begins, affecting which minimum is reached and how fast. Poor initialization (e.g., all zeros or very large values) can cause symmetry problems, vanishing or exploding gradients, and slow or failed convergence.

Put it into practice with AI Learning

This topic — and hundreds more — comes from our free, offline AI Learning app. Practice Q&A, quizzes and cheat sheets anywhere, no account needed.

  • Free
  • No account
  • Works offline
Coming soon toGoogle Play