SlideShare a Scribd company logo
Artifiial Neural Network:�
Keras and Tensorfow
AAA-Python Edition
Plan
●
1- Keras and Tensorfoo
●
2- MLP oith Tensorfoow High Level API
●
3- MLP oith Keras
●
4- More about tensorfoo
●
5- Tensorboard
3
1-Kerasand
Tensorfow
[By Amina Delali]
IntroductionIntroduction
●
Kerasw a high level API to build & train a deep learning
model.
●
It is oritten in python and runs on the top of Tensorfow
●
Implementationw
Application Programming
Interface: it defines how to
interact and use built-in
Keras modules.
We will talk about
in the next lesson
●
tf.keras : tensorflow implementation of keras
●
keras: Keras library (apart)
We will use the second
implementation
4
1-Kerasand
Tensorfow
[By Amina Delali]
KerasKeras
●
●
Tensorflow keras
version may no be
up to date (right
now, this is not the
case)
●
The default saving formats of
the model’s weights are
different
5
1-Kerasand
Tensorfow
[By Amina Delali]
TensorfooTensorfoo
●
Tensorfow� an open sourie library that enables you develop
and train ML models.
●
There is 2 important releases of Tensorfow�
➢
Versions 1.*.* defned by the APIs r1.*
➢
Versions 2.*.* defned by the APIs r2.*
●
Right now there is only one
version: TensorFlow 2.0 Alpha
defined by the API r2.0
●
Unlike the previous release, you
have to manually install it on
google colab.
In the previous
example, we wrote:
tf.VERSION
6
2-MLPwith
Tensorfow�High
LevelAPI
[By Amina Delali]
Using tensorfooUsing tensorfoo
●
There are 2 oays to implement artifcial neural netoorks in
tensorfoow
➢
Using the high level API
➢
Using the low level API
●
For example, building and training an MLP Using the high level API
is simple and trivial.
●
The loo level API, permits more fexibility in defning the
architecture of your model, but oill require more code.
●
In our frst example oe oill use the high level API. In other oorld,
oe oill use its premade estimators
●
Just a reminder, oe oill implement the same MLP oe defned in
the previous lesson.
7
2-MLPwith
Tensorfow�High
LevelAPI
[By Amina Delali]
StepsSteps
●
Elements to consider ohen using a pre-made estimator of
tensorfoow
➢
Defne at least one input funitionw it oill be used by the
estimator to create a structured data that it oill use later for
training and/or predicting. For our example, the function oill
return a tuple ofw
➔
Features� a dictionary oith the features names and their
corresponding values.
➔
The corresponding labels
➢
Defne the features iolumnsw used to build the estimator. In
our case, they oill be an array of the numerii feature
iolumns constructed using tensorfoo. They indicate the
features to use from the data returned from the previous defned
input funition.
➢
Build the estimator and use it for training, predicting … etc
The number of values will determine the
batch size
8
2-MLPwith
Tensorfow�High
LevelAPI
[By Amina Delali]
Build the MLPBuild the MLP
We will use sklearn to
use iris dataset
The features values
will be numeric
The keys correspond
to those used in the
input function
Approximately the
same as tansig function
Approximately the
same as tansig function
Tanh formula:
tanh(x)=
e
x
−e
− x
e
x
+e−x
To be able to use the
function for making
prediction
9
2-MLPwith
Tensorfow�High
LevelAPI
[By Amina Delali]
Training and evaluatingTraining and evaluating
●
Our input function dosen’t return fixed data values;the data must be passed as
parameters. This way, we can use the same input function for both training and
evaluating our model
●
The train and evaluate methods require a callable function. So, to use our defined
function, we have to define another one that calls our function with the desired
data parameter==> will lead to have two sepearate input functions: one for training
and one for testing.
●
To avoid defining 2 functions, we will use the python high order function
lambda: we give it a function’s definition, and it returns a function (without a
name).
Loss is
calculated
using softmax
cross entropy.
10
2-MLPwith
Tensorfow�High
LevelAPI
[By Amina Delali]
PredictingPredicting
●
We expected to have the
right predictions since we
used the test set that
scored 1.0 accuracy
Concerning the
labels array in the
training and
evaluating, we didn’t
have to convert it to
a multidimensional
array.
Concerning the
labels array in the
training and
evaluating, we didn’t
have to convert it to
a multidimensional
array.
We didn’t have to
define a function that
returns the
corresponding class for
each prediction (the
predicted class is in
the output of the
prediction).
We didn’t have to
define a function that
returns the
corresponding class for
each prediction (the
predicted class is in
the output of the
prediction).
11
3-MLPwith
Keras
[By Amina Delali]
Sequential modelSequential model
●
There is 2 oays to build a ANN oith kerasw
➢
Using a sequential modelw to build a sequential stack of layers.
Ideal for building simple, fully-connected netoorks.
➢
Using a funitional modelw ideal to build complex model
topologies.
●
To build our MLP oith the Sequential model, oe have tow
➢
Defne our layersw
➔
Specifying the number of neurons
➔
Selecting the activation function
➔
Defne hoo the neuron’s oeights (and the bias term) oill be
initialized
➔
Defne the optimization methodw it defnes hoo the learning is
performed.
➔
Defne the loss functionw the function to be minimized during
the learning.
12
3-MLPwith
Keras
[By Amina Delali]
Building our modelBuilding our model
It specifies a regular densely-
connected NN layer: applies the
activation function on a weighted
sum.
●
It specifies the function that will be
used to initialize the weights
●
The truncated normal
distribution: generates the same
values as the normal distribution
except that values more than two
standard deviations from the mean
are discarded and redrawn
●
The default values are:
➢
Mean: 0.0
➢
Standard deviation: 0.05
●
The input array will have the
shape : (*,4)
To be compatible
with our keras
example
13
3-MLPwith
Keras
[By Amina Delali]
TrainingTraining
The loss function will
be the mean square
error
The learning
algorithm will be the
stochastic gradient
descent
The metrics that will be returned by the
evaluation method in addition to the loss
function value.
For example:
The label 2 will be converted into 0. 0. 1.
14
3-MLPwith
Keras
[By Amina Delali]
Evaluating and predictingEvaluating and predicting
●
A correct
prediction
A wrong
prediction
We defined
the
prediction
class to
extract the
class
correspond
ing to the
highest
probability
We defined
the
prediction
class to
extract the
class
correspond
ing to the
highest
probability
15
3-MLPwith
Keras
[By Amina Delali]
Cross entropyCross entropy
●
For a multi-class classifcation, using the softmax activation
function, the cross entropy loss function is a better choice to
compute the cost to minimize.
●
It takes into consideration the values of the probabilities
returned by the output neurons instead of just taking into
account correct or the orong classifcationw
J(w)=
−1
m
∑
i=1
m
∑
k=1
K
yk
(i)
log( ^pk
(i)
)
Predicted
probability for
the instance i
for the class
k
The true label value,
== 1 if the class of
the instance (i) is k,
otherwise it equals to
0
Number
of
instances
Number
of
Classes
The
weights
to be
updated
16
3-MLPwith
Keras
[By Amina Delali]
Applying the cross entropyApplying the cross entropy
●
We have same
accuracy result as we
had with tensorflow
(because of the use
of the cross entropy
loss function)
We changed only the
loss function
We don’t have to convert our
labels array
But we still need a
function to extract the
predicted class
17
4-Moreabout
tensorfow
[By Amina Delali]
Graph, tensor, operationGraph, tensor, operation
●
With tensorfow it is possible to defne your model as a graph.
●
The concept is simplew
➢
You defne your graphw the steps of the computation( the
tensorfoo program)
➢
You run your graph
●
Your graph may containw
➢
Tensorsw the central unit of data. Arrays of any number of
dimension (a scalar is a tensor oith dimension (rank:) 0). They
also represent the Edges of the graph.
➢
Operationsw the nodes of the graph. They describe calculations
oith tensors . We can use constructor for operations as folloow
➔
tensorfoo.constant(3.5)w creates an operation that oill
produce the value 3.5 and add it to the default graph
(TensorFloo provides a default graph that is an implicit
argument to all API functions in the same context.)
18
4-Moreabout
tensorfow
[By Amina Delali]
TensorboardTensorboard
●
Tenorboard is a suite of visualization tools that can be utilised
to visualize TensorFloo graph, plot quantitative metriis about
the exeiution of your graph.
●
To use Tensorboard oith google iolab, you can use the library
tensorboardiolab�
By clicking on this link
you can access to
tensorboard
19
5-Tensorboard
[By Amina Delali]
A simple graph in tensorboardA simple graph in tensorboard
●
Tensor produced by the
operation tf.constant
Log file generated in
“./Graph/”
Visualization generated
in tensorboard
20
5-Tensorboard
[By Amina Delali]
A simple graph in tensorboard (suite)A simple graph in tensorboard (suite)
If you click on the node
“add”
21
5-Tensorboard
[By Amina Delali]
Tensorboard oith KerasTensorboard oith Keras
We use the variable we already
defined by TensorBoardColab() call
Since we specified
“accuracy” and “mae”
as metrics, their
progression graphs will
be generated in
tenorboard
22
5-Tensorboard
[By Amina Delali]
Tensorboard oith KerasTensorboard oith Keras
The generated graph
Referenies
●
Keras, httpsw//ooo.tensorfoo.org/guide/keras
●
TensorBoardw Visualizing Learning,
httpsw//ooo.tensorfoo.org/guide/summaries_and_tensorboard
●
Keras 2.2.4, httpsw//pypi.org/project/Keras/
●
Premade Estimators
httpsw//ooo.tensorfoo.org/guide/premade_estimators
●
Feature Columns,
httpsw//ooo.tensorfoo.org/guide/feature_columns
●
tansig ,
httpsw//edoras.sdsu.edu/doc/matlab/toolbox/nnet/tansig.html
●
Hyperbolic functions
httpsw//ooo.math10.com/en/algebra/hyperbolic-
functions/hyperbolic-functions.html
●
Tensorfoo, Introduction,
httpsw//ooo.tensorfoo.org/guide/loo_level_intro
●
Hands-on machine learning oith Scikit-Learn and TensorFloow
concepts, tools, and techniques to build intelligent systems.
O’Reilly Media, Inc.
Thank:
you!
FOR ALL YOUR TIME

