lecture 2: learning with neural networks - uva deep learning … ·  · 2016-12-17o machine...

94
Lecture 2: Learning with neural networks Deep Learning @ UvA UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLING LEARNING WITH NEURAL NETWORKS - PAGE 1

Upload: trinhanh

Post on 10-Apr-2018

246 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Lecture 2: Learning with neural networksDeep Learning @ UvA

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLING LEARNING WITH NEURAL NETWORKS - PAGE 1

Page 2: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Machine Learning Paradigm for Neural Networks

o The Backpropagation algorithm for learning with a neural network

o Neural Networks as modular architectures

o Various Neural Network modules

o How to implement and check your very own module

Lecture Overview

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGINTRODUCTION ON DEEP LEARNING AND NEURAL NETWORKS - PAGE 2

Page 3: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

The Machine Learning Paradigm

UVA DEEP LEARNING COURSEEFSTRATIOS GAVVES & MAX WELLING

OPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 3

Page 4: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Collect annotated data

o Define model and initialize randomly

o Predict based on current model◦ In neural network jargon “forward propagation”

o Evaluate predictions

Forward computations

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 4

Model

ℎ(𝑥𝑖; 𝜗)

Objective/Loss/Cost/Energy

ℒ(𝜗; ෝ𝑦𝑖 , ℎ)

Score/Prediction/Output

ෝ𝑦𝑖 ∝ ℎ(𝑥𝑖; 𝜗)

𝑋Input:𝑌Targets:

Data

𝜗

(𝑦𝑖 − ෝ𝑦𝑖)2

Page 5: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Collect annotated data

o Define model and initialize randomly

o Predict based on current model◦ In neural network jargon “forward propagation”

o Evaluate predictions

Forward computations

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 5

Model

ℎ(𝑥𝑖; 𝜗)

Objective/Loss/Cost/Energy

ℒ(𝜗; ෝ𝑦𝑖 , ℎ)

Score/Prediction/Output

ෝ𝑦𝑖 ∝ ℎ(𝑥𝑖; 𝜗)

𝑋Input:𝑌Targets:

Data

𝜗

(𝑦𝑖 − ෝ𝑦𝑖)2

Page 6: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Collect annotated data

o Define model and initialize randomly

o Predict based on current model◦ In neural network jargon “forward propagation”

o Evaluate predictions

Forward computations

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 6

Model

ℎ(𝑥𝑖; 𝜗)

Objective/Loss/Cost/Energy

ℒ(𝜗; ෝ𝑦𝑖 , ℎ)

Score/Prediction/Output

ෝ𝑦𝑖 ∝ ℎ(𝑥𝑖; 𝜗)

𝑋Input:𝑌Targets:

Data

𝜗

(𝑦𝑖 − ෝ𝑦𝑖)2

Page 7: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Collect annotated data

o Define model and initialize randomly

o Predict based on current model◦ In neural network jargon “forward propagation”

o Evaluate predictions

Forward computations

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 7

Model

ℎ(𝑥𝑖; 𝜗)

Objective/Loss/Cost/Energy

ℒ(𝜗; ෝ𝑦𝑖 , ℎ)

Score/Prediction/Output

ෝ𝑦𝑖 ∝ ℎ(𝑥𝑖; 𝜗)

𝑋Input:𝑌Targets:

Data

𝜗

(𝑦𝑖 − ෝ𝑦𝑖)2

Page 8: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backward computations

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 8

o Collect gradient data

o Define model and initialize randomly

o Predict based on current model◦ In neural network jargon “backpropagation”

o Evaluate predictions Model Objective/Loss/Cost/EnergyScore/Prediction/Output

𝑋Input:𝑌Targets:

Data

= 1𝜗

ℒ( )

(𝑦𝑖 − ෝ𝑦𝑖)2

Page 9: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backward computations

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 9

o Collect gradient data

o Define model and initialize randomly

o Predict based on current model◦ In neural network jargon “backpropagation”

o Evaluate predictions Model Objective/Loss/Cost/EnergyScore/Prediction/Output

𝑋Input:𝑌Targets:

Data

= 1𝜗

𝜕ℒ(𝜗; ෝ𝑦𝑖)

𝜕 ෝ𝑦𝑖

Page 10: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backward computations

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 10

o Collect gradient data

o Define model and initialize randomly

o Predict based on current model◦ In neural network jargon “backpropagation”

o Evaluate predictions Model Objective/Loss/Cost/EnergyScore/Prediction/Output

𝑋Input:𝑌Targets:

Data

𝜗

𝜕ℒ(𝜗; ෝ𝑦𝑖)

𝜕 ෝ𝑦𝑖

𝜕 ෝ𝑦𝑖𝜕ℎ

Page 11: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backward computations

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 11

o Collect gradient data

o Define model and initialize randomly

o Predict based on current model◦ In neural network jargon “backpropagation”

o Evaluate predictions Model Objective/Loss/Cost/EnergyScore/Prediction/Output

𝑋Input:𝑌Targets:

Data

𝜗

𝜕ℒ(𝜗; ෝ𝑦𝑖)

𝜕 ෝ𝑦𝑖

𝜕 ෝ𝑦𝑖𝜕ℎ

𝜕ℎ(𝑥𝑖)

𝜕𝜃

Page 12: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backward computations

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 12

o Collect gradient data

o Define model and initialize randomly

o Predict based on current model◦ In neural network jargon “backpropagation”

o Evaluate predictions Model Objective/Loss/Cost/EnergyScore/Prediction/Output

𝑋Input:𝑌Targets:

Data

𝜗

𝜕ℒ(𝜗; ෝ𝑦𝑖)

𝜕 ෝ𝑦𝑖

𝜕 ෝ𝑦𝑖𝜕ℎ

𝜕ℎ(𝑥𝑖)

𝜕𝜃

Page 13: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o As with many model, we optimize our neural network with Gradient Descent𝜃(𝑡+1) = 𝜃(𝑡) − 𝜂𝑡𝛻𝜃ℒ

o The most important component in this formulation is the gradient

o Backpropagation to the rescue◦ The backward computations of network return the gradients

◦ How to make the backward computations

Optimization through Gradient Descent

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGLEARNING WITH NEURAL NETWORKS - PAGE 13

Page 14: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backpropagation

UVA DEEP LEARNING COURSEEFSTRATIOS GAVVES & MAX WELLING

OPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 14

Page 15: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o A family of parametric, non-linear and hierarchical representation learning functions, which are massively optimized with stochastic gradient descent to encode domain knowledge, i.e. domain invariances, stationarity.

o 𝑎𝐿 𝑥; 𝜃1,…,L = ℎ𝐿 (ℎ𝐿−1 …ℎ1 𝑥, θ1 , θ𝐿−1 , θ𝐿)◦ 𝑥:input, θ𝑙: parameters for layer l, 𝑎𝑙 = ℎ𝑙(𝑥, θ𝑙): (non-)linear function

o Given training corpus {𝑋, 𝑌} find optimal parameters

θ∗ ← argmin𝜃

(𝑥,𝑦)⊆(𝑋,𝑌)

ℓ(𝑦, 𝑎𝐿 𝑥; 𝜃1,…,L )

What is a neural network again?

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGINTRODUCTION ON NEURAL NETWORKS AND DEEP LEARNING - PAGE 15

Page 16: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o A neural network model is a series of hierarchically connected functions

o This hierarchies can be very, very complex

Neural network models

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 16

ℎ1 (𝑥

𝑖 ;𝜗)

ℎ2 (𝑥

𝑖 ;𝜗)

ℎ3 (𝑥

𝑖 ;𝜗)

ℎ4 (𝑥

𝑖 ;𝜗)

ℎ5 (𝑥

𝑖 ;𝜗)

𝐿𝑜𝑠𝑠

𝐼𝑛𝑝𝑢𝑡

Forward connections (Feedforward architecture)

Page 17: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o A neural network model is a series of hierarchically connected functions

o This hierarchies can be very, very complex

