neural networks - carnegie mellon...

108
Neural Networks Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj

Upload: others

Post on 03-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Neural Networks

Class 22: MLSP, Fall 2016

Instructor: Bhiksha Raj

Page 2: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

IMPORTANT ADMINSTRIVIA

• Final week. Project presentations on 6th

18797/11755 2

Page 3: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Neural Networks are taking over!

• Neural networks have become one of the major thrust areas recently in various pattern recognition, prediction, and analysis problems

• In many problems they have established the state of the art

– Often exceeding previous benchmarks by large margins

18797/11755 3

Page 4: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Recent success with neural networks

• Some recent successes with neural networks – A bit of hyperbole, but still..

18797/11755 4

Page 5: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Recent success with neural networks

• Some recent successes with neural networks – A bit of hyperbole, but still..

18797/11755 5

Page 6: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Recent success with neural networks

• Some recent successes with neural networks – A bit of hyperbole, but still..

18797/11755 6

Page 7: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Recent success with neural networks

• Some recent successes with neural networks – A bit of hyperbole, but still.. 18797/11755 7

Page 8: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Recent success with neural networks

• Captions generated entirely by a neural network 18797/11755 8

Page 9: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Successes with neural networks

• And a variety of other problems:

– Image recognition

– Signal enhancement

– Even predicting stock markets!

18797/11755 9

Page 10: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

So what are neural networks??

• What are these boxes?

N.Net Voice signal Transcription N.Net Image Text caption

N.Net Game State Next move

18797/11755 10

Page 11: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

So what are neural networks??

• It began with this..

• Humans are very good at the tasks we just saw

• Can we model the human brain/ human intelligence?

– An old question – dating back to Plato and Aristotle.. 18797/11755 11

Page 12: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Observation: The Brain

• Mid 1800s: The brain is a mass of interconnected neurons

18797/11755 12

Page 13: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Brain: Interconnected Neurons

• Many neurons connect in to each neuron

• Each neuron connects out to many neurons

18797/11755 13

Page 14: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

The brain is a connectionist machine

• The human brain is a connectionist machine

– Bain, A. (1873). Mind and body. The theories of their relation. London: Henry King.

– Ferrier, D. (1876). The Functions of the Brain. London: Smith, Elder and Co

• Neurons connect to other neurons. The processing/capacity of the brain is a function of these connections

• Connectionist machines emulate this structure

18797/11755 14

Page 15: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Connectionist Machines

• Neural networks are connectionist machines – As opposed to Von Neumann Machines

• The machine has many processing units – The program is the connections between these units

• Connections may also define memory

PROCESSOR PROGRAM

DATA

Memory Processing unit

Von Neumann Machine

NETWORK

Neural Network

18797/11755 15

Page 16: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Modelling the brain

• What are the units?

• A neuron:

• Signals come in through the dendrites into the Soma

• A signal goes out via the axon to other neurons

– Only one axon per neuron

• Factoid that may only interest me: Neurons do not undergo cell division

Dendrites

Soma

Axon

18797/11755 16

Page 17: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

McCullough and Pitts

• The Doctor and the Hobo..

– Warren McCulloch: Neurophysician

– Walter Pitts: Homeless wannabe logician who arrived at his door

18797/11755 17

Page 18: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

The McCulloch and Pitts model

• A mathematical model of a neuron

– McCulloch, W.S. & Pitts, W.H. (1943). A Logical Calculus of the Ideas Immanent in Nervous Activity, Bulletin of Mathematical Biophysics, 5:115-137, 1943

– Threshold Logic

• Note: McCullough and Pitts original model was actually slightly different – this model is actually due to Rosenblatt

A single neuron

18

Page 19: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

The solution to everything

• Frank Rosenblatt

– Psychologist, Logician

– Inventor of the solution to everything, aka the Perceptron (1958)

• A mathematical model of the neuron that could solve everything!!! 19

Page 20: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Simplified mathematical model

• Number of inputs combine linearly

– Threshold logic: Fire if combined input exceeds

threshold

𝑌 = 1 𝑖𝑓 𝑤𝑖𝑥𝑖 + 𝑏 > 0

𝑖

0 𝑒𝑙𝑠𝑒

18797/11755 20

Page 21: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Simplified mathematical model

• A mathematical model

– Originally assumed could represent any Boolean circuit

– Rosenblatt, 1958 : “the embryo of an electronic computer

that [the Navy] expects will be able to walk, talk, see,

write, reproduce itself and be conscious of its existence”

