Automationscribe.com
  • Home
  • AI Scribe
  • AI Tools
  • Artificial Intelligence
  • Contact Us
No Result
View All Result
Automation Scribe
  • Home
  • AI Scribe
  • AI Tools
  • Artificial Intelligence
  • Contact Us
No Result
View All Result
Automationscribe.com
No Result
View All Result

Backpropagation Defined for Freshmen (Half 1): Constructing the Instinct

admin by admin
July 19, 2026
in Artificial Intelligence
0
Backpropagation Defined for Freshmen (Half 1): Constructing the Instinct
399
SHARES
2.3k
VIEWS
Share on FacebookShare on Twitter


to know backpropagation?

In case you’re making an attempt to know how trendy AI programs like giant language fashions (LLMs) are skilled, backpropagation is likely one of the most essential ideas to know.

However in case you ask me how I felt once I encountered it, I used to be utterly misplaced by trying on the math equations. It felt like a psychological block for me.

I spotted and wished to begin from scratch and construct my understanding one step at a time.

That journey started with my earlier article, the place we constructed a neural community from scratch utilizing a easy dataset and understood the way it makes predictions.

The weblog acquired an ideal response. Thanks for that!

Now, let’s proceed with the identical method. We’ll break down backpropagation step-by-step, retaining it as easy and intuitive as earlier than.

Earlier than we start, I simply wish to say one factor. We’ll take this one step at a time.

Subjects like backpropagation can really feel overwhelming at first, however as soon as we construct a powerful basis, every part else turns into a lot simpler to know.

So, let’s get began.


Welcome again!

Let’s proceed our studying journey by means of deep studying.

We have already got a primary understanding of neural networks, which we explored utilizing a easy dataset within the earlier weblog.

Now, let’s first recall what we discovered within the earlier weblog on neural networks.

Fast Recap

We thought-about this straightforward dataset.

Picture by Creator

After plotting the info, it regarded like this:

Picture by Creator

We noticed {that a} single line was not sufficient to suit it. So, we determined to resolve it utilizing neural networks.

Subsequent, we obtained to know in regards to the equation of a single neuron, and after that, we discovered in regards to the completely different layers in a neural community.

For simplicity, we thought-about one hidden layer with two hidden neurons.

Subsequent, we noticed how the 2 hidden neurons produced two completely different linear transformations, after which we wished to mix them within the output layer.

Nevertheless, we came upon that combining two strains produced one other line, not the curve that would match the info.

That is the place we realized the importance of activation capabilities, as they introduce non-linearity into the mannequin.

So, we handed the outputs from the hidden neurons by means of the activation operate (ReLU) after which mixed them within the output layer.

In different phrases, we took the linear mixture of the outputs from the activation operate within the output layer, and eventually, we obtained the curve.

Picture by Creator

Within the earlier weblog we constructed the neural community structure and noticed the way it makes predictions by means of ahead propagation.

Picture by Creator

Earlier than we learn the way backpropagation works, let’s first have a look at the values produced at every layer through the ahead move which we mentioned in earlier weblog.

We’ll use these values all through the weblog to know how the community learns by updating its parameters.

Picture by Creator

Why Does the Community Must Be taught?

Once we have a look at the ultimate curve produced by our neural community, we will see that it’s not a superb match.

For instance, when the hours studied (x) is 1, the precise examination rating is 55, however our neural community predicts it as 28, which is a large distinction.

Now, we have to make our neural community carry out higher, which suggests it ought to predict values which can be a lot nearer to the precise examination scores.

To do this, the neural community must study. By studying, we imply determining which parameters must be elevated and which must be decreased to scale back the loss.


Studying from a Acquainted Instance

Now, how can we do that?

At this level, we don’t understand how to do this.

Let’s do one factor. Let’s proceed with what we already know.

However what will we already know?

We have already got an thought about easy linear regression, how the loss is calculated, and the way the bowl curve seems.