Neural network models

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 17

ℎ1(𝑥𝑖; 𝜗)

ℎ2(𝑥𝑖; 𝜗)

ℎ3(𝑥𝑖; 𝜗)

ℎ4(𝑥𝑖; 𝜗)

ℎ5(𝑥𝑖; 𝜗)

𝐿𝑜𝑠𝑠

𝐼𝑛𝑝𝑢𝑡

ℎ2(𝑥𝑖; 𝜗)

ℎ4(𝑥𝑖; 𝜗)

Interweaved connections(Directed Acyclic Grapharchitecture- DAGNN)

Page 18: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o A neural network model is a series of hierarchically connected functions

o This hierarchies can be very, very complex

Neural network models

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 18

ℎ1 (𝑥

𝑖 ;𝜗)

ℎ2 (𝑥

𝑖 ;𝜗)

ℎ3 (𝑥

𝑖 ;𝜗)

ℎ4 (𝑥

𝑖 ;𝜗)

ℎ5 (𝑥

𝑖 ;𝜗)

𝐿𝑜𝑠𝑠

𝐼𝑛𝑝𝑢𝑡

Loopy connections(Recurrent architecture, special care needed)

Page 19: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o A neural network model is a series of hierarchically connected functions

o This hierarchies can be very, very complex

Neural network models

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 19

ℎ1 (𝑥

𝑖 ;𝜗)

ℎ2 (𝑥

𝑖 ;𝜗)

ℎ3 (𝑥

𝑖 ;𝜗)

ℎ4 (𝑥

𝑖 ;𝜗)

ℎ5 (𝑥

𝑖 ;𝜗)

𝐿𝑜𝑠𝑠

𝐼𝑛𝑝𝑢𝑡

ℎ1(𝑥𝑖; 𝜗)

ℎ2(𝑥𝑖; 𝜗)

ℎ3(𝑥𝑖; 𝜗)

ℎ4(𝑥𝑖; 𝜗)

ℎ5(𝑥𝑖; 𝜗)

𝐿𝑜𝑠𝑠

𝐼𝑛𝑝𝑢𝑡

ℎ2(𝑥𝑖; 𝜗)

ℎ4(𝑥𝑖; 𝜗)

ℎ1 (𝑥

𝑖 ;𝜗)

ℎ2 (𝑥

𝑖 ;𝜗)

ℎ3 (𝑥

𝑖 ;𝜗)

ℎ4 (𝑥

𝑖 ;𝜗)

ℎ5 (𝑥

𝑖 ;𝜗)

𝐿𝑜𝑠𝑠

𝐼𝑛𝑝𝑢𝑡

𝐿𝑜𝑠𝑠𝐿𝑜𝑠𝑠

𝐿𝑜𝑠𝑠

Functions Modules

Page 20: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o A module is a building block for our network

o Each module is an object/function 𝑎 = ℎ(𝑥; 𝜃) that◦ Contains trainable parameters (𝜃)◦ Receives as an argument an input 𝑥◦ And returns an output 𝑎 based on the activation function ℎ …

o The activation function should be (at least)first order differentiable (almost) everywhere

o For easier/more efficient backpropagation storemodule input ◦ easy to get module output fast◦ easy to compute derivatives

What is a module?

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 20

ℎ1(𝑥1; 𝜃1)

ℎ2(𝑥2; 𝜃2)

ℎ3(𝑥3; 𝜃3)

ℎ4(𝑥4; 𝜃4)

ℎ5(𝑥5; 𝜃5)

𝐿𝑜𝑠𝑠

𝐼𝑛𝑝𝑢𝑡

ℎ2(𝑥2; 𝜃2)

ℎ5(𝑥5; 𝜃5)

Page 21: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o A neural network is a composition of modules (building blocks)

o Any architecture works

o If the architecture is a feedforward cascade, no special care

o If acyclic, there is right order of computing the forward computations

o If there are loops, these form recurrent connections (revisited later)

Anything goes or do special constraints exist?

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 21

Page 22: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Simply compute the activation of each module in the network

𝑎𝑙 = ℎ𝑙 𝑥𝑙; 𝜗 , where 𝑎𝑙 = 𝑥𝑙+1(or 𝑥𝑙 = 𝑎𝑙−1)

o We need to know the precise function behindeach module ℎ𝑙(… )

o Recursive operations◦ One module’s output is another’s input

o Steps◦ Visit modules one by one starting from the data input◦ Some modules might have several inputs from multiple modules

o Compute modules activations with the right order◦ Make sure all the inputs computed at the right time

Forward computations for neural networks

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 22

𝐿𝑜𝑠𝑠

𝑫𝒂𝒕𝒂 𝑰𝒏𝒑𝒖𝒕

ℎ1(𝑥1; 𝜃1)

ℎ2(𝑥2; 𝜃2)

ℎ3(𝑥3; 𝜃3)

ℎ4(𝑥4; 𝜃4)

ℎ5(𝑥5; 𝜃5)

ℎ2(𝑥2; 𝜃2)

ℎ5(𝑥5; 𝜃5)

Page 23: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Simply compute the gradients of each module for our data◦ We need to know the gradient formulation of each module𝜕ℎ𝑙(𝑥𝑙; 𝜃𝑙) w.r.t. their inputs 𝑥𝑙 and parameters 𝜃𝑙

o We need the forward computations first◦ Their result is the sum of losses for our input data

o Then take the reverse network (reverse connections)and traverse it backwards

o Instead of using the activation functions, we usetheir gradients

o The whole process can be described very neatly and conciselywith the backpropagation algorithm

Backward computations for neural networks

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 23

𝒅𝑳𝒐𝒔𝒔(𝑰𝒏𝒑𝒖𝒕)Data:

𝑑ℎ1(𝑥1; 𝜃1)

𝑑ℎ2(𝑥2; 𝜃2)

𝑑ℎ3(𝑥3; 𝜃3)

𝑑ℎ4(𝑥4; 𝜃4)

𝑑ℎ5(𝑥5; 𝜃5)

𝑑ℎ2(𝑥2; 𝜃2)

𝑑ℎ5(𝑥5; 𝜃5)

Page 24: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o 𝑎𝐿 𝑥; 𝜃1,…,L = ℎ𝐿 (ℎ𝐿−1 …ℎ1 𝑥, θ1 , θ𝐿−1 , θ𝐿)◦ 𝑥:input, θ𝑙: parameters for layer l, 𝑎𝑙 = ℎ𝑙(𝑥, θ𝑙): (non-)linear function

o Given training corpus {𝑋, 𝑌} find optimal parameters

θ∗ ← argmin𝜃

(𝑥,𝑦)⊆(𝑋,𝑌)

ℓ(𝑦, 𝑎𝐿 𝑥; 𝜃1,…,L )

o To use any gradient descent based optimization (𝜃(𝑡+1) = 𝜃(𝑡+1) − 𝜂𝑡𝜕ℒ

𝜕𝜃(𝑡)) we

need the gradients𝜕ℒ

𝜕𝜃𝑙, 𝑙 = 1, … , 𝐿

o How to compute the gradients for such a complicated function enclosing other functions, like 𝑎𝐿(… )?

Again, what is a neural network again?

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGINTRODUCTION ON NEURAL NETWORKS AND DEEP LEARNING - PAGE 24

Page 25: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Assume a nested function, 𝑧 = 𝑓 𝑦 and 𝑦 = 𝑔 𝑥

o Chain Rule for scalars 𝑥, 𝑦, 𝑧

◦𝑑𝑧

𝑑𝑥=

𝑑𝑧

𝑑𝑦

𝑑𝑦

𝑑𝑥

o When 𝑥 ∈ ℛ𝑚, 𝑦 ∈ ℛ𝑛, 𝑧 ∈ ℛ

◦𝑑𝑧

𝑑𝑥𝑖= σ𝑗

𝑑𝑧

𝑑𝑦𝑗

𝑑𝑦𝑗

𝑑𝑥𝑖 gradients from all possible paths