18797/11755 21

Page 22: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Perceptron

• Boolean Gates

• But…

X

Y

1

1

2

X

Y

1

1

1

0 X -1

X ∧ Y

X ∨ Y

X

18797/11755 22

Page 23: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Perceptron

X

Y

?

?

? X⨁Y

No solution for XOR! Not universal!

• Minsky and Papert, 1968

18797/11755 23

Page 24: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

A single neuron is not enough

• Individual elements are weak computational elements – Marvin Minsky and Seymour Papert, 1969, Perceptrons:

An Introduction to Computational Geometry

• Networked elements are required

18797/11755 24

Page 25: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Multi-layer Perceptron!

• XOR

– The first layer is a “hidden” layer

25

1

1

1

-1

1

-1

X

Y

1

X⨁Y

-1

2

X ∨ Y

X ∨ Y

Hidden Layer

18797/11755

Page 26: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Multi-Layer Perceptron

• Even more complex Boolean functions can be composed using layered networks of perceptrons

– Two hidden layers in above model

– In fact can build any Boolean function over any number of inputs 26

( 𝐴&𝑋 &𝑍 | 𝐴&𝑌 )&( 𝑋 & 𝑌 | 𝑋&𝑍 )

1 2 1 1 1 2 1 1

X Y Z A

1 0 1 1

1 2

1 1 1 -1 1 1 -1

1 1

1 -1 1 1

1 1

18797/11755

Page 27: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Multi-layer perceptrons are universal Boolean functions

• A multi-layer perceptron is a universal Boolean function

• In fact, an MLP with only one hidden layer is a universal Boolean function!

18797/11755 27

Page 28: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

𝟐𝒏 inputs

Constructing Boolean functions with only one hidden layer

• Any Boolean formula can be expressed by an MLP with one hidden layer

– Any Boolean formula can be expressed in Conjunctive Normal Form

• The one hidden layer can be exponentially wide

– But the same formula can be obtained with a much smaller network if we have multiple hidden layers

28

x1x2

y1y2 x1x2𝑦 1𝑦 2 + x1x2𝑦 1𝑦2 + x1x 2𝑦 1𝑦2 + … 𝟗 terms

𝟐𝒏 units

18797/11755

Page 29: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Neural Networks: Multi-layer Perceptrons

• In reality the input to these systems is not Boolean

• Inputs are continuous valued – Signals may be continuous valued

– Image features are continuous valued

– Pixels are multi-valued (e.g. 0-255)

N.Net Voice signal Transcription N.Net Image Text caption

29

Page 30: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

MLP on continuous inputs

• The inputs are continuous valued

– Threshold logic: Fire if combined input exceeds

threshold

𝑌 = 1 𝑖𝑓 𝑤𝑖𝑥𝑖 + 𝑏 > 0

𝑖

0 𝑒𝑙𝑠𝑒

18797/11755 30

Page 31: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

A Perceptron on Reals

• A perceptron operates on real-valued vectors – This is just a linear classifier

31

x1

x2

w1,w2

𝑦 = 1 𝑖𝑓 𝑤𝑖x𝑖 ≥ 𝑇

𝑖

0 𝑒𝑙𝑠𝑒

x1

x2

18797/11755

Page 32: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Booleans over the reals

• The network must fire if the input is in the coloured area

32

x1

x2 Can now be composed into “networks” to compute arbitrary classification “boundaries”

18797/11755

Page 33: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Booleans over the reals

• The network must fire if the input is in the coloured area

33

x1

x2

x1 x2

18797/11755

Page 34: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Booleans over the reals

• The network must fire if the input is in the coloured area

34

x1

x2

x1 x2

18797/11755

Page 35: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Booleans over the reals

• The network must fire if the input is in the coloured area

35

x1

x2

x1 x2

18797/11755

Page 36: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Booleans over the reals

• The network must fire if the input is in the coloured area

36

x1

x2

x1 x2

18797/11755

Page 37: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Booleans over the reals

• The network must fire if the input is in the coloured area

37

x1

x2

x1 x2

18797/11755

Page 38: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Booleans over the reals

• The network must fire if the input is in the coloured area

38

x1

x2

x1

x2

AND

5

4 4

4

4

4

3

3

3

3 3 x1 x2

y𝑖

𝑁

𝑖=1

≥ 𝑁?

y1 y5 y2 y3 y4

18797/11755

Page 39: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Booleans over the reals

• “OR” two polygons

• A third layer is required 39

x2

AND AND

