Clase 4 Backpropagation
Clase 4 Backpropagation
(Backpropagation)
Deisy Chaves
Oficina 10, 4rto Piso, Edificio B13
[email protected]
Contenido
Artificial neuron
• Input features, xj
• Weights, wi 𝑥1 𝜔1 𝑏 Bias
• Bias
Activation function
1 𝑠𝑖 𝑧 ≥ 0 1
𝜎(𝑧) = ቊ 𝜎(𝑧) =
0 𝑠𝑖 𝑧 < 0 1 + 𝑒 −𝑧
Artificial neuron
• Weights, wi
𝑥1 𝜔1 𝑏 Bias
• Weighted sum (linear function):
w1·x1+ w2·x2 + ... + wn·xn +b =Z
𝑥2 𝜔2
⋮
∑ 𝑦ො
⋮
• Activation function, : Activation Output
ො (w1·x1+ w2·x2 + ... + wn·xn +b)
𝑦= 𝑥𝑚 𝜔𝑚 Weighted
sum
1 Inputs Weights
(𝑧) =
1 + 𝑒 −𝑧
• Bias
Backpropagation
• Introduced in the 1970s
• Method for fine-tuning the weights (training) of a neural network (Perceptron,
MLP,…) with respect to the error rate obtained in the previous iteration or epoch
Backpropagation
• The error -loss function- of
model output compared to the
true values is calculated to
evaluate the model
https://machinelearningknowledge.ai/wp-content/uploads/2019/10/Backpropagation.gif
Backpropagation: Gradient descent
• The gradient of a function at a
specific point is the direction
Loss function (L) vs Weight (w) of the steepest ascent
https://datamapu.com/posts/deep_learning/intro_dl/
Backpropagation: example
1
• Activation Function: Sigmoid function (𝑧) = 1 + 𝑒 −𝑧
1
• Activation Function: Sigmoid function (𝑧) = 1 + 𝑒 −𝑧
• Activation function:
1
a = (𝑧) =
1 + 𝑒 −𝑧
1 1
ො a = (z) =
• Output: 𝑦= =
1+𝑒 −𝑧 1+𝑒 −(𝑤𝑥+𝑏)
Backpropagation: one neuron
• Input features, x
• Weights, w (initial w =0.3)
• Bias, b (initial b =0.1)
• Weighted sum (linear function):
Z(x) = w·x+b
• Activation function:
1
a = (𝑧) =
1 + 𝑒 −𝑧
1 1
ො a = (z) =
• Output: 𝑦= =
1+𝑒 −𝑧 1+𝑒 −(𝑤𝑥+𝑏)
Backpropagation: one neuron
• Forward pass
ො a = (z)
𝑦=
ො (w·x+b)
𝑦=
1
𝑦ො =
1 + 𝑒 −(𝑤𝑥+𝑏)
1
L(y,ොy) = (y − yො )2
2
• Forward pass
ො a = (z)
𝑦=
ො (w·x+b)
𝑦=
1
𝑦ො = =0.56
1+𝑒 −(𝑤𝑥+𝑏)
1 1
L(y,ොy) = 2 (y − yො )2 = 2 (1.5 − 0.56)2 = 0.44
• Input features, x
• Weights, w (initial w(1) =0.3, w(2) =0.2)
• Bias, b (initial b(1) =0.1, b(2) =0.4)
• Weighted sum (linear function):
Z(x) = w·x+b
• Activation function:
1
a = (𝑧) =
1 + 𝑒 −𝑧
1 1
ො a = (z) =
• Output: 𝑦= =
1+𝑒 −𝑧 1+𝑒 −(𝑤𝑥+𝑏)
Backpropagation: two neuron
• Forward pass
ො a(3) = (z (3))
𝑦=
1
(z) =
1+𝑒 −𝑧
1
L(y,ොy) = (y − yො )2
2
• Forward pass
• Forward pass
• Forward pass
ො a(3) = (z (3)) = 0.625
𝑦=
𝟏
ෝ)𝟐
ො = (y − 𝒚
L(y,𝐲)
𝟐
• Forward pass
ො a(3) = (z (3)) = 0.625
𝑦=
𝟏
ො =
L(y,𝐲) ෝ)𝟐
(y − 𝒚
𝟐
1
L(y,ොy) = (1.5 − 0.625)2 = 0.38
2
Training sample (x =0.5, y=1.5)
Weights, w (initial w(1) =0.3, w(2) =0.2)
Bias, b (initial b(1) =0.1, b(2) =0.4)
Learning rate, = 0.1
Backpropagation: two neuron
• Backward pass
• Backward pass
We need to update the
model parameters
• Backward pass
The calculations for w(2) and
b(2) are similar to the ones in
the first example
• Backward pass
The calculations for w(2) and
b(2) are similar to the ones in
the first example
• Backward pass
The calculations for w(2) and
b(2) are similar to the ones in
the first example
• Backward pass
Calculations for w(1) and b(1)
• Backward pass
Calculations for w(1) and b(1)
• Backward pass
Calculations for w(1) and b(1)
• Input features, x
• Weights, w (initial w(1) =0.3, w(2) =0.2,…)
• Bias, b (initial b(1) =[b1(1), b2(1)], b(2) =[b1(2), b2(2)],
• Forward pass
In this case, consider the sum of the two
neurons in the layer
Backpropagation: Two Neurons in a layer
• Forward pass
In this case, consider the sum of the two
neurons in the layer
Backpropagation: Two Neurons in a layer
• Forward pass
In this case, consider the sum of the two
neurons in the layer
Backpropagation: Two Neurons in a layer
• Backward pass
In this case, it is necesary to update
Backpropagation: Two Neurons in a layer
• Backward pass
For the parameters of the first layer
Backpropagation: Two Neurons in a layer
• Backward pass
For the parameters of the first layer
Example: implementation of backpropagation
Example adapt from:
• https://github.com/CodigoMaquina/code/blob/main/machine_learning_python/ba
ckpropagation_paso_a_paso.ipynb
• https://www.youtube.com/watch?v=iOsR-EC9z6I
Backpropagation: limitations & challenges
• Data quality: poor data quality, including noise, incompleteness, or bias,
can lead to inaccurate models, as backpropagation learns exactly what it
is given
m
Accelerating learning
GD SGD Mini-Batch SGD
Slides adapts from Lecture 6: “Optimization for Deep Neural Networks CMSC
35246: Deep Learning”