Possibly we will study one thing from it.

In easy linear regression, we have to discover the optimum values for β0 (intercept) and β1 (slope).

After all, we have already got formulation, however we additionally derived them ourselves.

What we did was plot a graph with three axes. One axis represented (β0), the second represented (β1), and the third represented the loss.

We plotted the loss values for various (β0) and (β1) values and noticed a bowl-shaped curve.

We then understood that the minimal loss happens on the backside of the curve, the place the slope of the loss floor turns into zero.

Picture by Creator

To search out that time, we used partial differentiation and ultimately solved the ensuing equations to acquire the formulation.

In easy linear regression, we will use completely different loss capabilities such because the Sum of Squared Errors (SSE), Imply Squared Error (MSE), or different appropriate loss capabilities relying on the issue.

Right here, we’ll contemplate the Imply Squared Error (MSE) as our loss operate.

For easy linear regression, the loss operate is

[
L(beta_0,beta_1)=frac{1}{n}sum_{i=1}^{n}left(y_i-hat{y}_iright)^2
]

the place

[
hat{y}_i=beta_0+beta_1x_i.
]

Discover that the loss relies upon solely on two parameters, [beta_0] and [beta_1]

Now we have to search out the values of [beta_0] and [beta_1] that decrease this loss.

Now, let’s have a look at our neural community.

Since our present drawback is a non-linear regression drawback, we will proceed utilizing the identical Imply Squared Error (MSE).

The loss operate can now be written as

[
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-hat{y}_iright)^2.
]

Nevertheless, not like easy linear regression, our prediction is now not given by

[
hat{y}=beta_0+beta_1x.
]

As a substitute, it’s produced by the complete neural community.

For our neural community,

[
hat{y}_i
=
w_3,mathrm{ReLU}(w_1x_i+b_1)
+
w_4,mathrm{ReLU}(w_2x_i+b_2)
+
b_3.
]

In consequence, the loss now not relies on simply two parameters. It now relies on all seven parameters of the neural community, that are [w_1,w_2,w_3,w_4,b_1,b_2,b_3]

Identical to in easy linear regression, our aim continues to be the identical: discover the values of those parameters that decrease the loss.

To attain that, we have to perceive how the loss modifications once we change every parameter individually whereas retaining the remaining parameters fastened.

In different phrases, we have to compute partial derivatives resembling

[
frac{partial L}{partial w_1},
quad
frac{partial L}{partial w_2},
quad
frac{partial L}{partial w_3},
quad
ldots,
quad
frac{partial L}{partial b_3}.
]

These partial derivatives inform us how delicate the loss is to every parameter and assist us decide whether or not that parameter must be elevated or decreased to scale back the loss.


Setting the Objective

In easy linear regression, once we plot the loss values for various combos of the slope and intercept, we get a bowl-shaped curve in three-dimensional area.

For our neural community, nonetheless, we can’t visualize the loss floor in the identical method as a result of it now exists in eight-dimensional area.

Though we will’t visualize it, our goal stays the identical which is to search out the parameter values that decrease the loss.


Time to Perceive Chain Rule

Now, primarily based on what we already know from easy linear regression, we discovered a method to proceed additional, which is to compute the partial derivatives of the loss with respect to every parameter.

The parameters are

[w_1,w_2,w_3,w_4,b_1,b_2,b_3]

However earlier than we proceed, there’s one essential idea that we have to perceive, and that’s the chain rule as a result of it’s the basis of every part we’re going to do subsequent.

The chain rule is used every time one amount relies on one other amount, which in flip relies on one other amount.

Let’s perceive this with a easy instance.

Suppose

[
y=x^2
]

and

[
z=y^3
]

Now, we wish to discover

[
frac{dz}{dx}
]

First, let’s discover this spinoff utilizing classical differentiation.

Discover that [z] is written when it comes to [y] not [x] Since we would like the spinoff with respect to [x] we will first remove the intermediate variable by substituting [y=x^2] into the equation for [z]