OR

x1 x1 x2

18797/11755

Page 40: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

How Complex Can it Get

• An arbitrarily complex decision boundary

• Basically any Boolean function over the basic linear boundaries

• Even with a single hidden layer!

40 18797/11755

Page 41: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Composing a polygon

• The polygon net

• Increasing the number of sides shrinks the area

outside the polygon that have sum close to N 41

4 5 6

4 4

4

4

4

5 5

5 5

5

5

AND

x1 x2

y𝑖

𝑁

𝑖=1

≥ 𝑁?

y1 y5 y2 y3 y4

18797/11755

Page 42: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

+

Composing a circle

• The circle net

– Very large number of neurons

– Circle can be of arbitrary diameter, at any location

– Achieved without using a thresholding function!! 42

No nonlinearity applied!

Page 43: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Adding circles

• The “sum” of two circles sub nets is exactly a net with output 1 if the input falls within either circle

43

No nonlinearity applied!

+

18797/11755

Page 44: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

+

Composing an arbitrary figure

• Just fit in an arbitrary number of circles

– More accurate approximation with greater number of smaller circles

– A lesson here that we will refer to again shortly.. 44 18797/11755

Page 45: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Story so far..

• Multi-layer perceptrons are Boolean networks

– They represent Boolean functions over linear boundaries

– They can approximate any boundary

• Using a sufficiently large number of linear units

– Complex Boolean functions are better modeled with more layers

– Complex boundaries are more compactly represented using more layers

45 18797/11755

Page 46: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Lets look at the weights

• What do the weights tell us?

– The neuron fires if the inner product between the weights and the inputs exceeds a threshold

46

x1

x2

x3

xN

𝑦 = 1 𝑖𝑓 𝑤𝑖x𝑖 ≥ 𝑇

𝑖

0 𝑒𝑙𝑠𝑒

𝑦 = 1 𝑖𝑓 𝐱𝑇𝐰 ≥ 𝑇

0 𝑒𝑙𝑠𝑒

18797/11755

Page 47: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

The weight as a “template”

• The perceptron fires if the input is within a specified angle of the weight

– Represents a convex region on the surface of the sphere!

– The network is a Boolean function over these regions. • The overall decision region can be arbitrarily nonconvex

• Neuron fires if the input vector is close enough to the weight vector.

– If the input pattern matches the weight pattern closely enough

47

w 𝑿𝑻𝑾 > 𝑻

𝐜𝐨𝐬𝜽 >𝑻

𝑿

𝜽 < 𝒄𝒐𝒔−𝟏𝑻

𝑿

x1

x2

x3

xN

18797/11755

Page 48: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

The weight as a template

• If the correlation between the weight pattern and the inputs exceeds a threshold, fire

• The perceptron is a correlation filter! 48

W X X

Correlation = 0.57 Correlation = 0.82 𝑦 =

1 𝑖𝑓 𝑤𝑖x𝑖 ≥ 𝑇

𝑖

0 𝑒𝑙𝑠𝑒

18797/11755

Page 49: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

The MLP as a Boolean function over feature detectors

• The input layer comprises “feature detectors”

– Detect if certain patterns have occurred in the input

• The network is a Boolean function over the feature detectors

• I.e. it is important for the first layer to capture relevant patterns 49

DIGIT OR NOT?

Page 50: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

The MLP as a cascade of feature detectors

• The network is a cascade of feature detectors

– Higher level neurons compose complex templates from features represented by lower-level neurons

• Risk in this perspective: Upper level neurons may be performing “OR”

– Looking for a choice of compound patterns 50

DIGIT OR NOT?

Page 51: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Story so far

• MLPs are Boolean machines

– They represent Boolean functions over linear boundaries

– They can represent arbitrary boundaries

• Perceptrons are correlation filters

– They detect patterns in the input

• MLPs are Boolean formulae over patterns detected by perceptrons

– Higher-level perceptrons may also be viewed as feature detectors

• Extra: MLP in classification

– The network will fire if the combination of the detected basic features matches an “acceptable” pattern for a desired class of signal

• E.g. Appropriate combinations of (Nose, Eyes, Eyebrows, Cheek, Chin) Face

51 18797/11755

Page 52: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

MLP as a continuous-valued regression

• MLPs can actually compose arbitrary functions to arbitrary precision

– Not just classification/Boolean functions

• 1D example

– Left: A net with a pair of units can create a pulse of any width at any location

– Right: A network of N such pairs approximates the function with N scaled pulses 52