Chain rule

LEARNING WITH NEURAL NETWORKS - PAGE 25UVA DEEP LEARNING COURSE – EFSTRATIOS GAVVES & MAX WELLING

𝑧

𝑦(1) 𝑦(2)

𝑥(1) 𝑥(2) 𝑥(3)

Page 26: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Assume a nested function, 𝑧 = 𝑓 𝑦 and 𝑦 = 𝑔 𝑥

o Chain Rule for scalars 𝑥, 𝑦, 𝑧

◦𝑑𝑧

𝑑𝑥=

𝑑𝑧

𝑑𝑦

𝑑𝑦

𝑑𝑥

o When 𝑥 ∈ ℛ𝑚, 𝑦 ∈ ℛ𝑛, 𝑧 ∈ ℛ

◦𝑑𝑧

𝑑𝑥𝑖= σ𝑗

𝑑𝑧

𝑑𝑦𝑗𝑑𝑦𝑗

𝑑𝑥𝑖 gradients from all possible paths

Chain rule

LEARNING WITH NEURAL NETWORKS - PAGE 26UVA DEEP LEARNING COURSE – EFSTRATIOS GAVVES & MAX WELLING

𝑧

𝑦1 𝑦2

𝑥1 𝑥2 𝑥3

𝑑𝑧

𝑑𝑥1=

𝑑𝑧

𝑑𝑦1𝑑𝑦1

𝑑𝑥1+𝑑𝑧

𝑑𝑦2𝑑𝑦2

𝑑𝑥1

Page 27: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Assume a nested function, 𝑧 = 𝑓 𝑦 and 𝑦 = 𝑔 𝑥

o Chain Rule for scalars 𝑥, 𝑦, 𝑧

◦𝑑𝑧

𝑑𝑥=

𝑑𝑧

𝑑𝑦

𝑑𝑦

𝑑𝑥

o When 𝑥 ∈ ℛ𝑚, 𝑦 ∈ ℛ𝑛, 𝑧 ∈ ℛ

◦𝑑𝑧

𝑑𝑥𝑖= σ𝑗

𝑑𝑧

𝑑𝑦𝑗

𝑑𝑦𝑗

𝑑𝑥𝑖 gradients from all possible paths

Chain rule

LEARNING WITH NEURAL NETWORKS - PAGE 27UVA DEEP LEARNING COURSE – EFSTRATIOS GAVVES & MAX WELLING

𝑧

𝑦1 𝑦2

𝑥1 𝑥2 𝑥3

𝑑𝑧

𝑑𝑥2=

𝑑𝑧

𝑑𝑦1𝑑𝑦1

𝑑𝑥2+𝑑𝑧

𝑑𝑦2𝑑𝑦2

𝑑𝑥2

Page 28: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Assume a nested function, 𝑧 = 𝑓 𝑦 and 𝑦 = 𝑔 𝑥

o Chain Rule for scalars 𝑥, 𝑦, 𝑧

◦𝑑𝑧

𝑑𝑥=

𝑑𝑧

𝑑𝑦

𝑑𝑦

𝑑𝑥

o When 𝑥 ∈ ℛ𝑚, 𝑦 ∈ ℛ𝑛, 𝑧 ∈ ℛ

◦𝑑𝑧

𝑑𝑥𝑖= σ𝑗

𝑑𝑧

𝑑𝑦𝑗

𝑑𝑦𝑗

𝑑𝑥𝑖 gradients from all possible paths

Chain rule

LEARNING WITH NEURAL NETWORKS - PAGE 28UVA DEEP LEARNING COURSE – EFSTRATIOS GAVVES & MAX WELLING

𝑧

𝑦(1) 𝑦(2)

𝑥(1) 𝑥(2) 𝑥(3)

𝑑𝑧

𝑑𝑥3=

𝑑𝑧

𝑑𝑦1𝑑𝑦1

𝑑𝑥3+𝑑𝑧

𝑑𝑦2𝑑𝑦2

𝑑𝑥3

Page 29: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Assume a nested function, 𝑧 = 𝑓 𝑦 and 𝑦 = 𝑔 𝑥

o Chain Rule for scalars 𝑥, 𝑦, 𝑧

◦𝑑𝑧

𝑑𝑥=

𝑑𝑧

𝑑𝑦

𝑑𝑦

𝑑𝑥

o When 𝑥 ∈ ℛ𝑚, 𝑦 ∈ ℛ𝑛, 𝑧 ∈ ℛ

◦𝑑𝑧

𝑑𝑥𝑖= σ𝑗

𝑑𝑧

𝑑𝑦𝑗

𝑑𝑦𝑗

𝑑𝑥𝑖 gradients from all possible paths

◦ or in vector notation

𝑑𝑧

𝑑𝒙=

𝑑𝒚

𝑑𝒙

𝑇

⋅𝑑𝑧

𝑑𝑦

◦𝑑𝑦

𝑑𝑥is the Jacobian

Chain rule

LEARNING WITH NEURAL NETWORKS - PAGE 29UVA DEEP LEARNING COURSE – EFSTRATIOS GAVVES & MAX WELLING

𝑧

𝑦(1) 𝑦(2)

𝑥(1) 𝑥(2) 𝑥(3)

Page 30: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

The Jacobian

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGLEARNING WITH NEURAL NETWORKS - PAGE 30

o When 𝑥 ∈ ℛ3, 𝑦 ∈ ℛ2

𝐽 𝑦 𝑥 =𝑑𝒚

𝑑𝒙=

𝜕𝑦 1

𝜕𝑥 1

𝜕𝑦 1

𝜕𝑥 2

𝜕𝑦 1

𝜕𝑥 3

𝜕𝑦 2

𝜕𝑥 1

𝜕𝑦 2

𝜕𝑥 2

𝜕𝑦 2

𝜕𝑥 3

Page 31: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o f y = sin 𝑦 , 𝑦 = 𝑔 𝑥 = 0.5 𝑥2

𝑑𝑓

𝑑𝑥=𝑑 [sin(𝑦)]

𝑑𝑔

𝑑 0.5𝑥2

𝑑𝑥

= cos 0.5𝑥2 ⋅ 𝑥

Chain rule in practice

LEARNING WITH NEURAL NETWORKS - PAGE 31UVA DEEP LEARNING COURSE – EFSTRATIOS GAVVES & MAX WELLING

Page 32: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o The loss function ℒ(𝑦, 𝑎𝐿) depends on 𝑎𝐿, which depends on 𝑎𝐿−1, …, which depends on 𝑎2:

o Gradients of parameters of layer l Chain rule

𝜕ℒ

𝜕𝜃𝑙=

𝜕ℒ

𝜕𝑎𝐿∙𝜕𝑎𝐿𝜕𝑎𝐿−1

∙𝜕𝑎𝐿−1𝜕𝑎𝐿−2

∙ … ∙𝜕𝑎𝑙𝜕𝜃𝑙

o When shortened, we need to two quantities

𝜕ℒ

𝜕𝜃𝑙= (

𝜕𝑎𝑙𝜕𝜃𝑙

)𝑇⋅𝜕ℒ

𝜕𝑎𝑙

Backpropagation ⟺ Chain rule!!!

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 32

Gradient of a module w.r.t. its parameters

𝑎𝐿 𝑥; 𝜃1,…,L = ℎ𝐿 (ℎ𝐿−1 …ℎ1 𝑥, θ1 , … , θ𝐿−1 , θ𝐿)

Gradient of loss w.r.t. the module output

Page 33: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o For 𝜕𝑎𝑙

𝜕𝜃𝑙in

𝜕ℒ

𝜕𝜃𝑙= (

𝜕𝑎𝑙

𝜕𝜃𝑙)𝑇⋅

𝜕ℒ

𝜕𝑎𝑙we only need the Jacobian of the 𝑙-th

module output 𝑎𝑙 w.r.t. to the module’s parameters 𝜃𝑙

o Very local rule, every module looks for its own

o Since computations can be very local◦ graphs can be very complicated

