Backpropagation Explained for Beginners (Part 2): There Has to Be a Better Way

backpropagationbeginnerschain ruledeep learninggradient descentneural networkstraining

Welcome back! Let's continue our journey of understanding backpropagation in detail.

Let's briefly recall what we covered in Part 1 so far.


A Quick Recap

We first started trying to understand neural networks using a simple dataset.

Neural network diagram
Image by Author

In that process, we built a small neural network and understood how it makes predictions through forward propagation.

Forward propagation illustration
Image by Author

We then observed that the predicted values were far from the actual values, resulting in a large error. Now, we wanted to train this neural network to perform better.

By comparing it with simple linear regression, we observed that, in our neural network, the loss depends on seven parameters: w_1, w_2, w_3, w_4, b_1, b_2, b_3.

Our complete loss function looked like this:

L(w_1,w_2,w_3,w_4,b_1,b_2,b_3) = \frac{1}{n} \sum_{i=1}^{n} \left( y_i - \left( w_3 \text{ReLU}(w_1 x_i + b_1) + w_4 \text{ReLU}(w_2 x_i + b_2) + b_3 \right) \right)^2

Next, just as we did in simple linear regression, we wanted to differentiate the loss with respect to each parameter. We started with w_1 and used the classical differentiation method, arriving at:

\frac{\partial L}{\partial w_1} = -\frac{2}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i) \, w_3 \, \text{ReLU}'(w_1 x_i + b_1) \, x_i


Do We Really Have to Repeat This?

Now it's time to think. We differentiated the loss with respect to w_1, meaning we were finding how the loss changes as w_1 changes. We used the classical differentiation method. However, we have six more parameters to differentiate with respect to. Do we need to proceed with the same method? No.


The Chain Rule to the Rescue

If you remember, we discussed the chain rule in Part 1. We used a simple example: y = x^2 and z = y^3. We noticed that z does not depend directly on x. Instead, the relationship looks like x \rightarrow y \rightarrow z. This means that when x changes, it first changes y, and the change in y then affects z. Since the chain rule efficiently captures such dependencies, we can apply it to our neural network to compute gradients without re-deriving each derivative from scratch. In the context of modern deep learning (2026), frameworks like TensorFlow and PyTorch automate this process using automatic differentiation, but understanding the chain rule remains fundamental for debugging and optimizing models.

via Towards Data Science

Related