More Related Content

PPTX
Regularization in deep learning
PDF
Aaa ped-22-Artificial Neural Network: Introduction to ANN
PPTX
Back propagation network
PPTX
Ot regularization and_gradient_descent
PPT
2.5 backpropagation
PPT
Principles of soft computing-Associative memory networks
PPTX
Deep learning: Mathematical Perspective
PPTX
Regularization in deep learning
Aaa ped-22-Artificial Neural Network: Introduction to ANN
Back propagation network
Ot regularization and_gradient_descent
2.5 backpropagation
Principles of soft computing-Associative memory networks
Deep learning: Mathematical Perspective

What's hot (20)

PDF
PPT
Classification using back propagation algorithm
DOCX
Backpropagation
PDF
Overview of TensorFlow For Natural Language Processing
PPTX
Hopfield Networks
PPTX
Associative memory network
ODP
Best practices in Java
PPT
Counterpropagation NETWORK
PPTX
Deep learning with TensorFlow
PDF
Training Neural Networks
PDF
Open mp directives
PPTX
Python Closures Explained | What are Closures in Python | Python Closures
PPT
Very Small Tutorial on Terrier 3.0 Retrieval Toolkit
PDF
Artificial Neural Network Lecture 6- Associative Memories & Discrete Hopfield...
PDF
TFFN: Two Hidden Layer Feed Forward Network using the randomness of Extreme L...
PPT
Fundamentals of matlab programming
PPT
Java ppt
PPT
Effective Java - Enum and Annotations
DOCX
First fare 2010 java-introduction
PDF
Text Classification Powered by Apache Mahout and Lucene
Classification using back propagation algorithm
Backpropagation
Overview of TensorFlow For Natural Language Processing
Hopfield Networks
Associative memory network
Best practices in Java
Counterpropagation NETWORK
Deep learning with TensorFlow
Training Neural Networks
Open mp directives
Python Closures Explained | What are Closures in Python | Python Closures
Very Small Tutorial on Terrier 3.0 Retrieval Toolkit
Artificial Neural Network Lecture 6- Associative Memories & Discrete Hopfield...
TFFN: Two Hidden Layer Feed Forward Network using the randomness of Extreme L...
Fundamentals of matlab programming
Java ppt
Effective Java - Enum and Annotations
First fare 2010 java-introduction
Text Classification Powered by Apache Mahout and Lucene
Ad