◦ modules can be complicated (as long as they are differentiable)

Backpropagation ⟺ Chain rule!!!

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 33

Page 34: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o For 𝜕ℒ

𝜕𝑎𝑙in

𝜕ℒ

𝜕𝜃𝑙= (

𝜕𝑎𝑙

𝜕𝜃𝑙)𝑇⋅

𝜕ℒ

𝜕𝑎𝑙we apply chain rule again

𝜕ℒ

𝜕𝑎𝑙=

𝜕𝑎𝑙+1𝜕𝑎𝑙

𝑇

⋅𝜕ℒ

𝜕𝑎𝑙+1

o We can rewrite 𝜕𝑎𝑙+1

𝜕𝑎𝑙as gradient of module w.r.t. to input

◦ Remember, the output of a module is the input for the next one: 𝑎𝑙=𝑥𝑙+1

𝜕ℒ

𝜕𝑎𝑙=

𝜕𝑎𝑙+1𝜕𝑥𝑙+1

𝑇

⋅𝜕ℒ

𝜕𝑎𝑙+1

Backpropagation ⟺ Chain rule!!!

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 34

Recursive rule (good for us)!!!

Gradient w.r.t. the module input

𝑎𝑙 = ℎ𝑙(𝑥𝑙; 𝜃𝑙)

𝑎𝑙+1 = ℎ𝑙+1(𝑥𝑙+1; 𝜃𝑙+1)

𝑥𝑙+1 = 𝑎𝑙

Page 35: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Often module functions depend on multiple input variables◦ Softmax!

◦ Each output dimension depends onmultiple input dimensions

o For these cases for the 𝜕𝑎𝑙

𝜕𝑥𝑙(or

𝜕𝑎𝑙

𝜕𝜃𝑙) we must compute Jacobian matrix as 𝑎𝑙

depends on multiple input 𝑥𝑙 (or 𝜃𝑙)◦ e.g. in softmax 𝑎2 depends on all 𝑒𝑥

1, 𝑒𝑥

2and 𝑒𝑥

3, not just on 𝑒𝑥

2

Multivariate functions 𝑓(𝒙)

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 35

𝑎𝑗 =𝑒𝑥

𝑗

𝑒𝑥1+ 𝑒𝑥

2+ 𝑒𝑥

3 , 𝑗 = 1,2,3

Page 36: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Often in modules the output depends only in a single input◦ e.g. a sigmoid 𝑎 = 𝜎(𝑥), or 𝑎 = tanh(𝑥), or 𝑎 = exp(𝑥)

o Not need for full Jacobian, only the diagonal: anyways d𝑎𝑖

𝑑𝑥𝑗= 0, ∀ i ≠ j

◦ Can rewrite equations as inner products to save computations

Diagonal Jacobians

LEARNING WITH NEURAL NETWORKS - PAGE 36UVA DEEP LEARNING COURSE – EFSTRATIOS GAVVES & MAX WELLING

𝑑𝒂

𝑑𝒙=𝑑𝝈

𝑑𝒙=

𝜎(𝑥1)(1 − 𝜎(𝑥1)) 0 0

0 𝜎(𝑥2)(1 − 𝜎(𝑥2)) 0

0 0 𝜎(𝑥3)(1 − 𝜎(𝑥3))

~

𝜎(𝑥1)(1 − 𝜎(𝑥1))

𝜎(𝑥2)(1 − 𝜎(𝑥2))

𝜎(𝑥3)(1 − 𝜎(𝑥3))

𝑎 𝑥 = σ 𝒙 = σ𝑥1

𝑥2

𝑥3=

σ(𝑥1)

σ(𝑥2)

σ(𝑥3)

Page 37: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o To make sure everything is done correctly “Dimension analysis”

o The dimensions of the gradient w.r.t. 𝜃𝑙 must be equal to the dimensions of the respective weight 𝜃𝑙

dim𝜕ℒ

𝜕𝑎𝑙= dim 𝑎𝑙

dim𝜕ℒ

𝜕𝜃𝑙= dim 𝜃𝑙

Dimension analysis

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGLEARNING WITH NEURAL NETWORKS - PAGE 37

Page 38: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o For 𝜕ℒ

𝜕𝑎𝑙=

𝜕𝑎𝑙+1

𝜕𝑥𝑙+1

𝑇𝜕ℒ

𝜕𝑎𝑙+1

[𝑑𝑙× 1] = 𝑑𝑙+1 × 𝑑𝑙𝑇 ⋅ [𝑑𝑙+1× 1]

o For 𝜕ℒ

𝜕𝜃𝑙=

𝜕𝛼𝑙

𝜕𝜃𝑙⋅

𝜕ℒ

𝜕𝛼𝑙

𝑇

[𝑑𝑙−1× 𝑑𝑙] = [𝑑𝑙−1× 1] ∙ [1 × 𝑑𝑙]

Dimension analysis

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGLEARNING WITH NEURAL NETWORKS - PAGE 38

dim 𝑎𝑙 = 𝑑𝑙dim 𝜃𝑙 = 𝑑𝑙−1 × 𝑑𝑙

Page 39: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backpropagation: Recursive chain rule

o Step 1. Compute forward propagations for all layers recursively

𝑎𝑙 = ℎ𝑙 𝑥𝑙 and 𝑥𝑙+1 = 𝑎𝑙

o Step 2. Once done with forward propagation, follow the reverse path. ◦ Start from the last layer and for each new layer compute the gradients

◦ Cache computations when possible to avoid redundant operations

o Step 3. Use the gradients 𝜕ℒ

𝜕𝜃𝑙with Stochastic Gradient Descend to train

𝜕ℒ

𝜕𝑎𝑙=

𝜕𝑎𝑙+1𝜕𝑥𝑙+1

𝑇

⋅𝜕ℒ

𝜕𝑎𝑙+1

𝜕ℒ

𝜕𝜃𝑙=𝜕𝑎𝑙𝜕𝜃𝑙

⋅𝜕ℒ

𝜕𝑎𝑙

𝑇

Page 40: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backpropagation: Recursive chain rule

o Step 1. Compute forward propagations for all layers recursively

𝑎𝑙 = ℎ𝑙 𝑥𝑙 and 𝑥𝑙+1 = 𝑎𝑙

o Step 2. Once done with forward propagation, follow the reverse path. ◦ Start from the last layer and for each new layer compute the gradients

◦ Cache computations when possible to avoid redundant operations

o Step 3. Use the gradients 𝜕ℒ

𝜕𝜃𝑙with Stochastic Gradient Descend to train

𝜕ℒ

𝜕𝑎𝑙=

𝜕𝑎𝑙+1𝜕𝑥𝑙+1

𝑇

⋅𝜕ℒ

𝜕𝑎𝑙+1

𝜕ℒ

𝜕𝜃𝑙=𝜕𝑎𝑙𝜕𝜃𝑙

⋅𝜕ℒ

𝜕𝑎𝑙

𝑇

Vector with dimensions [𝑑𝑙+1× 1]

Jacobian matrix with dimensions 𝑑𝑙+1 × 𝑑𝑙𝑇

Vector with dimensions [𝑑𝑙× 1]

Matrix with dimensions [𝑑𝑙−1× 𝑑𝑙]

Vector with dimensions [𝑑𝑙−1× 1]

Vector with dimensions [1 × 𝑑𝑙]

Page 41: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o 𝑑𝑙−1 = 15 (15 neurons), 𝑑𝑙 = 10 (10 neurons), 𝑑𝑙+1 = 5 (5 neurons)

o Let’s say 𝑎𝑙 = 𝜃𝑙Τ𝑥𝑙 and 𝑎𝑙+1 = θ𝑙+1

Τ 𝑥𝑙+1

o Forward computations◦ 𝑎𝑙−1 ∶ 15 × 1 , 𝑎𝑙 : 10 × 1 , 𝑎𝑙+1 : [5 × 1]

◦ 𝑥𝑙: 15 × 1 , 𝑥𝑙+1: 10 × 1