Substituting,

[
z=(x^2)^3=x^6
]

Now the expression relies upon solely on [x] so we will differentiate it instantly.

Utilizing the ability rule,

[
frac{dz}{dx}
=
frac{d}{dx}(x^6)
=
6x^5
]

This methodology may be straightforward for easy issues like this one as a result of we will simply substitute one expression into one other.

Nevertheless, think about a a lot larger expression with a number of intermediate variables.

Rewriting the complete equation earlier than differentiating would turn into troublesome and there’s a increased probability for errors.

As a substitute of mixing every part right into a single expression first, we now have a way more systematic method referred to as the chain rule.

As a substitute of eliminating the intermediate variables, with the chain rule we will work by means of them one step at a time.

Let’s see how we will implement chain rule.

We already know that, [frac{dz}{dx}] tells us how a lot [z] modifications once we make a really small change in [x]

Right here [z] doesn’t rely instantly on [x]

As a substitute, the connection seems like this:

[
x rightarrow y rightarrow z.
]

Which means that every time [x] modifications, it first modifications [y] and that change in [y] then modifications [z]

Now as an alternative of making an attempt to distinguish every part without delay, the chain rule tells us to interrupt the issue into smaller items.

[
frac{dz}{dx}=frac{dz}{dy}timesfrac{dy}{dx}
]

Now let’s calculate every half individually.

Since

[
z=y^3,
]

we get

[
frac{dz}{dy}=3y^2.
]

Equally, since

[
y=x^2,
]

we get

[
frac{dy}{dx}=2x.
]

Multiplying these collectively,

[
frac{dz}{dx}=3y^2times2x.
]

Lastly, we all know that

[
y=x^2,
]

so we substitute it again into the equation.

[
frac{dz}{dx}=3(x^2)^2times2x=6x^5.
]

The essential factor we will observe right here is that we by no means differentiated the complete expression at a time.

As a substitute, we broke it into smaller derivatives, solved them one after the other, after which multiplied them collectively.

We’ll use precisely the identical thought in our neural community.

The one distinction is that the chain is now slightly longer.


Fixing step-by-step utilizing Classical Differentiation Technique

Now that we perceive the chain rule, let’s proceed to calculate the partial derivatives with respect to every parameter.

Till now, we used particular values for the weights and biases to know how the ahead move works. Nevertheless, our goal is to study these values from the info.

So, as an alternative of utilizing fastened values, let’s symbolize them utilizing parameters first.

The output of our neural community is given by

[
hat{y}=w_3a_1+w_4a_2+b_3
]

the place

[
a_1=mathrm{ReLU}(z_1)
]
[
z_1=w_1x+b_1
]

and

[
a_2=mathrm{ReLU}(z_2)
]
[
z_2=w_2x+b_2
]

Utilizing this output, we will calculate the Imply Squared Error (MSE), which is the loss operate of our neural community.

The final MSE equation is

[
L(w_1,w_2,w_3,w_4,b_1,b_2,b_3)=frac{1}{n}sum_{i=1}^{n}(y_i-hat{y}_i)^2
]

Now, let’s substitute the prediction equation into the loss operate.

[
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_3a_{1i}+w_4a_{2i}+b_3right)right)^2
]

Since

[
a_{1i}=mathrm{ReLU}(w_1x_i+b_1)
]

and

[
a_{2i}=mathrm{ReLU}(w_2x_i+b_2)
]

the whole loss operate turns into

[
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_3mathrm{ReLU}(w_1x_i+b_1)+w_4mathrm{ReLU}(w_2x_i+b_2)+b_3right)right)^2
]

Now, let’s begin discovering the partial spinoff with respect to any one of many parameters, let’s start with

[w_1]

So, we now have to calculate

[
frac{partial}{partial w_1}left[frac{1}{n}sum_{i=1}^{n}left(y_i-left(w_3,mathrm{ReLU}(w_1x_i+b_1)+w_4,mathrm{ReLU}(w_2x_i+b_2)+b_3right)right)^2right]
]

