Backpropagation Explained for Beginners (Part 1): Building the Intuition

The Genesis of Learning: Backpropagation’s Historical Significance
The journey to understanding backpropagation is not merely an academic exercise but a dive into the very engine of the current AI revolution. While the concept of gradient descent, the iterative optimization algorithm that backpropagation leverages, has roots in the 19th century, its application to neural networks gained prominence through the work of numerous researchers. Paul Werbos first described the application of backpropagation to neural networks in his 1974 Ph.D. thesis. However, it was the 1986 paper by David Rumelhart, Geoffrey Hinton, and Ronald Williams, "Learning representations by back-propagating errors," that popularized the algorithm and ignited widespread interest in neural networks. Despite this breakthrough, neural networks and backpropagation faced an "AI winter" due to limitations in computational power and data availability.
The resurgence of deep learning in the early 2010s, marked by breakthroughs like AlexNet’s performance in the ImageNet competition in 2012, was largely attributed to the availability of massive datasets, powerful GPUs for parallel processing, and refined implementations of backpropagation. Today, backpropagation is the backbone of systems ranging from image recognition and natural language processing to drug discovery and autonomous vehicles. Its efficiency in calculating gradients for millions or even billions of parameters is what makes the training of sophisticated models like GPT-3 or GPT-4 feasible, allowing them to exhibit human-like understanding and generation of text.
The Imperative of Learning: Bridging Prediction Gaps
At its core, a neural network’s purpose is to make predictions. In a previous exploration, a simple neural network was constructed to predict exam scores based on hours studied, using a dataset that revealed a non-linear relationship. Initially, this network, despite its architectural sophistication—featuring a hidden layer with two neurons and ReLU activation functions—produced a curve that visibly deviated from the actual data points. For instance, an input of 1 hour studied might yield an actual score of 55, while the untrained network predicts a mere 28. This substantial discrepancy underscores the network’s deficiency and highlights the fundamental need for it to "learn."

Learning, in this context, means systematically adjusting the network’s internal parameters—its weights and biases—to minimize the difference between its predictions and the true observed values. The objective is to refine these parameters so that the predicted outputs align as closely as possible with the actual data, thereby reducing the "loss" or error. This process is iterative, with each adjustment aiming to incrementally improve the network’s performance. Without an effective learning mechanism, even the most intricately designed neural network remains a mere calculator, incapable of adapting to the nuances of real-world data.
Quantifying Error: The Role of Loss Functions
To guide the learning process, a neural network requires a metric to quantify its prediction errors. This metric is known as the loss function. Drawing parallels from simpler models like linear regression, where the Mean Squared Error (MSE) is a common choice, we can extend this concept to neural networks. For linear regression, the loss function, $L(beta_0, beta1) = frac1nsumi=1^n(y_i – haty_i)^2$, depends solely on the intercept ($beta_0$) and slope ($beta_1$). The goal is to find the values of these two parameters that minimize this loss, often visualized as finding the bottom of a bowl-shaped loss surface in a 3D plot.
In the case of our simple neural network, which tackles a non-linear regression problem, MSE remains an appropriate choice. However, the complexity escalates significantly. The prediction $haty_i$ is no longer a simple linear equation but the output of the entire network:
$haty_i = w_3mathrmReLU(w_1x_i+b_1) + w_4mathrmReLU(w_2x_i+b_2) + b_3$.
Consequently, the loss function, $L(w_1, w_2, w_3, w_4, b_1, b_2, b3) = frac1nsumi=1^n(y_i – haty_i)^2$, now depends on seven distinct parameters: $w_1, w_2, w_3, w_4$ (weights) and $b_1, b_2, b_3$ (biases). Minimizing this loss requires navigating an eight-dimensional loss surface (seven parameters plus the loss value itself), a landscape impossible to visualize directly. The challenge lies in determining how each of these parameters should be adjusted to incrementally decrease the overall loss.
Navigating High-Dimensional Landscapes: The Power of Partial Derivatives
The strategy for minimizing the loss in such a high-dimensional space mirrors the principle used in simpler regression: compute the partial derivative of the loss with respect to each parameter. A partial derivative, such as $fracpartial Lpartial w_1$, indicates the rate at which the loss changes when a specific parameter ($w_1$ in this instance) is infinitesimally adjusted, while all other parameters are held constant. These values, known as gradients, provide crucial directional information, guiding the network on whether to increase or decrease a parameter to move towards a lower loss.