◦ 𝜃𝑙: 15 × 10

o Gradients

◦𝜕ℒ

𝜕𝑎𝑙: 5 × 10 𝑇 ∙ 5 × 1 = 10 × 1

◦𝜕ℒ

𝜕𝜃𝑙∶ 15 × 1 ∙ 10 × 1 𝑇 = 15 × 10

Dimensionality analysis: An Example

𝑥𝑙 = 𝑎𝑙−1

Page 42: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

IntuitiveBackpropagation

UVA DEEP LEARNING COURSEEFSTRATIOS GAVVES & MAX WELLING

OPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 42

Page 43: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Things are dead simple, just compute per module

o Then follow iterative procedure

Backpropagation in practice

LEARNING WITH NEURAL NETWORKS - PAGE 43UVA DEEP LEARNING COURSE – EFSTRATIOS GAVVES & MAX WELLING

𝜕𝑎(𝑥; 𝜃)

𝜕𝑥

𝜕𝑎(𝑥; 𝜃)

𝜕𝜃

𝜕ℒ

𝜕𝑎𝑙=

𝜕𝑎𝑙+1𝜕𝑥𝑙+1

𝑇

⋅𝜕ℒ

𝜕𝑎𝑙+1

𝜕ℒ

𝜕𝜃𝑙=𝜕𝑎𝑙𝜕𝜃𝑙

⋅𝜕ℒ

𝜕𝑎𝑙

𝑇

Page 44: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Things are dead simple, just compute per module

o Then follow iterative procedure [remember: 𝑎𝑙 = 𝑥𝑙+1]

Backpropagation in practice

LEARNING WITH NEURAL NETWORKS - PAGE 44UVA DEEP LEARNING COURSE – EFSTRATIOS GAVVES & MAX WELLING

𝜕𝑎(𝑥; 𝜃)

𝜕𝑥

𝜕𝑎(𝑥; 𝜃)

𝜕𝜃

Module derivatives

Derivatives from layer above

𝜕ℒ

𝜕𝑎𝑙=

𝜕𝑎𝑙+1𝜕𝑥𝑙+1

𝑇

⋅𝜕ℒ

𝜕𝑎𝑙+1

𝜕ℒ

𝜕𝜃𝑙=𝜕𝑎𝑙𝜕𝜃𝑙

⋅𝜕ℒ

𝜕𝑎𝑙

𝑇

Page 45: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o For instance, let’s consider our module is the function cos 𝜃𝑥 + 𝜋

o The forward computation is simply

Forward propagation

LEARNING WITH NEURAL NETWORKS - PAGE 45UVA DEEP LEARNING COURSE – EFSTRATIOS GAVVES & MAX WELLING

import numpy as npdef forward(x):

return np.cos(self.theta*x)+np.pi

Page 46: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o The backpropagation for the function cos 𝑥 + 𝜋

Backward propagation

LEARNING WITH NEURAL NETWORKS - PAGE 46UVA DEEP LEARNING COURSE – EFSTRATIOS GAVVES & MAX WELLING

import numpy as npdef backward_dx(x):

return -self.theta*np.sin(self.theta*x)

import numpy as npdef backward_dtheta(x):

return -x*np.sin(self.theta*x)

Page 47: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backpropagation: An example

UVA DEEP LEARNING COURSEEFSTRATIOS GAVVES & MAX WELLING

OPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 47

Page 48: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backpropagation visualization

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 48

𝑥11 𝑥1

2 𝑥13 𝑥1

4

ℒ𝐿 = 3, 𝑎3 = ℎ3(𝑥3)

𝑎2 = ℎ2(𝑥2, 𝜃2)

𝑎1 = ℎ1(𝑥1, 𝜃1)

𝜃1

𝜃2

𝜃3 = ∅

𝑥1

Page 49: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backpropagation visualization at epoch (𝑡)

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 49

ℒ𝑎3 = ℎ3(𝑥3)

𝑎2 = ℎ2(𝑥2, 𝜃2)

𝑎1 = ℎ1(𝑥1, 𝜃1)

𝜃1

𝜃2

𝜃3 = ∅

Forward propagations

Compute and store 𝑎1= ℎ1(𝑥1)

Example

𝑎1 = 𝜎(𝜃1𝑥1)

Store!!!

𝑥1

Page 50: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backpropagation visualization at epoch (𝑡)

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 50

ℒ𝐿 = 3, 𝑎3 = ℎ3(𝑥3)

𝑎2 = ℎ2(𝑥2, 𝜃2)

𝑎1 = ℎ1(𝑥1, 𝜃1)

𝜃1

𝜃2

𝜃3 = ∅

Forward propagations

Compute and store 𝑎2= ℎ2(𝑥2)

Example

𝑎2 = 𝜎(𝜃2𝑥2)𝑎1 = 𝜎(𝜃1𝑥1)

Store!!!

𝑥1

Page 51: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backpropagation visualization at epoch (𝑡)

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 51

ℒ𝐿 = 3, 𝑎3 = ℎ3(𝑥3)

𝑎2 = ℎ2(𝑥2, 𝜃2)

𝑎1 = ℎ1(𝑥1, 𝜃1)

𝜃1

𝜃2

𝜃3 = ∅

Forward propagations

Compute and store 𝑎3= ℎ3(𝑥3)

Example

𝑎3 = 𝑦 − 𝑥32

𝑎1 = 𝜎(𝜃1𝑥1)

𝑎2 = 𝜎(𝜃2𝑥2)

Store!!!

𝑥1

Page 52: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backpropagation visualization at epoch (𝑡)

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 52

ℒBackpropagation

𝑎3= ℎ3(𝑥3)

𝑎2 = ℎ2(𝑥2, 𝜃2)

𝑎1 = ℎ1(𝑥1, 𝜃1)

𝜃1

𝜃2

𝜃3 = ∅

Example

𝜕ℒ

𝜕𝑎3= … Direct computation

𝜕ℒ

𝜕𝜃3

𝑎3 = ℒ 𝑦, 𝑥3 = ℎ3(𝑥3) = 0.5 𝑦 − 𝑥32

𝜕ℒ

𝜕𝑥3= −(𝑦 − 𝑥3)

𝑥1

Page 53: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backpropagation visualization at epoch (𝑡)

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 53

Stored during forward computations

𝑎3 = ℎ3(𝑥3 )

𝑎2 = ℎ2(𝑥2, 𝜃2)

𝑎1 = ℎ1(𝑥1, 𝜃1)

𝜃1

𝜃2

𝜃3 = ∅

𝜕ℒ

𝜕𝜃2=

𝜕ℒ

𝜕𝑎2∙𝜕𝑎2𝜕𝜃2

𝜕ℒ

𝜕𝑎2=

𝜕ℒ

𝜕𝑎3∙𝜕𝑎3𝜕𝑎2

Backpropagation

Example

ℒ 𝑦, 𝑥3 = 0.5 𝑦 − 𝑥32

𝜕ℒ

𝜕𝑎2= −(𝑦 − 𝑥3)

𝑥3 = 𝑎2

𝜕ℒ

𝜕𝑎2=

𝜕ℒ

𝜕𝑥3= −(𝑦 − 𝑥3)

𝜕ℒ

𝜕𝜃2=

𝜕ℒ

𝜕𝑎2𝑥2𝑎2(1 − 𝑎2)

𝑎2 = 𝜎(𝜃2𝑥2)

𝜕𝑎2𝜕𝜃2

= 𝑥2𝜎(𝜃2𝑥2)(1 − 𝜎(𝜃2𝑥2))

= 𝑥2𝑎2(1 − 𝑎2)

𝜕𝜎(𝑥) = 𝜎(𝑥)(1 − 𝜎(𝑥))

𝑥1

Page 54: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backpropagation visualization at epoch (𝑡)

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 54

ℒ𝑎3 = ℎ3(𝑥3)

𝑎2 = ℎ2(𝑥2, 𝜃2)

