Back Propagation
Back Propagation
If you are building your own neural network, you will definitely need to
understand how to train it. Backpropagation is a commonly used technique
for training neural network. There are many resources explaining the
technique, but this post will explain backpropagation with concrete example
in a very detailed colorful steps.
Overview
Our dataset has one sample with two inputs and one output.
Forward Pass
We will use given weights and inputs to predict the output. Inputs are
multiplied by weights; the results are then passed forward to next layer.
Calculating Error
Now, it’s time to find out how our network performed by calculating the
difference between the actual output and predicted one. It’s clear that our
network output, or prediction, is not even close to actual output. We can
calculate the difference or the error as following.
Reducing Error
Our main goal of the training is to reduce the error or the difference
between prediction and actual output. Since actual output is constant,
“not changing”, the only way to reduce the error is to
change prediction value. The question now is, how to
change prediction value?
For example, to update w6, we take the current w6 and subtract the partial
derivative of error function with respect to w6. Optionally, we multiply the
derivative of the error function by a selected number to make sure that the
new updated weight is minimizing the error function; this number is
called learning rate.
The derivation of the error function is evaluated by applying the chain rule
as following
We can find the update formula for the remaining weights w2, w3 and w4 in the same way.
Learning rate: is a hyper parameter which means that we need to manually guess its value.
Now, using the new weights we will repeat the forward passed
We can notice that the prediction 0.26 is a little bit closer to actual output than the previously
predicted one 0.191. We can repeat the same process of backward and forward pass
until error is close or equal to zero.
Backpropagation Visualization
You can see visualization of the forward pass and backpropagation here.