Similar to Aaa ped-23-Artificial Neural Network: Keras and Tensorfow (20)

PDF
TensorFlow and Keras: An Overview
PPTX
slide-keras-tf.pptx
PPTX
Deep Learning, Keras, and TensorFlow
PPTX
Demystifying-AI-Frameworks-TensorFlow-PyTorch-JAX-and-More (1).pptx
PDF
Machine Learning with TensorFlow 2
PDF
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
PPTX
Keras on tensorflow in R & Python
PDF
TensorFlow meetup: Keras - Pytorch - TensorFlow.js
PPTX
TechEvent Machine Learning
PDF
Keras and TensorFlow
PDF
OpenPOWER Workshop in Silicon Valley
PPTX
Deep Learning in your Browser: powered by WebGL
PPTX
python_libraries_for_artificial_intelligence.pptx
PPTX
Machine Learning Toolssssssssssssss.pptx
PDF
Getting Started with Keras and TensorFlow - StampedeCon AI Summit 2017
PPTX
Deep Learning, Scala, and Spark
PPTX
H2 o berkeleydltf
PDF
Intro to TensorFlow and PyTorch Workshop at Tubular Labs
PDF
Neural networks using tensor flow in amazon deep learning server
TensorFlow and Keras: An Overview
slide-keras-tf.pptx
Deep Learning, Keras, and TensorFlow
Demystifying-AI-Frameworks-TensorFlow-PyTorch-JAX-and-More (1).pptx
Machine Learning with TensorFlow 2
A Tale of Three Deep Learning Frameworks: TensorFlow, Keras, & PyTorch with B...
Keras on tensorflow in R & Python
TensorFlow meetup: Keras - Pytorch - TensorFlow.js
TechEvent Machine Learning
Keras and TensorFlow
OpenPOWER Workshop in Silicon Valley
Deep Learning in your Browser: powered by WebGL
python_libraries_for_artificial_intelligence.pptx
Machine Learning Toolssssssssssssss.pptx
Getting Started with Keras and TensorFlow - StampedeCon AI Summit 2017
Deep Learning, Scala, and Spark
H2 o berkeleydltf
Intro to TensorFlow and PyTorch Workshop at Tubular Labs
Neural networks using tensor flow in amazon deep learning server
Ad