𝑎1 = ℎ1(𝑥1, 𝜃1)

𝜃1

𝜃2

𝜃3 = ∅

Backpropagation

𝜕ℒ

𝜕𝜃1=𝜕ℒ

𝜕𝑎1∙𝜕𝑎1𝜕𝜃1

𝜕ℒ

𝜕𝑎1=

𝜕ℒ

𝜕𝑎2∙𝜕𝑎2𝜕𝑎1

Example

ℒ 𝑦, 𝑎3 = 0.5 𝑦 − 𝑎32

𝜕ℒ

𝜕𝑎1=

𝜕ℒ

𝜕𝑎2𝜃2𝑎2(1 − 𝑎2)

𝑎2 = 𝜎(𝜃2𝑥2)𝑥2 = 𝑎1

𝜕𝑎2𝜕𝑎1

=𝜕𝑎2𝜕𝑥2

= 𝜃2𝑎2(1 − 𝑎2)

𝜕ℒ

𝜕𝜃1=𝜕ℒ

𝜕𝑎1𝑥1𝑎1(1 − 𝑎1)

𝑎1 = 𝜎(𝜃1𝑥1)

𝜕𝑎1𝜕𝜃1

= 𝑥1𝑎1(1 − 𝑎1)

Computed from the exact previous backpropagation step (Remember, recursive rule)

𝑥1

Page 55: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backpropagation visualization at epoch (𝑡 + 1)

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 55

ℒ𝐿 = 3, 𝑎3 = ℎ3(𝑥3)

𝑎2 = ℎ2(𝑥2, 𝜃2)

𝑎1 = ℎ1(𝑥1, 𝜃1)

𝜃1

𝜃2

𝜃3 = ∅

Forward propagations

Compute and store 𝑎1= ℎ1(𝑥1)

Example

𝑎1 = 𝜎(𝜃1𝑥1)

Store!!!

𝑥1

Page 56: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backpropagation visualization at epoch (𝑡 + 1)

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 56

ℒ𝐿 = 3, 𝑎3 = ℎ3(𝑥3)

𝑎2 = ℎ2(𝑥2, 𝜃2)

𝑎1 = ℎ1(𝑥1, 𝜃1)

𝜃1

𝜃2

𝜃3 = ∅

Forward propagations

Compute and store 𝑎2= ℎ2(𝑥2)

Example

𝑎2 = 𝜎(𝜃2𝑥2)𝑎1 = 𝜎(𝜃1𝑥1)

Store!!!

𝑥1

Page 57: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backpropagation visualization at epoch (𝑡 + 1)

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 57

ℒ𝐿 = 3, 𝑎3 = ℎ3(𝑥3)

𝑎2 = ℎ2(𝑥2, 𝜃2)

𝑎1 = ℎ1(𝑥1, 𝜃1)

𝜃1

𝜃2

𝜃3 = ∅

Forward propagations

Compute and store 𝑎3= ℎ3(𝑥3)

Example

𝑎3 = 𝑦 − 𝑥32

𝑎1 = 𝜎(𝜃1𝑥1)

𝑎2 = 𝜎(𝜃2𝑥2)

Store!!!

𝑥1

Page 58: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backpropagation visualization at epoch (𝑡 + 1)

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 58

ℒBackpropagation

𝑎3= ℎ3(𝑥3)

𝑎2 = ℎ2(𝑥2, 𝜃2)

𝑎1 = ℎ1(𝑥1, 𝜃1)

𝜃1

𝜃2

𝜃3 = ∅

Example

𝜕ℒ

𝜕𝑎3= … Direct computation

𝜕ℒ

𝜕𝜃3

𝑎3 = ℒ 𝑦, 𝑥3 = ℎ3(𝑥3) = 0.5 𝑦 − 𝑥32

𝜕ℒ

𝜕𝑥3= −(𝑦 − 𝑥3)

𝑥1

Page 59: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backpropagation visualization at epoch (𝑡 + 1)

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 59

Stored during forward computations

𝑎3 = ℎ3(𝑥3 )

𝑎2 = ℎ2(𝑥2, 𝜃2)

𝑎1 = ℎ1(𝑥1, 𝜃1)

𝜃1

𝜃2

𝜃3 = ∅

𝜕ℒ

𝜕𝜃2=

𝜕ℒ

𝜕𝑎2∙𝜕𝑎2𝜕𝜃2

𝜕ℒ

𝜕𝑎2=

𝜕ℒ

𝜕𝑎3∙𝜕𝑎3𝜕𝑎2

Backpropagation

Example

ℒ 𝑦, 𝑥3 = 0.5 𝑦 − 𝑥32

𝜕ℒ

𝜕𝑎2= −(𝑦 − 𝑥3)

𝑥3 = 𝑎2

𝜕ℒ

𝜕𝑎2=

𝜕ℒ

𝜕𝑥3= −(𝑦 − 𝑥3)

𝜕ℒ

𝜕𝜃2=

𝜕ℒ

𝜕𝑎2𝑥2𝑎2(1 − 𝑎2)

𝑎2 = 𝜎(𝜃2𝑥2)

𝜕𝑎2𝜕𝜃2

= 𝑥2𝜎(𝜃2𝑥2)(1 − 𝜎(𝜃2𝑥2))

= 𝑥2𝑎2(1 − 𝑎2)

𝜕𝜎(𝑥) = 𝜎(𝑥)(1 − 𝜎(𝑥))

𝑥1

Page 60: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backpropagation visualization at epoch (𝑡 + 1)

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 60

ℒ𝑎3 = ℎ3(𝑥3)

𝑎2 = ℎ2(𝑥2, 𝜃2)

𝑎1 = ℎ1(𝑥1, 𝜃1)

𝜃1

𝜃2

𝜃3 = ∅

Backpropagation

𝜕ℒ

𝜕𝜃1=𝜕ℒ

𝜕𝑎1∙𝜕𝑎1𝜕𝜃1

𝜕ℒ

𝜕𝑎1=

𝜕ℒ

𝜕𝑎2∙𝜕𝑎2𝜕𝑎1

Example

ℒ 𝑦, 𝑎3 = 0.5 𝑦 − 𝑎32

𝜕ℒ

𝜕𝑎1=

𝜕ℒ

𝜕𝑎2𝜃2𝑎2(1 − 𝑎2)

𝑎2 = 𝜎(𝜃2𝑥2)𝑥2 = 𝑎1

𝜕𝑎2𝜕𝑎1

=𝜕𝑎2𝜕𝑥2

= 𝜃2𝑎2(1 − 𝑎2)

𝜕ℒ

𝜕𝜃1=𝜕ℒ

𝜕𝑎1𝑥1𝑎1(1 − 𝑎1)

𝑎1 = 𝜎(𝜃1𝑥1)

𝜕𝑎1𝜕𝜃1

= 𝑥1𝑎1(1 − 𝑎1)

Computed from the exact previous backpropagation step (Remember, recursive rule)

𝑥1

Page 61: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o For classification use cross-entropy loss

o Use Stochastic Gradient Descent on mini-batches

o Shuffle training examples at each new epoch

o Normalize input variables◦ 𝜇, 𝜎2 = 0,1

◦ 𝜇 = 0

Some practical tricks of the trade

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 61

Page 62: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Everything is amodule

UVA DEEP LEARNING COURSEEFSTRATIOS GAVVES & MAX WELLING

OPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 62

Page 63: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o A neural network model is a series of hierarchically connected functions

o This hierarchies can be very, very complex

Neural network models

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 63

ℎ1 (𝑥

𝑖 ;𝜗)

ℎ2 (𝑥

𝑖 ;𝜗)

ℎ3 (𝑥

𝑖 ;𝜗)

ℎ4 (𝑥

𝑖 ;𝜗)

ℎ5 (𝑥

𝑖 ;𝜗)

𝐿𝑜𝑠𝑠

𝐼𝑛𝑝𝑢𝑡

ℎ1(𝑥𝑖; 𝜗)

ℎ2(𝑥𝑖; 𝜗)

