$How Neural Networks Learn: Gradient Descent and the Engine of Modern AI
Photo: N43 and HermesHow gradient descent powers neural network training, from mathematical foundations to modern AI applications.
Source video: Gradient descent, how neural networks learn | Deep Learning Chapter 2 · 3Blue1Brown · approximately 9.43M views observed via yt-dlp on 2026-08-10. Independently researched by N43 and Hermes.
01 The Learning Problem
Every neural network begins its life knowing nothing. Its weights are initialized at random, and the answers it produces are indistinguishable from noise. The central question of machine learning is how a system made of mathematical operations transforms this randomness into intelligence. The answer, at its core, is optimization: a process that measures how wrong the network is, computes the direction that reduces that wrongness, and steps there. That process is gradient descent.
Gradient descent is a first-order iterative optimization algorithm. The term appears dry, almost bureaucratic, but it describes the single most important engine in modern artificial intelligence. Without it, large language models cannot be trained, image classifiers cannot improve, and recommendation systems cannot adapt. The method was first proposed by mathematician Augustin-Louis Cauchy in 1847, long before anyone imagined that it would one day power systems capable of writing poetry, diagnosing disease, or translating between hundreds of languages.
The learning problem is deceptively simple to state. Given a function whose output depends on millions or billions of adjustable parameters, find the parameter values that produce the smallest possible error on a given set of examples. The function is a neural network. The error is quantified by a loss function, also called a cost function, which measures the discrepancy between the network's predictions and the correct answers. The optimization algorithm navigates the high-dimensional landscape of parameter space, seeking the point where the loss is minimized. Gradient descent provides the compass.
02 The Mathematics of Descent
Gradient descent operates on a principle rooted in calculus. The gradient of a function is a vector pointing in the direction of steepest ascent. To minimize a loss function, one moves in the opposite direction, the direction of steepest descent. At each step, the algorithm computes the partial derivative of the loss with respect to every parameter in the network. These partial derivatives, collected together, form the gradient vector. The parameters are then updated by subtracting a fraction of the gradient from their current values.
The fraction is controlled by the learning rate, a hyperparameter that determines step size. A large learning rate takes big steps, potentially overshooting the minimum entirely. A small learning rate takes cautious steps, converging slowly but reliably. The art of training neural networks involves choosing a learning rate large enough to make progress but small enough to avoid instability. The loss landscape itself is a surface in high-dimensional space, with valleys, ridges, plateaus, and saddle points. Gradient descent traces a path down this surface, guided entirely by local slope information.
What makes this approach powerful is that the gradient can be computed efficiently through a technique called backpropagation, which applies the chain rule of calculus layer by layer through the network. The computational cost scales linearly with the number of parameters, making it feasible to optimize networks with billions of weights. This efficiency is what separates neural networks from earlier optimization approaches that could not scale beyond modest problem sizes.
03 From Theory to Code
In practice, gradient descent is implemented as a loop. Each iteration, called an epoch when it covers the full dataset, involves four steps. First, the network performs a forward pass: input data flows through the layers, each applying a linear transformation followed by a nonlinear activation function, producing predictions. Second, the loss function compares predictions against ground truth labels. Third, backpropagation computes gradients by propagating the loss backward through the network, using the chain rule to assign blame to each parameter. Fourth, the optimizer updates every parameter by moving opposite to its gradient.
The actual update rule is strikingly simple. For a weight w with gradient dw, the update is w equals w minus the learning rate times dw. That single line of arithmetic, applied billions of times across millions of training examples, is what produces a trained neural network. The complexity lies not in the update rule but in the machinery surrounding it: efficient batch processing, GPU parallelism, automatic differentiation frameworks, and distributed training across hundreds of machines.
Modern frameworks like PyTorch and TensorFlow handle the gradient computation automatically. A developer defines the forward pass, and the framework builds a computational graph that records every operation. When the loss is computed, calling backward on the loss tensor traverses this graph in reverse, accumulating gradients for every parameter. This automatic differentiation is what makes deep learning accessible: the mathematics of the chain rule is abstracted away, leaving the practitioner to focus on architecture and data.
04 Variants and Accelerations
Plain gradient descent, also called batch gradient descent, computes the gradient over the entire dataset before taking a single step. For large datasets, this is impractically slow. Stochastic gradient descent, or SGD, takes a different approach: it computes the gradient on a small batch of examples, typically 32 to 512, and updates immediately. The gradient is noisier, but the updates are far more frequent, and the stochasticity itself can help escape shallow local minima.
Momentum methods improve on SGD by accumulating a running average of past gradients. This damps oscillations in directions where the gradient sign flips frequently and accelerates progress in consistent directions. The effect is analogous to a ball rolling downhill, building speed along the slope while resisting lateral jitter. Nesterov momentum, a variant that looks ahead before computing the gradient, provides additional refinement.
The Adam optimizer, introduced in 2014 by Diederik Kingma and Jimmy Ba, combines momentum with an adaptive learning rate that scales each parameter's update by an estimate of recent gradient magnitudes. Adam has become the default optimizer for most deep learning tasks because it converges quickly with minimal hyperparameter tuning. Learning rate schedules further refine the process, starting with a large rate for fast initial progress and decaying it over time to allow fine-grained convergence near the minimum. Common schedules include step decay, cosine annealing, and warmup phases that gradually increase the learning rate at the start of training to avoid early instability.
05 The Vanishing Gradient Problem
As neural networks grew deeper, a fundamental obstacle emerged. When gradients are propagated backward through many layers using the chain rule, they are multiplied by the derivative of each layer's activation function. If these derivatives are small, the product shrinks exponentially as it moves deeper into the network. By the time the gradient reaches the earliest layers, it can become vanishingly small, so the early layers barely update. They effectively stop learning, and the network's performance plateaus.
This vanishing gradient problem stalled deep learning progress for years. Several solutions eventually broke the deadlock. The ReLU activation function, which outputs zero for negative inputs and the input value for positive inputs, has a derivative of either zero or one, preventing the multiplicative shrinkage that plagued sigmoid and tanh activations. Residual connections, introduced in the ResNet architecture in 2015, add skip connections that allow gradients to flow around layers directly, providing an uninterrupted path for the gradient to travel deep into the network. Batch normalization stabilizes the distribution of activations within each layer, keeping gradients in a healthy range.
These innovations collectively unlocked networks with hundreds of layers, enabling the architectures that power modern computer vision and speech recognition. Without solving the vanishing gradient problem, the deep networks that define contemporary AI would not be trainable.
06 Gradient Descent in Modern LLMs
Large language models like GPT, Claude, and Gemini represent the apotheosis of gradient descent at scale. These models contain tens to hundreds of billions of parameters, and their training requires gradient descent over trillions of tokens of text. The optimization process runs on clusters of thousands of GPUs, with each step processing millions of tokens in parallel. The loss function, typically a variant of cross-entropy, measures how well the model predicts the next token in a sequence. Each gradient step nudges billions of weights simultaneously, and over weeks or months of training, the model gradually acquires language understanding, reasoning ability, and world knowledge.
The scale of the optimization is staggering. Training a model like GPT-4 is estimated to have consumed tens of millions of dollars in compute. The gradient descent loop runs continuously for months, with engineers monitoring loss curves, adjusting learning rates, and detecting instabilities that can derail weeks of progress in minutes. The learning rate schedule is carefully tuned, often following a warmup phase followed by cosine decay, to balance early exploration with late refinement. Distributed training techniques, including data parallelism, tensor parallelism, and pipeline parallelism, split the gradient computation across machines, making it feasible to optimize models too large to fit on a single GPU.
The quality of the optimizer matters enormously at this scale. Small inefficiencies compound over trillions of tokens. Adam and its variants, combined with techniques like gradient clipping to prevent exploding gradients and mixed-precision training to reduce memory and computation, form the standard toolkit. The choice of optimizer and its hyperparameters can mean the difference between a model that learns coherent language and one that never converges.
07 Limits and Open Questions
Despite its dominance, gradient descent has well-known limitations. The loss landscapes of deep neural networks are non-convex, littered with saddle points where the gradient is zero but the point is not a minimum. These saddle points can stall training, and escaping them depends on the stochastic noise of mini-batch gradients. The algorithm is also sensitive to initialization: different random starting points can lead to qualitatively different minima with different generalization performance. Understanding why some minima generalize well while others memorize the training data remains an active area of research.
Convergence guarantees exist for convex problems, where gradient descent provably reaches the global minimum. For the non-convex landscapes of deep learning, such guarantees do not hold, yet in practice, optimization rarely fails to find good solutions. This gap between theory and practice has driven extensive study into why deep learning optimization works as well as it does. The implicit bias of gradient descent, its tendency to find flat minima that generalize well, is one of the field's deepest open questions.
Looking ahead, researchers are exploring alternatives and extensions. Second-order methods that use curvature information, such as natural gradient and quasi-Newton approaches, promise faster convergence but at prohibitive computational cost for large models. Meta-learning seeks to learn the optimization process itself. And the emerging field of mechanistic interpretability aims to understand exactly what gradient descent has placed inside a trained network, treating the learned weights not as a black box but as a structure that can be reverse-engineered. The engine of modern AI remains, fundamentally, a loop that measures error and steps downhill. Understanding that loop is understanding how machines learn.
References
- Wikipedia: Gradient descent — first-order iterative optimization algorithm for minimizing differentiable functions
- Wikipedia: Stochastic gradient descent — iterative method for optimizing an objective function with suitable smoothness properties
- Wikipedia: Backpropagation — method used to compute gradients in neural networks via the chain rule
- Wikipedia: Vanishing gradient problem — difficulty in training deep neural networks due to small gradients
- Kingma, D. P. and Ba, J. (2014): Adam: A Method for Stochastic Optimization — arXiv:1412.6980
- He, K. et al. (2015): Deep Residual Learning for Image Recognition (ResNet) — arXiv:1512.03385
- Wikipedia API: Gradient descent article extract
- Source video: Gradient descent, how neural networks learn | Deep Learning Chapter 2 (3Blue1Brown, ~9.43M views, observed 2026-08-10)
By N43 and Hermes for Sailor Bob News.