This equation appears troublesome to resolve. How can we discover the partial spinoff with respect to

[w_1]

from such a big equation?

Let’s proceed utilizing the identical concepts from differentiation that we already know.

As a substitute of differentiating every part without delay, we’ll simplify the issue step-by-step.

We wish to compute

[
frac{partial L}{partial w_1}
]

Substitute the loss operate into the spinoff.

[
frac{partial L}{partial w_1}
=
frac{partial}{partial w_1}
left(
frac{1}{n}
sum_{i=1}^{n}
(y_i-hat{y}_i)^2
right)
]

Discover that we don’t substitute the complete expression for

[hat{y}_i]

but. We’ll try this solely when it turns into crucial.

As [frac{1}{n}] is a continuing, we all know that it may be moved outdoors the spinoff.

[
frac{partial L}{partial w_1}
=
frac{1}{n}
frac{partial}{partial w_1}
left(
sum_{i=1}^{n}
(y_i-hat{y}_i)^2
right)
]

The summation can also be linear, so the spinoff can move by means of it.

What will we imply by that?

It means in summation we add many phrases collectively and we will differentiate every time period individually after which add the derivatives.

[
frac{partial L}{partial w_1}
=
frac{1}{n}
sum_{i=1}^{n}
frac{partial}{partial w_1}
left(
(y_i-hat{y}_i)^2
right)
]

Now Differentiate the Sq.

Let

[
A=y_i-hat{y}_i
]

Then

[
frac{partial L}{partial w_1}
=
frac{1}{n}
sum_{i=1}^{n}
frac{partial}{partial w_1}(A^2)
]

Utilizing the ability rule,

[
frac{partial}{partial w_1}(A^2)
=
2A
frac{partial A}{partial w_1}
]

Substitute this into the earlier equation.

[
frac{partial L}{partial w_1}
=
frac{2}{n}
sum_{i=1}^{n}
A
frac{partial A}{partial w_1}
]

Substitute [A] with [y_i-hat{y}_i].

[
frac{partial L}{partial w_1}
=
frac{2}{n}
sum_{i=1}^{n}
(y_i-hat{y}_i)
frac{partial}{partial w_1}
(y_i-hat{y}_i)
]

Differentiate the Expression Inside

We all know that the true goal (precise commentary) [y_i] is a continuing,

[
frac{partial y_i}{partial w_1}=0
]

Subsequently,

[
frac{partial}{partial w_1}
(y_i-hat{y}_i)
=
-frac{partialhat{y}_i}{partial w_1}
]

Substitute this again.

[
frac{partial L}{partial w_1}
=
-frac{2}{n}
sum_{i=1}^{n}
(y_i-hat{y}_i)
frac{partialhat{y}_i}{partial w_1}
]

Now Differentiating the Prediction [frac{partialhat{y}_i}{partial w_1}
]

We all know that from the output layer in our neural community

[
hat{y}_i
=
w_3a_{1i}
+
w_4a_{2i}
+
b_3
]

Substitute the equations of hidden neuron activation capabilities.

[
hat{y}_i
=
w_3mathrm{ReLU}(w_1x_i+b_1)
+
w_4mathrm{ReLU}(w_2x_i+b_2)
+
b_3
]

Differentiate with respect to [w_1]

[
frac{partialhat{y}_i}{partial w_1}
=
frac{partial}{partial w_1}
left(
w_3mathrm{ReLU}(w_1x_i+b_1)
+
w_4mathrm{ReLU}(w_2x_i+b_2)
+
b_3
right)
]

Differentiating every time period individually.

As [w_3] is fixed,

[
frac{partial}{partial w_1}
left(
w_3mathrm{ReLU}(w_1x_i+b_1)
right)
=
w_3
frac{partial}{partial w_1}
mathrm{ReLU}(w_1x_i+b_1)
]