ℎ3(𝑥𝑖; 𝜗)

ℎ4(𝑥𝑖; 𝜗)

ℎ5(𝑥𝑖; 𝜗)

𝐿𝑜𝑠𝑠

𝐼𝑛𝑝𝑢𝑡

ℎ2(𝑥𝑖; 𝜗)

ℎ4(𝑥𝑖; 𝜗)

ℎ1 (𝑥

𝑖 ;𝜗)

ℎ2 (𝑥

𝑖 ;𝜗)

ℎ3 (𝑥

𝑖 ;𝜗)

ℎ4 (𝑥

𝑖 ;𝜗)

ℎ5 (𝑥

𝑖 ;𝜗)

𝐿𝑜𝑠𝑠

𝐼𝑛𝑝𝑢𝑡

Functions Modules

Page 64: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Activation function 𝑎 = 𝜃𝑥

o Gradient with respect to the input 𝜕𝑎

𝜕𝑥= 𝜃

o Gradient with respect to the parameters 𝜕𝑎

𝜕𝜃= 𝑥

Linear module

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 64

Page 65: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Activation function 𝑎 = 𝜎 𝑥 =1

1+𝑒−𝑥

o Gradient wrt the input 𝜕𝑎

𝜕𝑥= 𝜎(𝑥)(1 − 𝜎(𝑥))

o Gradient wrt the input 𝜕𝜎 𝜃𝑥

𝜕𝑥= 𝜃 ∙ 𝜎 𝜃𝑥 1 − 𝜎 𝜃𝑥

o Gradient wrt the parameters𝜕𝜎 𝜃𝑥

𝜕𝜃= 𝑥 ∙ 𝜎(𝜃𝑥)(1 − 𝜎(𝜃𝑥))

Sigmoid module

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 65

Page 66: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

+ Output can be interpreted as probability

+ Output bounded in [0, 1] network cannot overshoot

- Always multiply with < 1 Gradients can be small in deep networks

- The gradients at the tails flat to 0 no serious SGD updates◦ Overconfident, but not necessarily “correct”

◦ Neurons get stuck

Sigmoid module – Pros and Cons

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 66

Page 67: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Activation function 𝑎 = 𝑡𝑎𝑛ℎ 𝑥 =𝑒𝑥−𝑒−𝑥

𝑒𝑥+𝑒−𝑥

o Gradient with respect to the input 𝜕𝑎

𝜕𝑥= 1 − 𝑡𝑎𝑛ℎ2(𝑥)

o Similar to sigmoid, but with different output range◦ [−1,+1] instead of 0,+1

◦ Stronger gradients, because data is centeredaround 0 (not 0.5)

◦ Less bias to hidden layer neurons as now outputscan be both positive and negative (more likelyto have zero mean in the end)

Tanh module

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 67

Page 68: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Activation function 𝑎 = ℎ(𝑥) = max 0, 𝑥

o Gradient wrt the input 𝜕𝑎

𝜕𝑥= ቊ

0, 𝑖𝑓 𝑥 ≤ 01, 𝑖𝑓𝑥 > 0

o Very popular in computer vision and speech recognition

o Much faster computations, gradients◦ No vanishing or exploding problems, only comparison, addition, multiplication

o People claim biological plausibility

o Sparse activations

o No saturation

o Non-symmetric

o Non-differentiable at 0

o A large gradient during training can cause a neuron to “die”. Higher learning rates mitigate the problem

Rectified Linear Unit (ReLU) module (Alexnet)

Page 69: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

ReLU convergence rate

ReLU

Tanh

Page 70: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Soft approximation (softplus): 𝑎 = ℎ(𝑥) = ln 1 + 𝑒𝑥

o Noisy ReLU: 𝑎 = ℎ 𝑥 = max 0, x + ε , ε~𝛮(0, σ(x))

o Leaky ReLU: 𝑎 = ℎ 𝑥 = ቊ𝑥, 𝑖𝑓 𝑥 > 0

0.01𝑥 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒

o Parametric ReLu: 𝑎 = ℎ 𝑥 = ቊ𝑥, 𝑖𝑓 𝑥 > 0

𝛽𝑥 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒(parameter 𝛽 is trainable)

Other ReLUs

Page 71: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Activation function 𝑎(𝑘) = 𝑠𝑜𝑓𝑡𝑚𝑎𝑥(𝑥(𝑘)) =𝑒𝑥

(𝑘)

σ𝑗 𝑒𝑥(𝑗)

◦ Outputs probability distribution, σ𝑘=1𝐾 𝑎(𝑘) = 1 for 𝐾 classes

o Because 𝑒𝑎+𝑏 = 𝑒𝑎𝑒𝑏, we usually compute

𝑎(𝑘) =𝑒𝑥

(𝑘)−𝜇

σ𝑗 𝑒𝑥(𝑗)−𝜇

, 𝜇 = max𝑘 𝑥(𝑘) because

𝑒𝑥(𝑘)−𝜇

σ𝑗 𝑒𝑥(𝑗)−𝜇

=𝑒𝜇𝑒𝑥

(𝑘)

𝑒𝜇 σ𝑗 𝑒𝑥(𝑗)

=𝑒𝑥

(𝑘)

σ𝑗 𝑒𝑥(𝑗)

o Avoid exponentianting large numbers better stability

Softmax module

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 71

Page 72: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Activation function 𝑎(𝑥) = 0.5 𝑦 − 𝑥 2

◦ Mostly used to measure the loss in regression tasks

o Gradient with respect to the input 𝜕𝑎

𝜕𝑥= 𝑥 − 𝑦

Euclidean loss module

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 72

Page 73: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Activation function 𝑎 𝑥 = −σ𝑘=1𝐾 𝑦(𝑘) log 𝑥(𝑘), 𝑦(𝑘)= {0, 1}

o Gradient with respect to the input 𝜕𝑎

𝜕𝑥(𝑘)= −

1

𝑥(𝑘)

o The cross-entropy loss is the most popular classification losses for classifiers that output probabilities (not SVM)

o Cross-entropy loss couples well softmax/sigmoid module◦ Often the modules are combined and joint gradients are computed

o Generalization of logistic regression for more than 2 outputs

Cross-entropy loss (log-loss or log-likelihood) module

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGOPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 73

Page 74: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Regularization modules◦ Dropout

o Normalization modules◦ ℓ2-normalization, ℓ1-normalization

Question: When is a normalization module needed?

Answer: Possibly when combining different modalities/networks (e.g. in Siamese or multiple-branch networks)

o Loss modules◦ Hinge loss

o and others, which we are going to discuss later in the course

Many, many more modules out there …

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGLEARNING WITH NEURAL NETWORKS - PAGE 74

Page 75: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Composite modules

or …

“Make your own module”

UVA DEEP LEARNING COURSEEFSTRATIOS GAVVES & MAX WELLING

OPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 75

Page 76: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Backpropagation again

o Step 1. Compute forward propagations for all layers recursively

𝑎𝑙 = ℎ𝑙 𝑥𝑙 and 𝑥𝑙+1 = 𝑎𝑙

o Step 2. Once done with forward propagation, follow the reverse path. ◦ Start from the last layer and for each new layer compute the gradients

◦ Cache computations when possible to avoid redundant operations

o Step 3. Use the gradients 𝜕ℒ

𝜕𝜃𝑙with Stochastic Gradient Descend to train

𝜕ℒ

𝜕𝑎𝑙=

𝜕𝑎𝑙+1𝜕𝑥𝑙+1

𝑇

⋅𝜕ℒ

𝜕𝑎𝑙+1

𝜕ℒ

𝜕𝜃𝑙=𝜕𝑎𝑙𝜕𝜃𝑙

⋅𝜕ℒ

𝜕𝑎𝑙

𝑇

Page 77: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Everything can be a module, given some ground rules

o How to make our own module?◦ Write a function that follows the ground rules

o Needs to be (at least) first-order differentiable (almost) everywhere

o Hence, we need to be able to compute the