More from AminaRepo (20)

PDF
Aaa ped-21-Recommender Systems: Content-based Filtering
PDF
Aaa ped-20-Recommender Systems: Model-based collaborative filtering
PDF
Aaa ped-19-Recommender Systems: Neighborhood-based Filtering
PDF
Aaa ped-18-Unsupervised Learning: Association Rule Learning
PDF
Aaa ped-17-Unsupervised Learning: Dimensionality reduction
PDF
Aaa ped-16-Unsupervised Learning: clustering
PDF
Aaa ped-15-Ensemble Learning: Random Forests
PDF
Aaa ped-14-Ensemble Learning: About Ensemble Learning
PDF
Aaa ped-12-Supervised Learning: Support Vector Machines & Naive Bayes Classifer
PDF
Aaa ped-11-Supervised Learning: Multivariable Regressor & Classifers
PDF
Aaa ped-10-Supervised Learning: Introduction to Supervised Learning
PDF
Aaa ped-9-Data manipulation: Time Series & Geographical visualization
PDF
Aaa ped-Data-8- manipulation: Plotting and Visualization
PDF
Aaa ped-8- Data manipulation: Data wrangling, aggregation, and group operations
PDF
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
PDF
Aaa ped-5-Data manipulation: Pandas
PDF
Aaa ped-4- Data manipulation: Numpy
PDF
Aaa ped-3. Pythond: advanced concepts
PDF
Aaa ped-2- Python: Basics
PDF
Aaa ped-1- Python: Introduction to AI, Python and Colab
Aaa ped-21-Recommender Systems: Content-based Filtering
Aaa ped-20-Recommender Systems: Model-based collaborative filtering
Aaa ped-19-Recommender Systems: Neighborhood-based Filtering
Aaa ped-18-Unsupervised Learning: Association Rule Learning
Aaa ped-17-Unsupervised Learning: Dimensionality reduction
Aaa ped-16-Unsupervised Learning: clustering
Aaa ped-15-Ensemble Learning: Random Forests
Aaa ped-14-Ensemble Learning: About Ensemble Learning
Aaa ped-12-Supervised Learning: Support Vector Machines & Naive Bayes Classifer
Aaa ped-11-Supervised Learning: Multivariable Regressor & Classifers
Aaa ped-10-Supervised Learning: Introduction to Supervised Learning
Aaa ped-9-Data manipulation: Time Series & Geographical visualization
Aaa ped-Data-8- manipulation: Plotting and Visualization
Aaa ped-8- Data manipulation: Data wrangling, aggregation, and group operations
Aaa ped-6-Data manipulation: Data Files, and Data Cleaning & Preparation
Aaa ped-5-Data manipulation: Pandas
Aaa ped-4- Data manipulation: Numpy
Aaa ped-3. Pythond: advanced concepts
Aaa ped-2- Python: Basics
Aaa ped-1- Python: Introduction to AI, Python and Colab