x

1 T1

T2

1

T1

T2

1

-1 T1 T2 x

f(x) x

+ × ℎ1 × ℎ2

× ℎ𝑛

ℎ1

ℎ2

ℎ𝑛

Page 53: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

+

MLP as a continuous-valued regression

• MLPs can actually compose arbitrary functions – Even with only one layer

– To arbitrary precision

– The MLP is a universal approximator!

53

× ℎ1

× ℎ2

× ℎ𝑛

ℎ1 ℎ2

ℎ𝑛

18797/11755

Page 54: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Multi-layer perceptrons are universal function approximators

• A multi-layer perceptron is a universal function approximator

– Hornik, Stinchcombe and White 1989, several others

N.Net X, Y Z, Colour

18797/11755 54

Page 55: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

What’s inside these boxes?

• Each of these tasks is performed by a net like this one – Functions that take the given input and produce the

required output

N.Net Voice signal Transcription N.Net Image Text caption

N.Net Game State Next move

18797/11755 55

Page 56: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Story so far

• MLPs are Boolean machines

– They represent arbitrary Boolean functions over arbitrary linear boundaries

– MLPs perform classification

• MLPs can compute arbitrary real-valued functions of arbitrary real-valued inputs

– To arbitrary precision

– They are universal approximators

56 18797/11755

Page 57: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

• Building a network for a task

18797/11755 57

Page 58: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

These tasks are functions

• Each of these boxes is actually a function

– E.g f: Image Caption

N.Net Voice signal Transcription N.Net Image Text caption

N.Net Game State Next move

18797/11755 58

Page 59: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

These tasks are functions

Voice signal Transcription Image Text caption

Game State Next move

• Each box is actually a function

– E.g f: Image Caption

– It can be approximated by a neural network

59

Page 60: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

The network as a function

• Inputs are numeric vectors

– Numeric representation of input, e.g. audio, image, game state, etc.

• Outputs are numeric scalars or vectors

– Numeric “encoding” of output from which actual output can be derived

– E.g. a score, which can be compared to a threshold to decide if the input is a face or not

– Output may be multi-dimensional, if task requires it

Input Output

18797/11755 60

Page 61: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

The network is a function

• Given an input, it computes the function layer wise to predict an output

18797/11755 61

Page 62: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

A note on activations

• Previous explanations assumed network units used a threshold function for “activation”

• In reality, we use a number of other differentiable functions

– Mostly, but not always, “squashing” functions 62

x1

x2

x3

xN

sigmoid tanh

Page 63: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

The entire network

• Inputs (D-dimensional): 𝑋1, … , 𝑋𝐷

• Weights from ith node in lth layer to jth node in l+1th layer: 𝑊𝑖,𝑗𝑙

• Complete set of weights

{𝑊𝑖,𝑗𝑙 ; 𝑙 = 0. . 𝐿, 𝑖 = 1…𝑁𝑙 , 𝑗 = 1…𝑁𝑙+1}

• Outputs (M-dimensional): 𝑂1, … , 𝑂𝑀 18797/11755 63

Page 64: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Making a prediction (Aka forward pass)

⋮ ⋮ ⋮ ⋮ 𝑋 Illustration with a

network with N-1 hidden layers ⋮ ⋮ ⋮ 𝑓𝑁

𝑂 ⋯

18797/11755 64

Page 65: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Forward Computation

i

i

ijj XWI 11

fN

fN

𝑓1

𝑓𝑁−1

ON IN

ON-1 IN-1 O1 I1 X

𝑓1

𝑓1

𝑓1

For the jth neuron of the 1st hidden layer: Input to the activation functions in the first layer

18797/11755 65

Page 66: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Forward Computation

i

i

ijj XWI 11

fN

fN

𝑓1

𝑓𝑁−1

ON IN

ON-1 IN-1 O1 I1 X

𝑓1

𝑓1

𝑓1

