Professional Documents
Culture Documents
Workings of Neural Networks
Workings of Neural Networks
Neural Networks
784 pixels
784 pixels
...
...
0 1 2 9
0 1 2 ... 9
Input
Output
Number of weights
Hidden Layer
Input
Output
2*1
2*3
Math of Neural Networks
Requirement Data
x1 x2 y
1 2 3
Let’s understand how Model will use input features (x 1, x2) and learn to predict y
Hidden Layer
Input
Output
W111 =0.5
Output
W111 =0.5
Output
2
h11 = 1 * 0.5 + 2 * 0.3 + 1
W111 =0.5
Output
Initializing each weight with random numbers and bias with 1 (can be any number)
h11
Output
2
h11
o11 = sigmoid(h11)
W111 =0.5 2.1
Output
o11 = 0.89
W111 =0.5 2.1
Output
2
h11
o11 = 0.89
W111 = 0.5 2.1
Output
h21
W121 = 0.15
1 o12 = 0.875
1.95
W122 = 0.4
2
o11 = 0.89
W111 = 0.5 2.1
Output
h21
W121 = 0.15
1 o12 = 0.875
1.95
W122 = 0.4
2
W
13
1 =0 h13
. 65
1.05
W132 = -0.3 o13 = 0.741
o11 = 0.89
W111 = 0.5 2.1
W122 = 0.4
2 56
0.
3
=-
W 21
W
13
1 =0 h13
. 65
1.05
W132 = -0.3 o13 = 0.741
Initialize weights and bias for output layer and calculate output
h11
o11 = 0.89
W111 = 0.5 2.1
W122 = 0.4
2 56
0.
3
=-
W 21
W
13
1 =0 h13
. 65
1.05
W132 = -0.3 o13 = 0.741
What’s next?
h11
o11 = 0.89
W111 = 0.5 2.1
1.05
W132 = -0.3 o13 = 0.741
Calculate Loss
h11
o11 = 0.89
W111 = 0.5 2.1
1.05
W132 = -0.3 o13 = 0.741
o11 = 0.89
W111 = 0.5 2.1
W
21
1 = Output
h21 -0. Loss
2 3
W121 = 0.15
1 o12 = 0.875 W212 = 0.83
1.95 1.106 1.793
W122 = 0.4
2 56
0.
3
=-
W 21
W
13
1 =0 h13
. 65
1.05
W132 = -0.3 o13 = 0.741
Calculate Gradient for Loss w.r.t each Weight and Bias in the Neural Network
h11
o11 = 0.89
W111 = 0.5 2.1
W
21
1 = Output
h21 -0. Loss
2 3
W121 = 0.15
1 o12 = 0.875 W212 = 0.83
1.95 1.106 1.793
W122 = 0.4
2 56
0.
3
=-
W 21
W
13
1 =0 h13
. 65
1.05
W132 = -0.3 o13 = 0.741
o11 = 0.89
W111 = 0.5 2.1
W
21
1 = Output
h21 -0. Loss
2 3
W121 = 0.15
1 o12 = 0.875 W212 = 0.83
1.95 1.106 1.793
W122 = 0.4
2 56
0.
3
=-
W 21
W
13
1 =0 h13
. 65
1.05
W132 = -0.3 o13 = 0.741
= -1.686
= -0.213
Calculate both in same way as W211
h11
o11 = 0.89
W111 = 0.5 2.1
1.05
W132 = -0.3 o13 = 0.741
o11 = 0.89
W111 = 0.5 2.1
1.05
W132 = -0.3 o13 = 0.741
NOTE!
= 0.0426
New value of w111
= 0.499