The second time period incorporates solely [w_2] so

[
frac{partial}{partial w_1}
left(
w_4mathrm{ReLU}(w_2x_i+b_2)
right)
=0
]

Additionally,

[
frac{partial b_3}{partial w_1}=0
]

Therefore,

[
frac{partialhat{y}_i}{partial w_1}
=
w_3
frac{partial}{partial w_1}
mathrm{ReLU}(w_1x_i+b_1)
]

Differentiate the ReLU Expression

Let

[
u=w_1x_i+b_1
]

Then

[
mathrm{ReLU}(w_1x_i+b_1)
=
mathrm{ReLU}(u)
]

Now Differentiating

[
u=w_1x_i+b_1
]

with respect to [w_1]

[
frac{du}{dw_1}=x_i
]

Now differentiate the activation.

[
frac{d,mathrm{ReLU}(u)}{du}
=
mathrm{ReLU}'(u)
]

Right here we use the chain rule,

[
frac{partial}{partial w_1}
mathrm{ReLU}(w_1x_i+b_1)
=
mathrm{ReLU}'(u)
frac{du}{dw_1}
]

Substituting [frac{du}{dw_1}=x_i]

[
frac{partial}{partial w_1}
mathrm{ReLU}(w_1x_i+b_1)
=
mathrm{ReLU}'(u)x_i
]

Changing [u]

[
frac{partial}{partial w_1}
mathrm{ReLU}(w_1x_i+b_1)
=
mathrm{ReLU}'(w_1x_i+b_1)x_i
]

This ReLU derivation may get complicated, let’s decelerate and see what we really did right here.

We all know that the ReLU activation doesn’t depend upon w1w_1 instantly.

It relies on the worth of w1xi+b1w_1x_i+b_1​.

On the identical time, the expression w1xi+b1w_1x_i+b_1​ relies on w1w_1​.

So when w1w_1 modifications, it first modifications w1xi+b1w_1x_i+b_1, which in flip modifications the output of the ReLU.

That is precisely the sort of state of affairs the place we use the chain rule.

So to search out how the ReLU modifications with respect to w1w_1​, we first discover how w1xi+b1w_1x_i+b_1 modifications with respect to w1w_1, after which how the ReLU modifications with respect to w1xi+b1w_1x_i+b_1​.

Lastly, we mix these two outcomes utilizing the chain rule.


Now Substitute Again

Earlier, we discovered

[
frac{partial L}{partial w_1}
=
-frac{2}{n}
sum_{i=1}^{n}
(y_i-hat{y}_i)
frac{partialhat{y}_i}{partial w_1}
]

We additionally calculated

[
frac{partialhat{y}_i}{partial w_1}
=
w_3
mathrm{ReLU}'(w_1x_i+b_1)
x_i
]

Substitute this into the earlier equation.

[
frac{partial L}{partial w_1}
=
-frac{2}{n}
sum_{i=1}^{n}
(y_i-hat{y}_i)
w_3
mathrm{ReLU}'(w_1x_i+b_1)
x_i
]

Last end result

Now we have derived

[
frac{partial L}{partial w_1}
=
-frac{2}{n}
sum_{i=1}^{n}
(y_i-hat{y}_i)
w_3
mathrm{ReLU}'(w_1x_i+b_1)
x_i
]

This tells us precisely how the loss modifications when the load

[w_1]

modifications.

At first, this equation could look obscure, however it’s really fairly easy.

Because it tells us how the whole loss modifications once we make a really small change to the load w1​, this worth is known as the gradient, and it’s precisely what gradient descent makes use of to replace the load.

To calculate this gradient, the equation considers each coaching instance within the dataset.

For every coaching instance:

[(y_i-hat{y}_i)] tells us how far the prediction is from the precise worth.

[w_3] tells us how a lot the primary hidden neuron contributes to the ultimate prediction.