For the jth neuron of the 1st hidden layer: Input to the activation functions in the first layer

)( 1

1

1

jj IfO Output of the jth neuron of the 1st hidden layer: 18797/11755 66

Page 67: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Forward Computation

1 k

i

i

k

ij

k

j OWI

fN

fN

𝑓𝑘 𝑓𝑁−1

ON IN

ON-1 IN-1 Ok Ik Ok-1 Ik-1

For the jth neuron of the kth hidden layer: Input to the activation functions in the kth layer

18797/11755 67

Page 68: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Forward Computation

1 k

i

i

k

ij

k

j OWI )( k

jk

k

j IfO

fN

fN

𝑓𝑘 𝑓𝑁−1

ON IN

ON-1 IN-1 Ok Ik Ok-1 Ik-1

Output of the jth neuron of the kth hidden layer:

For the jth neuron of the kth hidden layer: Input to the activation functions in the kth layer

18797/11755 68

Page 69: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Forward Computation

i

i

ijj XWI 11

1 k

i

i

k

ij

k

j OWI

)( k

jk

k

j IfO

fN

fN

𝑓𝑘 𝑓𝑁−1

ON IN

ON-1 IN-1 Ok Ik Ok-1 Ik-1

ITERATE FOR k = 1:N

for j = 1:layer-width

Output ON is the output of the network 18797/11755 69

Page 70: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

The problem of training the network

• The network must be composed correctly to produce the desired outputs

• This is the problem of “training” the network

18797/11755 70

Page 71: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

The Problem of Training a Network

• A neural network is effectively just a function – What makes it an NNet is the structure of the function

• Takes an input – Generally multi-dimensional

• Produces an output – May be uni- or multi-dimensional

• Challenge: How to make it produce the desired output for any given input

f(x) X Y = f(X) X Y = f(X)

18797/11755 71

Page 72: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Building by design

• Solution 1: Just hand design it – What will the network for the above function be?

• We can hand draw this one..

X1 X2

Y

X1

X2

18797/11755 72

Page 73: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

• Most functions are too complex to hand-design – Particularly in high-dimensional spaces

• Instead, we will try to learn it from “training” examples – Input-output pairs

– In reality the training data will not be even remotely as dense as shown in the figure

• It will be several orders of magnitude sparser

Training from examples

73

Page 74: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

General approach to training

• Define an error between the actual network output for any parameter value and the desired output

– Error can be defined in a number of ways

• Many “Divergence” functions have been defined

– Typically defined as the sum of the error over individual training instances

Blue lines: error when function is below desired output

Black lines: error when function is above desired output

18797/11755 74

Page 75: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Recall: A note on activations

• Composing/learning networks using threshold “activations” is a combinatorial problem

– Exponentially hard to find the right solution

• The smoother differentiable activation functions enable learning through optimization 75

x1

x2

x3

xN

sigmoid tanh

Page 76: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Minimizing Error

• Problem: Find the parameters at which this function achieves a minimum

– Subject to any constraints we may pose

– Typically, this cannot be found using a closed-form formula

ERR

OR

18797/11755 76

Page 77: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

The Approach of Gradient Descent

• Iterative solution:

– Start at some point

– Find direction in which to shift this point to decrease error • This can be found from the “slope” of the function

– A positive slope moving left decreases error

– A negative slope moving right decreases error

– Shift point in this direction • The size of the shift depends on the slope 18797/11755 77

Page 78: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

The Approach of Gradient Descent

• Multi-dimensional function:

– “Slope” replaced by vector “gradient”

• From current point shift in direction opposite to gradient

– Size of shift depends on magnitude of gradient

y

yxfx

yxf

f),(

),(

18797/11755 78

Page 79: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

The Approach of Gradient Descent

• The gradient descent algorithm 𝑊 ← 𝑊 − 𝜂𝛻𝑊𝐸 𝑋;𝑊

Until error E(X;W) converges

𝜂 is the “step size”

Steps are smaller when the “slope” is smaller, because the optimum value is generally at a location of near-zero slope

18797/11755 79

Page 80: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

The Approach of Gradient Descent

• The gradient descent algorithm 𝑊 ← 𝑊 − 𝜂𝛻𝑊𝐸 𝑋;𝑊

Until error E(X;W) converges

𝜂 is the “step size”

Steps are smaller when the “slope” is smaller, because the optimum value is generally at a location of near-zero slope

Needs computation of gradient of error w.r.t. network parameters

18797/11755 80

Page 81: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Gradients: Algebraic Formulation

• The network is a nested function 𝑜 = 𝑓𝑁(𝑊𝑁𝑓𝑁−1 𝑊𝑁−1𝑓𝑁−2 𝑊𝑁−2…𝑓𝑘(𝑊𝑘𝑓𝑘−1(…𝑓1 𝑊1𝑋 …) … ))

⋮ ⋮ ⋮ ⋮ ⋮ ⋯ ⋯

𝑋 𝑓1 𝑾1 𝑓𝑘 𝑾𝑘 𝑓𝑘−1 𝑓𝑁−1

𝑾𝑁 𝑓𝑁

𝑂

𝐸 = 𝐷𝑖𝑣 𝑦, 𝑜 = | 𝑦 − 𝑜 |2

Weights matrix Activation function

18797/11755 81

Page 82: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

A note on algebra

⋮ ⋮ ⋮ ⋮ ⋮ ⋯ ⋯

𝑋 𝑓1 𝑾1 𝑓𝑘 𝑓𝑁−1

𝑾𝑁 𝑓𝑁 𝑂

𝒀

𝑬 Div(O,Y)

𝐼𝑘 𝑾𝑘

𝑓𝑘−1

T

kW EEkk 1 fI

1 kkk WI fUsing fk to represent the output of the activations rather than Ok for easier interpretation Using subscripts rather than superscripts to represent layer

18797/11755 82

Page 83: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

A note on algebra

EEkkk kI fI f

⋮ ⋮ ⋮ ⋮ ⋮ ⋯ ⋯

𝑋 𝑓1 𝑾1 𝑓𝑘 𝑓𝑁−1

𝑾𝑁 𝑓𝑁 𝑂

𝒀

𝑬 Div(O,Y)

𝐼𝑘

'

,

'

2,

'

1,

00

000

00

00

Lk

k

k

k

f

f

f

k

fI

E

f

f

f

Ekkk

k

k

k

k ffI f

'

1,

'

1,

'

1,

00

000

00

00

'

,

'

1,

'

Lk

k

k

f

f

f EEkk k fI f '

18797/11755 83

Page 84: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Graidents: Algebraic Formulation

• Generic rule

• 𝐟𝑘−1 is the vector of outputs of the k-1th layer

• 𝛻𝐟𝑘𝐸 is the gradient of the error w.r.t. the vector of outputs of the kth layer

• is the vector of derivatives of the activations of the kth layer w.r.t their inputs

– taken at current input 𝑊𝑘𝐟𝑘−1

T

kkW EEkk 1

'

ff f T

W EE Xf f11

'

1

'

kf

⋮ ⋮ ⋮ ⋮ ⋮ ⋯ ⋯

𝑋 𝑓1 𝑾1 𝑓𝑘 𝑾𝑘 𝑓𝑘−1 𝑓𝑁−1

𝑾𝑁 𝑓𝑁 𝑂

𝒀

𝑬 Div(O,Y)

18797/11755 84

Page 85: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Graidents: Algebraic Formulation

⋮ ⋮ ⋮ ⋮ ⋮ ⋯ ⋯

𝑋 𝑓1 𝑾1 𝑓𝑘 𝑾𝑘 𝑓𝑘−1 𝑓𝑁−1

𝑾𝑁 𝑓𝑁 𝑂

𝒀

𝑬 Div(O,Y)

• What is this?

T

kkW EEkk 1

' ff f

18797/11755 85

Page 86: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

A note on algebra

T

kk WIk

1f

⋮ ⋮ ⋮ ⋮ ⋮ ⋯ ⋯

𝑋 𝑓1 𝑾1 𝑾𝑘

𝑓𝑘−1 𝑓𝑁−1

𝑾𝑁 𝑓𝑁 𝑂

𝒀

𝑬 Div(O,Y)

𝐼𝑘

1 kkk WI f

𝑓𝑘

'

,

'

2,

'

1,

00

000

00

00

11

Lk

k

k

T

kkkk

f

f

f

Wkkk

fIf Iff

18797/11755 86

Page 87: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Graidents: Algebraic Formulation

T

kkW EEkk 1

' ff f

⋮ ⋮ ⋮ ⋮ ⋮ ⋯

𝑋 𝑓1 𝑾1 𝑓𝑘 𝑾𝑘 𝑓𝑘−1

𝑾𝑁 𝑓𝑁 𝑂

𝒀

𝑬 Div(O,Y)

EWEEkkkk k

T

kk 11

'

111)(

ffff ff

EWEkk k

T

k 1

'

11 ff f

⋮ ⋮ 𝑓𝑘+1 𝑾𝑘+1

18797/11755 87

Page 88: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Gradients: Algebraic Formulation

⋮ ⋮ ⋮ ⋮ ⋮ ⋯ ⋯

𝑋 𝑓1 𝑾1 𝑓𝑘 𝑾𝑘 𝑓𝑘−1 𝑓𝑁−1

𝑾𝑁 𝑓𝑁 𝑂

𝒀

𝑬 Div(O,Y)

N

O

O

YODiv

O

YODiv

YODivEN

),(

),(

),(1

f

T

kkW EEkk 1

'

ff f

EWEkk k

T

k 1

'

11 ff f

Output layer

18797/11755 88

Page 89: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Gradients: Algebraic Formulation

⋮ ⋮ ⋮ ⋮ ⋮ ⋯ ⋯

𝑋 𝑓1 𝑾1 𝑓𝑘 𝑾𝑘 𝑓𝑘−1 𝑓𝑁−1

𝑾𝑁 𝑓𝑁 𝑂

𝒀

𝑬 Div(O,Y)

T

kON

T

Nk

T

kk

T

kkW YODivWWWEk 1

''

22

'

11

' ),(... fffff

18797/11755 89

Page 90: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Gradients: Back Propagation

⋮ ⋮ ⋮ ⋮ ⋮ ⋯ ⋯

𝑋 𝑓1 𝑾1 𝑓𝑘 𝑾𝑘 𝑓𝑘−1 𝑓𝑁−1

𝑾𝑁 𝑓𝑁 𝑂

𝒀

𝑬 Div(O,Y)

Xf 0

Forward pass:

For k = 1 to N: )( 1 kkkk Wf ff

Initialize

Output NO f

18797/11755 90

Page 91: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Gradients: Back Propagation

⋮ ⋮ ⋮ ⋮ ⋮ ⋯ ⋯

𝑋 𝑓1 𝑾1 𝑓𝑘 𝑾𝑘 𝑓𝑘−1 𝑓𝑁−1

𝑾𝑁 𝑓𝑁 𝑂

𝒀

𝑬 Div(O,Y)

T

kkW EEkk 1

' ff f

EWEkk k

T

k ff f

'

1

),( YODivE ONf

Error divergence:

For k = N downto 1:

(actual recursion) 91

Page 92: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

BP: Local Formulation

• The network again

⋮ ⋮ ⋮ ⋮ ⋮ ⋯ ⋯

𝑋 𝑓1 𝑾1 𝑓𝑘 𝑾𝑘 𝑓𝑘−1 𝑓𝑁−1

𝑾𝑁 𝑓𝑁 𝑂

𝒀

𝑬 Div(O,Y)

18797/11755 92

Page 93: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Gradients: Local Computation

• Redrawn

• Separately label input and output of each node

fN

fN

𝑓𝑘 𝑓𝑁−1

ON IN

ON-1 IN-1 Ok Ik Ok-1 Ik-1

⋯ Div(O,Y) E

18797/11755 93

Page 94: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Forward Computation

i

i

ijj XWI 11

fN

fN

𝑓1

𝑓𝑁−1

ON IN

ON-1 IN-1 O1 I1 X

𝑓1

𝑓1

𝑓1

18797/11755 94

Page 95: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Forward Computation

i

i

ijj XWI 11

1 k

i

i

k

ij

k

j OWI

fN

fN

𝑓𝑘 𝑓𝑁−1

ON IN

ON-1 IN-1 Ok Ik Ok-1 Ik-1

18797/11755 95

Page 96: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Forward Computation

i

i

ijj XWI 11

1 k

i

i

k

ij

k

j OWI )( k

jk

k

j IfO

fN

fN

𝑓𝑘 𝑓𝑁−1

ON IN

ON-1 IN-1 Ok Ik Ok-1 Ik-1

18797/11755 96

Page 97: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Forward Computation

i

i

ijj XWI 11

1 k

i

i

k

ij

k

j OWI

)( k

jk

k

j IfO

fN

fN

𝑓𝑘 𝑓𝑁−1

ON IN

ON-1 IN-1 Ok Ik Ok-1 Ik-1

ITERATE FOR k = 1:N

for j = 1:layer-width

18797/11755 97

Page 98: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Div(O,Y)

Gradients: Backward Computation

fN

fN

𝑓𝑘 𝑓𝑁−1

ON IN

ON-1 IN-1 Ok Ik Ok-1 Ik-1

⋯ E

18797/11755 98

Page 99: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Div(O,Y)

Gradients: Backward Computation

fN

fN

𝑓𝑘 𝑓𝑁−1

ON IN

ON-1 IN-1 Ok Ik Ok-1 Ik-1

⋯ E

N

i

N

i O

YODiv

O

E

),(

18797/11755 99

Page 100: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Div(O,Y)

Gradients: Backward Computation

fN

fN

𝑓𝑘 𝑓𝑁−1

ON IN

ON-1 IN-1 Ok Ik Ok-1 Ik-1

⋯ E

N

i

N

i O

YODiv

O

E

),(

N

i

N

iNN

i

N

i

N

i

N

i O

EIf

O

E

dI

dO

I

E

)('

18797/11755 100

Page 101: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Div(O,Y)

Gradients: Backward Computation

fN

fN

𝑓𝑘 𝑓𝑁−1

ON IN

ON-1 IN-1 Ok Ik Ok-1 Ik-1

⋯ E

N

i

N

i O

YODiv

O

E

),(

N

i

N

iNN

i O

EIf

I

E

)('

jN

j

N

ij

jN

j

N

i

N

j

N

i I

EW

I

E

O

I

O

E11

Note: stuffotherWOI N

ij

N

i

N

j 1

18797/11755 101

Page 102: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Div(O,Y)

Gradients: Backward Computation

fN

fN

𝑓𝑘 𝑓𝑁−1

ON IN

ON-1 IN-1 Ok Ik Ok-1 Ik-1

⋯ E

N

i

N

i O

YODiv

O

E

),(

N

i

N

iNN

i O

EIf

I

E

)('

jN

j

N

ijN

i I

EW

O

E1k

i

k

ikk

i O

EIf

I

E

)('

18797/11755 102

Page 103: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Div(O,Y)

Gradients: Backward Computation

fN

fN

𝑓𝑘 𝑓𝑁−1

ON IN

ON-1 IN-1 Ok Ik Ok-1 Ik-1

⋯ E

N

i

N

i O

YODiv

O

E

),(

jk

j

k

ij

jk

j

k

i

k

j

k

i I

EW

I

E

O

I

O

E11

k

i

k

ikk

i O

EIf

I

E

)('

18797/11755 103

Page 104: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Div(O,Y)

Gradients: Backward Computation

fN

fN

𝑓𝑘 𝑓𝑁−1

ON IN

ON-1 IN-1 Ok Ik Ok-1 Ik-1

⋯ E

N

i

N

i O

YODiv

O

E

),(

k

j

k

ik

j

k

ij

k

j

k

ij I

EO

I

E

W

I

W

E

1

k

i

k

ikk

i O

EIf

I

E

)('

jk

j

k

ijk

i I

EW

O

E1

Wijk

18797/11755 104

Page 105: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Gradients: Backward Computation

N

i

N

i O

YODiv

O

E

),(

jk

i

k

ijk

i I

EW

O

E1

k

i

k

ikk

i O

EIf

I

E

)('

Div(O,Y)

fN

fN

ON IN

ON-1 IN-1 Ok Ik Ok-1 Ik-1

⋯ E

Initialize: Gradient w.r.t network output

For k = N..1 For i = 1:layer-width

k

j

k

ik

ij I

EO

W

E

1

18797/11755 105

Page 106: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Backpropagation: Multiplicative Networks

• Some types of networks have multiplicative combination

Ik-1

Ok-1

Zk

Wk

Forward: 11 k

k

k

j

k

i OOz

Backward:

k

i

k

kk

i

k

j

k

i

k

j z

EO

z

E

O

z

O

E

1

11 k

i

k

jk

k z

EO

O

E

1

1

18797/11755 106

Page 107: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Overall Approach • For each data instance

– Forward pass: Pass instance forward through the net. Store all intermediate outputs of all computation

– Backward pass: Sweep backward through the net, iteratively compute all derivatives w.r.t weights

• Actual Error is the sum of the error over all training instances

• Actual gradient is the sum or average of the derivatives computed for each training instance

𝐄 = 𝐷𝑖𝑣 𝑦(𝑥), 𝑜(𝑥) = 𝐸 𝑥

𝑥𝑥

𝛻𝑊𝐄 = 𝛻𝑊𝐸(𝑥)

𝑥

𝑊 ← 𝑊 − 𝜂𝛻𝑊𝐄

18797/11755 107

Page 108: Neural Networks - Carnegie Mellon Universitymlsp.cs.cmu.edu/courses/fall2016/slides/Lecture22.DNN.pdf · Class 22: MLSP, Fall 2016 Instructor: Bhiksha Raj . IMPORTANT ADMINSTRIVIA

Issues and Challenges

• What does it learn? • Speed

– Will not address this

• Does it do what we want it to do?

• Next class: – Variations of nnets

• MLP, Convolution, recurrence

– Nnets for various tasks • Image recognition, speech recognition, signal enhancement,

modelling language..

18797/11755 108