For a network with millions or billions of parameters, calculating these gradients efficiently is paramount. Manual derivation for each parameter would be an arduous and error-prone task. This is where the mathematical elegance of the chain rule becomes indispensable, forming the bedrock of the backpropagation algorithm.
The Chain Rule: Deconstructing Complex Dependencies
The chain rule is a fundamental concept in calculus that allows for the differentiation of composite functions. It is invoked whenever a quantity depends on another quantity, which in turn depends on a third, and so on. Consider a simple example: if $y=x^2$ and $z=y^3$, and we wish to find $fracdzdx$. Classically, one might substitute $y=x^2$ into the equation for $z$ to get $z=(x^2)^3=x^6$, then differentiate directly to find $fracdzdx=6x^5$.
While effective for simple expressions, this substitution method quickly becomes intractable for more complex functions with multiple intermediate variables, as seen in neural networks. The chain rule offers a systematic, step-by-step approach. Instead of combining everything, it breaks down the derivative into a product of simpler derivatives:
$fracdzdx = fracdzdy times fracdydx$.
Applying this:
Given $z=y^3$, then $fracdzdy=3y^2$.
Given $y=x^2$, then $fracdydx=2x$.
Multiplying these yields $fracdzdx=3y^2 times 2x$.
Substituting $y=x^2$ back into the result gives $fracdzdx=3(x^2)^2 times 2x = 6x^5$.
The key insight is that the chain rule allows us to compute derivatives locally, propagating the influence of changes through the network’s layers. This modularity is precisely what backpropagation leverages to compute all necessary gradients efficiently.