[mathrm{ReLU}'(w_1x_i+b_1)] tells us whether or not the change in [w_1] can move by means of the ReLU activation.

[x_i] tells us how a lot a small change in [w_1] impacts the neuron’s enter.

Every coaching instance contributes its personal gradient primarily based on these portions.

We add all of those particular person contributions collectively, and since we’re utilizing the Imply Squared Error (MSE) loss operate, dividing by nn offers the common gradient throughout the complete dataset.

This common gradient tells us how w1w_1 must be adjusted to scale back the general loss, relatively than simply the error for a single coaching instance.

Conclusion

In case you bear in mind our dialogue on Easy Linear Regression, we calculated the partial derivatives with respect to solely two parameters.

On this weblog, we now have efficiently derived

[frac{partial L}{partial w_1}]

Though the derivation was lengthy, We used the identical concepts from calculus that we already knew in each step.

We merely utilized differentiation step-by-step and used the chain rule wherever it was required.

Now, our neural community nonetheless has six extra parameters, and every of them has its personal partial spinoff.

So, what do you suppose?

Do we have to repeat this whole course of for each weight and bias?

Thankfully, no.

As neural networks turn into bigger, manually deriving each gradient would rapidly turn into arduous and inefficient.

There must be a greater method.

The excellent news is that we don’t want any new arithmetic.

We merely want a greater method to set up these calculations.

All the things continues to be constructed on the identical chain rule we’ve been utilizing all through this text.

Within the subsequent half, we’ll see how the chain rule may be utilized effectively throughout the complete neural community, main us to some of the essential algorithms in deep studying: backpropagation.


I hope you discovered one thing from this text. In case you’re nonetheless confused about neural networks or wish to revisit the fundamentals, you possibly can all the time learn my earlier article right here.

In case you discovered this useful, be happy to share it with individuals who might have it.

In case you’ve gotten any doubts or ideas, you possibly can touch upon LinkedIn.

“It doesn’t matter how slowly you go so long as you don’t cease.”
— Confucius

Thanks for studying, and I’ll see you in Half 2!

Tags: BackpropagationBeginnersBuildingExplainedIntuitionPart
Previous Post

How Smartsheet constructed a distant MCP server on AWS

Next Post

Introducing Grok on Amazon Bedrock

Next Post
Introducing Grok on Amazon Bedrock

Introducing Grok on Amazon Bedrock

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Popular News

  • Greatest practices for Amazon SageMaker HyperPod activity governance

    Greatest practices for Amazon SageMaker HyperPod activity governance

    405 shares
    Share 162 Tweet 101
  • How Cursor Really Indexes Your Codebase

    405 shares
    Share 162 Tweet 101
  • Construct a serverless audio summarization resolution with Amazon Bedrock and Whisper

    404 shares
    Share 162 Tweet 101
  • Context Engineering — A Complete Fingers-On Tutorial with DSPy

    403 shares
    Share 161 Tweet 101
  • Speed up edge AI improvement with SiMa.ai Edgematic with a seamless AWS integration

    403 shares
    Share 161 Tweet 101

About Us

Automation Scribe is your go-to site for easy-to-understand Artificial Intelligence (AI) articles. Discover insights on AI tools, AI Scribe, and more. Stay updated with the latest advancements in AI technology. Dive into the world of automation with simplified explanations and informative content. Visit us today!

Category

  • AI Scribe
  • AI Tools
  • Artificial Intelligence

Recent Posts

  • Loop Engineering for RAG Query Parsing: The Small Loop That Runs Earlier than Retrieval
  • Introducing Grok on Amazon Bedrock
  • Backpropagation Defined for Freshmen (Half 1): Constructing the Instinct
  • Home
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms & Conditions

© 2024 automationscribe.com. All rights reserved.

No Result
View All Result
  • Home
  • AI Scribe
  • AI Tools
  • Artificial Intelligence
  • Contact Us

© 2024 automationscribe.com. All rights reserved.