Intoduction To Neural Networks
Intoduction To Neural Networks
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Agenda
● Introduction to neural networks
○ Neural Networks
○ Neurons
● Activation functions
○ Sigmoid, Tanh, ReLU
● Feed Forward neural network
○ Layer Details
● Training a neural network
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Agenda
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Neural Networks
Artificial Neural Networks are computing systems inspired from biological neuron
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Neuron
Artificial neuron is inspired by biological neuron
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Activation function
In artificial neural networks, helps in defining the output of a node
when a input is given.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Types of activation function
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Question:
What is the range of Sigmoid, Tanh and ReLU?
Answer:
Sigmoid (0,1)
Tanh (-1, 1)
ReLU (0, max)
This is a 2-layer neural network. One is the hidden layer (having 3 neurons) and the
other is output layer (having 2 neurons).
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Layer details
Output layer
- Represents the output of the neural network
Hidden layer(s)
- Represents the intermediary nodes.
- It takes in a set of weighted input and produces output
through an activation function
Input layer
- Represents dimensions of the input vector (one
node for each dimension)
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Training a neural network
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Error and Loss function
● In general, error/loss for a neural network is difference between actual value and
predicted value.
● The goal is to minimize the error/loss.
● Loss Function is a function that is used to calculate the error.
● You can choose loss function based on the problem you have at hand.
● Loss functions are different for classification and regression
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Optimization
In optimization, the main aim is to find weights that reduce loss
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Gradient
● Gradient is calculated by optimization
function
● Gradient is the change in loss with change
in weights.
● The weights are modified according to
the calculated gradient.
● Same process keep on repeating until
the minima is reached
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Gradient descent
Gradient descent is a method that defines a cost function of parameters and uses a
systematic approach to optimize the values of parameters to get minimum cost function.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Question:
Do we get multiple local optimum solutions if we solve using gradient descent.
Answer:
False. We get only one local optimum solution after using gradient descent
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Backpropagation
- Backpropagation is used while training the feedforward networks
- It helps in efficiently calculating the gradient of the loss function w.r.t weights
- It helps in minimizing loss by updating the weights
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Learning rate and Momentum
● The learning rate is a hyperparameter which determines to what extent newly
acquired weights overrides old weights. In general it lies between 0 and 1.
● You can try different learning rates for a neural networks to improve results.
● Momentum is used to decide the weight on nodes from previous iterations. It
helps in improving training speed and also in avoiding local minimas.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Summary of the Neural Network Process
TensorFlow
Introduction
Agenda
- What is tensorflow?
- Why we are using tensorflow?
- TensorFlow 2.x
- TensorFlow 2.x - features and changes
- Changes with respect to TensorFlow 1.x
- Keras and it’s advantages
- Keras vs tf.keras
- Tutorials and guides
- Notes
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
TensorFlow
- TensorFlow is a machine learning library by Google
- It is open sourced
- It is mainly used for implementing neural networks
- It is an end-to-end platform, which means you can use it for building your
models from scratch to deploying them into a production environment
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Why TensorFlow for this course?
- Most used library for deep learning
- Easy transition from research to production
- Extensive industry support
- Easy deployment around servers, mobile devices, web platforms etc
- You can easily sort out the issues using GitHub, StackOverflow etc
- Used by world’s top AI companies
- Consistently updated with cutting edge changes
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Some technical reasons
- Easy and readable syntax
- Being a low-level library it provide more flexibility to developers to implement
their own functionalities and services
- Provides high level API for implementing advanced neural net architectures
- Distributed training
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
OS Support
TensorFlow is supported on following 64-bit systems:
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Language support
- Python
- C++
- JavaScript
- Java
- Go
- Swift
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
What is a Tensor?
The most obvious differences between NumPy arrays and tf.Tensors are:
NumPy Compatibility
Tensors are explicitly converted to NumPy ndarrays using their .numpy() method.
GPU Acceleration
● Many TensorFlow operations are
accelerated using the GPU for
computation.
● Without any annotations, TensorFlow
automatically decides whether to use the
GPU or CPU for an operation—copying
the tensor between CPU and GPU
memory, if necessary.
● Tensors produced by an operation are
typically backed by the memory of the
device on which the operation executed,
for example:
Coding with Tensorflow
Source
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Basics with TensorFlow
1. Import tensorflow library 4. Compile the model with optimizer, loss
function and error metric for back
2. Load/Read the data propagation
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
What’s new in TF2?
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Changes with respect to TensorFlow 1.x
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or
distribution prohibited
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution
prohibited
Keras
- Keras is a high-level neural network API
- Written and implemented in Python
- Can run on top of TensorFlow
- It was designed keeping fast experimentation in mind.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Keras advantages
● User-friendly
○ Simple and user friendly interface. Actionable feedbacks are also provided.
● Easy to extend
○ Gives freedom to add custom blocks to build on new ideas.
○ Cusrom layers, metrics, loss functions etc. can be defined easily.
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Keras vs tf.keras
- In TF2 instead of writing “import keras” you will write
“from tensorflow import keras”
- In colab, if you see the message “Using TensorFlow Backend”, you are not
using tensorflow 2.x implementation of keras
- tf.keras is the TensorFlow’s implementation of keras so it supports all the latest
changes in the TensorFlow version
- tf.keras is also better in support and maintenance
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Latest tutorials and guides
- https://www.tensorflow.org/tutorials
- https://www.tensorflow.org/guide
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Notes
- TensorFlow 2.0 announcement video:
https://www.youtube.com/watch? v=EqWsPO8DVXk
- Guide to convert your code from TF 1 to TF 2:
https://www.tensorflow.org/guide/migrate
- Detailed introduction video:
https://www.youtube.com/watch? v=5ECD8J 3dvDQ
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or distribution prohibited
Proprietary content. ©Great Learning. All Rights Reserved. Unauthorized use or
distribution prohibited
Thank you!
Happy Learning :)