Deconstructing the Gradient: A Step-by-Step Derivation of $fracpartial Lpartial w_1$
Let’s apply this principle to our neural network’s loss function to derive the partial derivative with respect to a single weight, $w_1$. The network’s output $haty$ is structured as:
$haty = w_3a_1 + w_4a_2 + b_3$
where $a_1 = mathrmReLU(z_1)$, $z_1 = w_1x + b_1$, and similarly for $a_2$ and $z_2$.
The complete loss function for $n$ training examples is:
$L(w_1, w_2, w_3, w_4, b_1, b_2, b3) = frac1nsumi=1^nleft(y_i-left(w_3mathrmReLU(w_1x_i+b_1)+w_4mathrmReLU(w_2x_i+b_2)+b_3right)right)^2$.
Our goal is to compute $fracpartial Lpartial w_1$. We proceed systematically using the chain rule:
-
Differentiating the Outer Loss Function:
Starting with the MSE, $L = frac1nsum_i=1^n(y_i – haty_i)^2$.
$fracpartial Lpartial w1 = frac1nsumi=1^n fracpartialpartial w_1 (y_i – haty_i)^2$.
Applying the power rule and chain rule (let $A = y_i – haty_i$):
$fracpartial Lpartial w1 = frac1nsumi=1^n 2(y_i – haty_i) fracpartialpartial w_1 (y_i – haty_i)$.
Since $y_i$ is a constant with respect to $w_1$:
$fracpartial Lpartial w1 = frac2nsumi=1^n (y_i – haty_i) left(-fracpartial haty_ipartial w1right) = -frac2nsumi=1^n (y_i – haty_i) fracpartial haty_ipartial w_1$. -
Differentiating the Network Output $haty_i$:
The prediction is $haty_i = w_3mathrmReLU(w_1x_i+b_1) + w_4mathrmReLU(w_2x_i+b_2) + b_3$.
Differentiating with respect to $w_1$:
$fracpartial haty_ipartial w_1 = fracpartialpartial w_1 left(w_3mathrmReLU(w_1x_i+b_1)right) + fracpartialpartial w_1 left(w_4mathrmReLU(w_2x_i+b_2)right) + fracpartialpartial w_1 (b_3)$.
The second and third terms are zero because they do not depend on $w_1$.
$fracpartial haty_ipartial w_1 = w_3 fracpartialpartial w_1 mathrmReLU(w_1x_i+b_1)$.
-
Differentiating the ReLU Activation Function:
Let $u = w_1x_i+b_1$. Then we need to find $fracpartialpartial w_1 mathrmReLU(u)$.
Using the chain rule: $fracpartialpartial w_1 mathrmReLU(u) = fracd,mathrmReLU(u)du times fracdudw_1$.
The derivative of $mathrmReLU(u)$ with respect to $u$ is $mathrmReLU'(u)$, which is 1 if $u>0$ and 0 if $u le 0$ (undefined at $u=0$, but typically handled as 0 or 1 in practice).
The derivative of $u = w_1x_i+b_1$ with respect to $w_1$ is $x_i$.
So, $fracpartialpartial w_1 mathrmReLU(w_1x_i+b_1) = mathrmReLU'(w_1x_i+b_1) times x_i$. -
Substituting Back to Obtain the Final Gradient:
Combining the results:
$fracpartial haty_ipartial w_1 = w_3 mathrmReLU'(w_1x_i+b_1) x_i$.
Finally, substituting this back into the loss derivative:
$fracpartial Lpartial w1 = -frac2nsumi=1^n (y_i – haty_i) left(w_3 mathrmReLU'(w_1x_i+b_1) x_iright)$.
This equation, the gradient of the loss with respect to $w_1$, encapsulates how a tiny change in $w_1$ affects the overall error. Each component plays a specific role:
- $(y_i – haty_i)$: The error for a single training example. This term indicates the magnitude and direction of the discrepancy between the true and predicted values.
- $w_3$: The weight connecting the first hidden neuron’s activation ($a_1$) to the output neuron. It signifies how strongly changes in $a_1$ propagate to the final prediction.
- $mathrmReLU'(w_1x_i+b_1)$: The derivative of the ReLU activation. This term acts as a gate; if the neuron’s input is negative, the gradient flow is blocked, as the ReLU output is zero. If positive, the gradient passes through with a value of 1.
- $x_i$: The input feature associated with the current training example. It determines how much a change in $w_1$ influences the neuron’s weighted sum.
The summation and division by $n$ average these individual contributions across the entire dataset, providing a robust overall gradient that guides the optimization process. This average gradient dictates the magnitude and direction of the adjustment for $w_1$ in the next iteration of training.

Scaling Challenges and the Path Forward
While this detailed derivation for $w_1$ provides a complete understanding of how a single gradient is computed, it also underscores the immense challenge for a network with seven parameters, let alone the millions or billions found in modern LLMs. Manually repeating this intricate process for every weight and bias would be computationally prohibitive and prone to error.
This is precisely why the full backpropagation algorithm is not merely about individual partial derivatives but about an organized, systematic way to compute all gradients efficiently. Backpropagation cleverly reuses intermediate calculations as it propagates error signals backward through the network, from the output layer towards the input layer. This algorithmic efficiency, built entirely upon the chain rule, allows deep learning models to learn from vast amounts of data without requiring an individual, explicit derivation for each parameter.
Broader Impact and Future Directions
The mastery of backpropagation has propelled AI into an era of unprecedented capability, transforming industries and societal functions. From enabling natural conversations with generative AI to enhancing medical diagnostics and powering complex scientific simulations, its impact is profound. Yet, research continues to explore new frontiers. Scientists are investigating alternatives or enhancements to traditional backpropagation, such as biologically plausible learning rules or more robust optimization techniques, to address challenges like vanishing/exploding gradients in very deep networks or the computational cost of training. Understanding the mathematical foundations laid by backpropagation remains crucial for anyone aspiring to contribute to these evolving fields. The journey of deep learning is one of continuous refinement, but its core principles, rooted in calculus and efficient computation, endure.