Recently uploaded (20)

PDF
Biophysics 2.pdffffffffffffffffffffffffff
PPT
The World of Physical Science, • Labs: Safety Simulation, Measurement Practice
PDF
ELS_Q1_Module-11_Formation-of-Rock-Layers_v2.pdf
PPTX
2Systematics of Living Organisms t-.pptx
PDF
VARICELLA VACCINATION: A POTENTIAL STRATEGY FOR PREVENTING MULTIPLE SCLEROSIS
PPT
POSITIONING IN OPERATION THEATRE ROOM.ppt
PPTX
G5Q1W8 PPT SCIENCE.pptx 2025-2026 GRADE 5
PPTX
2. Earth - The Living Planet Module 2ELS
PDF
Unveiling a 36 billion solar mass black hole at the centre of the Cosmic Hors...
PPTX
EPIDURAL ANESTHESIA ANATOMY AND PHYSIOLOGY.pptx
PPTX
Classification Systems_TAXONOMY_SCIENCE8.pptx
PDF
Formation of Supersonic Turbulence in the Primordial Star-forming Cloud
PPTX
Protein & Amino Acid Structures Levels of protein structure (primary, seconda...
PPTX
neck nodes and dissection types and lymph nodes levels
PDF
HPLC-PPT.docx high performance liquid chromatography
PPTX
GEN. BIO 1 - CELL TYPES & CELL MODIFICATIONS
PPTX
The KM-GBF monitoring framework – status & key messages.pptx
PDF
The scientific heritage No 166 (166) (2025)
PDF
SEHH2274 Organic Chemistry Notes 1 Structure and Bonding.pdf
PPTX
cpcsea ppt.pptxssssssssssssssjjdjdndndddd
Biophysics 2.pdffffffffffffffffffffffffff
The World of Physical Science, • Labs: Safety Simulation, Measurement Practice
ELS_Q1_Module-11_Formation-of-Rock-Layers_v2.pdf
2Systematics of Living Organisms t-.pptx
VARICELLA VACCINATION: A POTENTIAL STRATEGY FOR PREVENTING MULTIPLE SCLEROSIS
POSITIONING IN OPERATION THEATRE ROOM.ppt
G5Q1W8 PPT SCIENCE.pptx 2025-2026 GRADE 5
2. Earth - The Living Planet Module 2ELS
Unveiling a 36 billion solar mass black hole at the centre of the Cosmic Hors...
EPIDURAL ANESTHESIA ANATOMY AND PHYSIOLOGY.pptx
Classification Systems_TAXONOMY_SCIENCE8.pptx
Formation of Supersonic Turbulence in the Primordial Star-forming Cloud
Protein & Amino Acid Structures Levels of protein structure (primary, seconda...
neck nodes and dissection types and lymph nodes levels
HPLC-PPT.docx high performance liquid chromatography
GEN. BIO 1 - CELL TYPES & CELL MODIFICATIONS
The KM-GBF monitoring framework – status & key messages.pptx
The scientific heritage No 166 (166) (2025)
SEHH2274 Organic Chemistry Notes 1 Structure and Bonding.pdf
cpcsea ppt.pptxssssssssssssssjjdjdndndddd

Aaa ped-23-Artificial Neural Network: Keras and Tensorfow

  • 1. Artifiial Neural Network:� Keras and Tensorfow AAA-Python Edition
  • 2. Plan ● 1- Keras and Tensorfoo ● 2- MLP oith Tensorfoow High Level API ● 3- MLP oith Keras ● 4- More about tensorfoo ● 5- Tensorboard
  • 3. 3 1-Kerasand Tensorfow [By Amina Delali] IntroductionIntroduction ● Kerasw a high level API to build & train a deep learning model. ● It is oritten in python and runs on the top of Tensorfow ● Implementationw Application Programming Interface: it defines how to interact and use built-in Keras modules. We will talk about in the next lesson ● tf.keras : tensorflow implementation of keras ● keras: Keras library (apart) We will use the second implementation
  • 4. 4 1-Kerasand Tensorfow [By Amina Delali] KerasKeras ● ● Tensorflow keras version may no be up to date (right now, this is not the case) ● The default saving formats of the model’s weights are different
  • 5. 5 1-Kerasand Tensorfow [By Amina Delali] TensorfooTensorfoo ● Tensorfow� an open sourie library that enables you develop and train ML models. ● There is 2 important releases of Tensorfow� ➢ Versions 1.*.* defned by the APIs r1.* ➢ Versions 2.*.* defned by the APIs r2.* ● Right now there is only one version: TensorFlow 2.0 Alpha defined by the API r2.0 ● Unlike the previous release, you have to manually install it on google colab. In the previous example, we wrote: tf.VERSION
  • 6. 6 2-MLPwith Tensorfow�High LevelAPI [By Amina Delali] Using tensorfooUsing tensorfoo ● There are 2 oays to implement artifcial neural netoorks in tensorfoow ➢ Using the high level API ➢ Using the low level API ● For example, building and training an MLP Using the high level API is simple and trivial. ● The loo level API, permits more fexibility in defning the architecture of your model, but oill require more code. ● In our frst example oe oill use the high level API. In other oorld, oe oill use its premade estimators ● Just a reminder, oe oill implement the same MLP oe defned in the previous lesson.
  • 7. 7 2-MLPwith Tensorfow�High LevelAPI [By Amina Delali] StepsSteps ● Elements to consider ohen using a pre-made estimator of tensorfoow ➢ Defne at least one input funitionw it oill be used by the estimator to create a structured data that it oill use later for training and/or predicting. For our example, the function oill return a tuple ofw ➔ Features� a dictionary oith the features names and their corresponding values. ➔ The corresponding labels ➢ Defne the features iolumnsw used to build the estimator. In our case, they oill be an array of the numerii feature iolumns constructed using tensorfoo. They indicate the features to use from the data returned from the previous defned input funition. ➢ Build the estimator and use it for training, predicting … etc The number of values will determine the batch size
  • 8. 8 2-MLPwith Tensorfow�High LevelAPI [By Amina Delali] Build the MLPBuild the MLP We will use sklearn to use iris dataset The features values will be numeric The keys correspond to those used in the input function Approximately the same as tansig function Approximately the same as tansig function Tanh formula: tanh(x)= e x −e − x e x +e−x To be able to use the function for making prediction
  • 9. 9 2-MLPwith Tensorfow�High LevelAPI [By Amina Delali] Training and evaluatingTraining and evaluating ● Our input function dosen’t return fixed data values;the data must be passed as parameters. This way, we can use the same input function for both training and evaluating our model ● The train and evaluate methods require a callable function. So, to use our defined function, we have to define another one that calls our function with the desired data parameter==> will lead to have two sepearate input functions: one for training and one for testing. ● To avoid defining 2 functions, we will use the python high order function lambda: we give it a function’s definition, and it returns a function (without a name). Loss is calculated using softmax cross entropy.
  • 10. 10 2-MLPwith Tensorfow�High LevelAPI [By Amina Delali] PredictingPredicting ● We expected to have the right predictions since we used the test set that scored 1.0 accuracy Concerning the labels array in the training and evaluating, we didn’t have to convert it to a multidimensional array. Concerning the labels array in the training and evaluating, we didn’t have to convert it to a multidimensional array. We didn’t have to define a function that returns the corresponding class for each prediction (the predicted class is in the output of the prediction). We didn’t have to define a function that returns the corresponding class for each prediction (the predicted class is in the output of the prediction).
  • 11. 11 3-MLPwith Keras [By Amina Delali] Sequential modelSequential model ● There is 2 oays to build a ANN oith kerasw ➢ Using a sequential modelw to build a sequential stack of layers. Ideal for building simple, fully-connected netoorks. ➢ Using a funitional modelw ideal to build complex model topologies. ● To build our MLP oith the Sequential model, oe have tow ➢ Defne our layersw ➔ Specifying the number of neurons ➔ Selecting the activation function ➔ Defne hoo the neuron’s oeights (and the bias term) oill be initialized ➔ Defne the optimization methodw it defnes hoo the learning is performed. ➔ Defne the loss functionw the function to be minimized during the learning.
  • 12. 12 3-MLPwith Keras [By Amina Delali] Building our modelBuilding our model It specifies a regular densely- connected NN layer: applies the activation function on a weighted sum. ● It specifies the function that will be used to initialize the weights ● The truncated normal distribution: generates the same values as the normal distribution except that values more than two standard deviations from the mean are discarded and redrawn ● The default values are: ➢ Mean: 0.0 ➢ Standard deviation: 0.05 ● The input array will have the shape : (*,4) To be compatible with our keras example
  • 13. 13 3-MLPwith Keras [By Amina Delali] TrainingTraining The loss function will be the mean square error The learning algorithm will be the stochastic gradient descent The metrics that will be returned by the evaluation method in addition to the loss function value. For example: The label 2 will be converted into 0. 0. 1.
  • 14. 14 3-MLPwith Keras [By Amina Delali] Evaluating and predictingEvaluating and predicting ● A correct prediction A wrong prediction We defined the prediction class to extract the class correspond ing to the highest probability We defined the prediction class to extract the class correspond ing to the highest probability
  • 15. 15 3-MLPwith Keras [By Amina Delali] Cross entropyCross entropy ● For a multi-class classifcation, using the softmax activation function, the cross entropy loss function is a better choice to compute the cost to minimize. ● It takes into consideration the values of the probabilities returned by the output neurons instead of just taking into account correct or the orong classifcationw J(w)= −1 m ∑ i=1 m ∑ k=1 K yk (i) log( ^pk (i) ) Predicted probability for the instance i for the class k The true label value, == 1 if the class of the instance (i) is k, otherwise it equals to 0 Number of instances Number of Classes The weights to be updated
  • 16. 16 3-MLPwith Keras [By Amina Delali] Applying the cross entropyApplying the cross entropy ● We have same accuracy result as we had with tensorflow (because of the use of the cross entropy loss function) We changed only the loss function We don’t have to convert our labels array But we still need a function to extract the predicted class
  • 17. 17 4-Moreabout tensorfow [By Amina Delali] Graph, tensor, operationGraph, tensor, operation ● With tensorfow it is possible to defne your model as a graph. ● The concept is simplew ➢ You defne your graphw the steps of the computation( the tensorfoo program) ➢ You run your graph ● Your graph may containw ➢ Tensorsw the central unit of data. Arrays of any number of dimension (a scalar is a tensor oith dimension (rank:) 0). They also represent the Edges of the graph. ➢ Operationsw the nodes of the graph. They describe calculations oith tensors . We can use constructor for operations as folloow ➔ tensorfoo.constant(3.5)w creates an operation that oill produce the value 3.5 and add it to the default graph (TensorFloo provides a default graph that is an implicit argument to all API functions in the same context.)
  • 18. 18 4-Moreabout tensorfow [By Amina Delali] TensorboardTensorboard ● Tenorboard is a suite of visualization tools that can be utilised to visualize TensorFloo graph, plot quantitative metriis about the exeiution of your graph. ● To use Tensorboard oith google iolab, you can use the library tensorboardiolab� By clicking on this link you can access to tensorboard
  • 19. 19 5-Tensorboard [By Amina Delali] A simple graph in tensorboardA simple graph in tensorboard ● Tensor produced by the operation tf.constant Log file generated in “./Graph/” Visualization generated in tensorboard
  • 20. 20 5-Tensorboard [By Amina Delali] A simple graph in tensorboard (suite)A simple graph in tensorboard (suite) If you click on the node “add”
  • 21. 21 5-Tensorboard [By Amina Delali] Tensorboard oith KerasTensorboard oith Keras We use the variable we already defined by TensorBoardColab() call Since we specified “accuracy” and “mae” as metrics, their progression graphs will be generated in tenorboard
  • 22. 22 5-Tensorboard [By Amina Delali] Tensorboard oith KerasTensorboard oith Keras The generated graph
  • 23. Referenies ● Keras, httpsw//ooo.tensorfoo.org/guide/keras ● TensorBoardw Visualizing Learning, httpsw//ooo.tensorfoo.org/guide/summaries_and_tensorboard ● Keras 2.2.4, httpsw//pypi.org/project/Keras/ ● Premade Estimators httpsw//ooo.tensorfoo.org/guide/premade_estimators ● Feature Columns, httpsw//ooo.tensorfoo.org/guide/feature_columns ● tansig , httpsw//edoras.sdsu.edu/doc/matlab/toolbox/nnet/tansig.html ● Hyperbolic functions httpsw//ooo.math10.com/en/algebra/hyperbolic- functions/hyperbolic-functions.html ● Tensorfoo, Introduction, httpsw//ooo.tensorfoo.org/guide/loo_level_intro ● Hands-on machine learning oith Scikit-Learn and TensorFloow concepts, tools, and techniques to build intelligent systems. O’Reilly Media, Inc.