Neural Deep Learning
Neural Deep Learning
Neural Networks
ANN
● Theory Topics
○ Perceptron Model to Neural Networks
○ Activation Functions
○ Cost Functions
○ Feed Forward Networks
○ BackPropagation
ANN
● Coding Topics
○ TensorFlow 2.0 Keras Syntax
○ ANN with Keras
■ Regression
■ Classification
○ Exercises for Keras ANN
○ Tensorboard Visualizations
Let’s get started!
Perceptron Model
Perceptron model
Dendrites
Axon
Nucleus
Perceptron model
Dendrites
Axon
Nucleus
Perceptron model
● Perceptron Model
Inputs Output
Perceptron model
● Let’s work through a simple example
x1
Inputs Output
x2
Perceptron model
● Let’s work through a simple example
x1
Inputs f(X) Output
x2
Perceptron model
● Let’s work through a simple example
x1
y
Inputs f(X) Output
x2
Perceptron model
● If f(X) is just a sum, then y=x1+x2
x1
y
Inputs f(X) Output
x2
Perceptron model
● Realistically, we would want to be able to
adjust some parameter in order to “learn”
x1
y
Inputs f(X) Output
x2
Perceptron model
● Let’s add an adjustable weight we multiply
against x
w1
x1
y
Inputs f(X) Output
w2
x2
Perceptron model
● Now y = x1w1 + x2w2
w1
x1
y
Inputs f(X) Output
w2
x2
Perceptron model
● We could update the weights to effect y
w1
x1
y
Inputs f(X) Output
w2
x2
Perceptron model
● But what if an x is zero? w won’t change
anything!
w1
x1
y
Inputs f(X) Output
w2
x2
Perceptron model
● Let’s add in a bias term b to the inputs.
w1
x1
y
Inputs f(X) Output
w2
x2
Perceptron model
● Let’s add in a bias term b to the inputs.
*w1 + b
x1
y
Inputs f(X) Output
x2 *w2 + b
Perceptron model
● y = (x1w1 + b) + (x2w2 + b)
*w1 + b
x1
y
Inputs f(X) Output
x2 *w2 + b
Perceptron model
● We can expand this to a generalization:
x1
*w1 + b y
Inputs f(X) Output
x2 *w2 + b
xn *wn + b
Perceptron model
xn *wn + b
Perceptron model
● Theoretically for any number of biases,
there exists a bias that is the sum.
x1
*w1 + b y
Inputs f(X) Output
x2 *w2 + b
xn *wn + b
Perceptron model
● Theoretically for any number of biases,
there exists a bias that is the sum.
x1
*w1 y
Inputs f(X) Output
x2 *w2
xn *wn
B
Perceptron model
● Theoretically for any number of biases,
there exists a bias that is the sum.
x1
*w1 y
Inputs f(X) Output
x2 *w2
xn *wn
B = b1 + b2 + … +bn
Perceptron model
● Terminology:
○ Input Layer: First layer that directly
accepts real data values
○ Hidden Layer: Any layer between input
and output layers
○ Output Layer: The final estimate of the
output.
Neural Networks
w1
x1
y
Inputs f(X) Output
w2
+b
x2
Perceptron model
● If we had a binary classification problem,
we would want an output of either 0 or 1.
w1
x1
y
Inputs f(X) Output
w2
+b
x2
Neural Networks
0
0
z = wx + b
Deep Learning
0
0
z = wx + b
Deep Learning
0
0
z = wx + b
Deep Learning
0
0
z = wx + b
Deep Learning
0
0
z = wx + b
Deep Learning
0
0
z = wx + b
Deep Learning
1
Output
0
0
z = wx + b
Deep Learning
0
0
z = wx + b
Deep Learning
0
0
z = wx + b
Deep Learning
0
0
z = wx + b
Deep Learning
1
Output
-1
0
Deep Learning
-1
0
Deep Learning
Output
0
z = wx + b
Deep Learning
● Non-Exclusive Classes
■ A data point can have multiple
classes/categories assigned to it
○ Photos can have multiple tags (e.g.
beach, family, vacation, etc…)
Deep Learning
Hidden Layers
Multiclass Classification
Class One
Class Two
Hidden Layers
Class N
Deep Learning
... ...
● Non-Exclusive Classes
A B C
Data Point 1 A,B
Data Point 1 1 1 0
Data Point 2 A
Data Point 2 1 0 0
Data Point 3 C,B
Data Point 3 0 1 1
... ...
... ... ... ...
Data Point N B
Data Point N 0 1 0
Deep Learning
● Non-exclusive
○ Sigmoid function
■ Each neuron will output a value
between 0 and 1, indicating the
probability of having that class
assigned to it.
Multiclass Classification
Class One
Class Two
Hidden Layers
Class N
Multiclass Classification
1
Class Two 0.2
0
Hidden Layers
1
Class N 0.3
0
Multiclass Classification
1
Class Two 0.6
0
Hidden Layers
1
Class N 0.2
0
Deep Learning
● Non-exclusive
○ Sigmoid function
■ Keep in mind this allows each neuron
to output independent of the other
classes, allowing for a single data
point fed into the function to have
multiple classes assigned to it.
Deep Learning
● Softmax Function
Deep Learning
● Review
○ Perceptrons expanded to neural
network model
○ Weights and Biases
○ Activation Functions
○ Time to learn about Cost Functions!
Cost Functions and
Gradient Descent
Deep Learning
w
Deep Learning
w
Deep Learning
w
Deep Learning
wmin
Deep Learning
wmin
Deep Learning
w
Deep Learning
w
Deep Learning
w
Deep Learning
w
Deep Learning
wmin
Deep Learning
wmin
Deep Learning
wmin
Deep Learning
wmin
Deep Learning
wmin
Deep Learning
wmin
Deep Learning
wmin
Deep Learning
wmin
Deep Learning
● Our steps:
C(w)
wmin
Deep Learning
wmin
Deep Learning
wmin
Deep Learning
wmin
Deep Learning
● Review:
○ Cost Functions
○ Gradient Descent
○ Adam Optimizer
○ Quadratic Cost and Cross-Entropy
Deep Learning
L-1 L
Deep Learning
L-1 L
Deep Learning
L-1 L
Deep Learning
L-1 L
Deep Learning
L-1 L
Deep Learning
L-1 L
Deep Learning
L-1 L
Deep Learning
● Early Stopping
○ Keras can automatically stop training
based on a loss condition on the
validation data passed during the
model.fit() call.
Deep Learning
● Dropout Layers
○ Dropout can be added to layers to
“turn off” neurons during training to
prevent overfitting.
Deep Learning
● Dropout Layers
○ Each Dropout layer will “drop” a
user-defined percentage of neuron
units in the previous layer every batch.
Introduction to Project
Deep Learning
● Completely Solo
○ Read the introduction in the Exercise
notebook, then proceed with your own
methods to build a predictive model.
Deep Learning