𝜕𝑎(𝑥;𝜃)

𝜕𝑥and

𝜕𝑎(𝑥;𝜃)

𝜕𝜃

New modules

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGLEARNING WITH NEURAL NETWORKS - PAGE 77

Page 78: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o As everything can be a module, a module of modules could also be a module

o We can therefore make new building blocks as we please, if we expect them to be used frequently

o Of course, the same rules for the eligibility of modules still apply

A module of modules

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGLEARNING WITH NEURAL NETWORKS - PAGE 78

Page 79: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Assume the sigmoid 𝜎(… ) operating on top of 𝜃𝑥𝑎 = 𝜎(𝜃𝑥)

o Directly computing it complicated backpropagation equations

o Since everything is a module, we can decompose this to 2 modules

1 sigmoid == 2 modules?

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGLEARNING WITH NEURAL NETWORKS - PAGE 79

𝑎1 = 𝜃𝑥 𝑎2 = 𝜎(𝑎1)

Page 80: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

- Two backpropagation steps instead of one

+ But now our gradients are simpler◦ Algorithmic way of computing gradients

◦ We avoid taking more gradients than needed in a (complex) non-linearity

1 sigmoid == 2 modules?

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGLEARNING WITH NEURAL NETWORKS - PAGE 80

𝑎1 = 𝜃𝑥 𝑎2 = 𝜎(𝑎1)

Page 81: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Network-in-network [Lin et al., arXiv 2013]

LEARNING WITH NEURAL NETWORKS - PAGE 81UVA DEEP LEARNING COURSE – EFSTRATIOS GAVVES & MAX WELLING

Page 82: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

ResNet [He et al., CVPR 2016]

LEARNING WITH NEURAL NETWORKS - PAGE 82UVA DEEP LEARNING COURSE – EFSTRATIOS GAVVES & MAX WELLING

Page 83: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o RBF module

𝑎 =𝑗𝑢𝑗 exp(−𝛽𝑗(𝑥 − 𝑤𝑗)

2)

o Decompose into cascade of modules

Radial Basis Function (RBF) Network module

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGLEARNING WITH NEURAL NETWORKS - PAGE 83

𝑎1 = (𝑥 − 𝑤)2

𝑎2 = exp −𝛽𝑎1

𝑎4 = 𝑝𝑙𝑢𝑠(… , 𝑎3𝑗, … )

𝑎3 = 𝑢𝑎2

Page 84: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o An RBF module is good for regression problems, in which cases it is followed by a Euclidean loss module

o The Gaussian centers 𝑤𝑗 can be initialized externally, e.g. with k-means

Radial Basis Function (RBF) Network module

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGLEARNING WITH NEURAL NETWORKS - PAGE 84

𝑎1 = (𝑥 − 𝑤)2

𝑎2 = exp −𝛽𝑎1

𝑎4 = 𝑝𝑙𝑢𝑠(… , 𝑎3𝑗, … )

𝑎3 = 𝑢𝑎2

Page 85: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

An RBF visually

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGLEARNING WITH NEURAL NETWORKS - PAGE 85

𝑎1 = (𝑥 − 𝑤)2→ 𝑎2 = exp −𝛽𝑎1 → 𝑎3 = 𝑢𝑎2 → 𝑎4 =𝑝𝑙𝑢𝑠(… , 𝑎3𝑗, … )

𝛼1(3)

= (𝑥 − 𝑤1)2

𝛼1(2)

= (𝑥 − 𝑤1)2𝛼1

(1)= (𝑥 − 𝑤1)

2

𝛼2(1)

= exp(−𝛽1𝛼1(1)) 𝛼2

(2)= exp(−𝛽1𝛼1

(2)) 𝛼2

(3)= exp(−𝛽1𝛼1

(3))

𝛼3(1)

= 𝑢1𝛼2(1)

𝛼3(2)

= 𝑢2𝛼2(2) 𝛼3

(3)= 𝑢3𝛼2

(3)

𝑎4 = 𝑝𝑙𝑢𝑠(𝑎3)

𝑎5 = 𝑦 − 𝑎42

RBF module

Page 86: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Unit tests

UVA DEEP LEARNING COURSEEFSTRATIOS GAVVES & MAX WELLING

OPTIMIZING NEURAL NETWORKS IN THEORY AND IN PRACTICE - PAGE 86

Page 87: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Always check your implementations◦ Not only for Deep Learning

o Does my implementation of the 𝑠𝑖𝑛 function return the correct values?◦ If I execute sin(𝜋/2) does it return 1 as it should

o Even more important for gradient functions◦ not only our implementation can be wrong, but also our math

o Slightest sign of malfunction ALWAYS RECHECK◦ Ignoring problems never solved problems

Unit test

LEARNING WITH NEURAL NETWORKS - PAGE 87UVA DEEP LEARNING COURSE – EFSTRATIOS GAVVES & MAX WELLING

Page 88: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Most dangerous part for new modules get gradients wrong

o Compute gradient analytically

o Compute gradient computationally

o Compare

Δ 𝜃(𝑖) =𝜕𝑎(𝑥; 𝜃(𝑖))

𝜕𝜃(𝑖)− 𝑔 𝜃(𝑖)

2

o Is difference in 10−4, 10−7 thengradients are good

Gradient check

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGLEARNING WITH NEURAL NETWORKS - PAGE 88

Original gradient definition: 𝑑𝑓(𝑥)

𝑑𝑥= limℎ→0

𝑓(𝑥+ℎ)

Δℎ

𝑔 𝜃(𝑖) ≈𝑎 𝜃 + 𝜀 − 𝑎 𝜃 − 𝜀

2𝜀

Page 89: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Perturb one parameter 𝜃(𝑖) at a time with 𝜃(𝑖) + 𝜀

o Then check Δ 𝜃(𝑖) for that one parameter only

o Do not perturb the whole parameter vector 𝜃 + 𝜀◦ This will give wrong results (simple geometry)

o Sample dimensions of the gradient vector◦ If you get a few dimensions of an gradient vector good, all is good

◦ Sample function and bias gradients equally, otherwise you might get your bias wrong

Gradient check

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGLEARNING WITH NEURAL NETWORKS - PAGE 89

Page 90: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o Can we replace analytical gradients with numerical gradients?

o In theory, yes!

o In practice, no!◦ Too slow

Numerical gradients

LEARNING WITH NEURAL NETWORKS - PAGE 90UVA DEEP LEARNING COURSE – EFSTRATIOS GAVVES & MAX WELLING

Page 91: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o What about trigonometric modules?

o Or polynomial modules?

o Or new loss modules?

Be creative!

UVA DEEP LEARNING COURSE - EFSTRATIOS GAVVES & MAX WELLINGLEARNING WITH NEURAL NETWORKS - PAGE 91

Page 92: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Summary

UVA DEEP LEARNING COURSEEFSTRATIOS GAVVES & MAX WELLING

INTRODUCTION ON NEURAL NETWORKS AND DEEP LEARNING - PAGE 92

o Machine learning paradigm for neural networks

o Backpropagation algorithm, backbone for training neural networks

o Neural network == modular architecture

o Visited different modules, saw how to implement and check them

Page 93: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

o http://www.deeplearningbook.org/◦ Part I: Chapter 2-5

◦ Part II: Chapter 6

Reading material & references

LEARNING WITH NEURAL NETWORKS - PAGE 93UVA DEEP LEARNING COURSE – EFSTRATIOS GAVVES & MAX WELLING

Page 94: Lecture 2: Learning with neural networks - UvA Deep Learning … ·  · 2016-12-17o Machine Learning Paradigm for Neural Networks o The Backpropagation algorithm for learning with

Next lecture

UVA DEEP LEARNING COURSEEFSTRATIOS GAVVES & MAX WELLING

INTRODUCTION ON NEURAL NETWORKS AND DEEP LEARNING - PAGE 94

o Optimizing deep networks

o Which loss functions per machine learning task

o Advanced modules

o Deep Learning theory