What is Deep Learning?

Deep Learning is the subfield of AI so before getting into this let’s understand what Artificial Intelligence is.

Artificial Intelligence

AI is something that makes machines intelligent. Nowadays as technologies are moving rapidly, everything is evolving with the help of Artificial Intelligence. It helps machines to mimic the cognitive functions of humans like talking, speaking, seeing, and most importantly understanding languages.

AI understands the patterns by itself which gives us the ability to train our computers to do many tasks which are very repetitive without any human intervention.

With the help of AI, you can do things that are impossible to do in rule-based programming. If you want to recognize any image then you have to write manually the rules which describe that particular image’s features which is very much impossible even if you write a code for one image but if you change the image a bit then you have to write it again. And imagine if you have thousands of images then how much it will be difficult to describe features for every image.

Now AI comes into the picture which will extract the features by itself and give us the rules which will recognize the image you only need to pass the images and their label(any name that defines that image) and it learns all the patterns and gives you the model which detects all similar images very easily. Isn’t it feel magical? This is just one example of AI.

There are so many applications of AI in the field of Medical Science, Finance, Agriculture, and, many more.

Now, as we discussed what is AI, let’s understand what deep learning is and how you can create a deep learning model.

Deep Learning

Deep Learning is the subfield of AI which involves creating an AI model with the help of Neural Networks. The word “Deep” here is significant in that it can learn or understand the data very deeply and intuitively which helps in getting very accurate results for the model. And the model here is a kind of an AI task that will give some output on a particular type of input.

Neural Networks require a lot of Data to perform well. As you all know Machine Learning is also a subfield of AI which covers the statistical part of AI and there are so many Traditional Algorithms(Logistic Regression, KNN, SVM, etc.)
Which is very intuitive.

Both Neural Networks and Machine Learning have their pros and cons in practical.

Let’s suppose you have less amount of data then it’s preferable to use Machine Learning, it might be possible that it performs better than the NNs. But if you have a huge dataset then it’s better to choose NNs over Machine learning because it is much faster than the Machine learning algorithms and can perform much better.

To learn Deep Learning concepts you have to understand what is Neural Network.

Neural Network

Neural Network is an artificial Architecture just like a human brain and created to
mimics the way the human brain operates.

According to Wikipedia ” A neural network is a network or circuit of neurons, or in a modern sense, an artificial neural network, composed of artificial neurons or nodes.”

Neural Network is also known as an Artificial Neural Network(ANN). It takes some input data and is trained on it to predict output on similar new data.

The architecture of Neural Network

Neural Network consists of layers of neurons. A single neuron Neural network is known as Perceptron.

Perceptron

So when you provide multiple inputs to the neuron it performs some processing and gives you the output. And, what the inputs are depending on the task.

Let’s understand it better, Suppose you are thinking of going to watch a movie so what makes you decide whether you are going to watch it or not. So basically it depends on some criteria like your favorite actor, your favorite director, the genre you like and your mood, etc. So these will be the input features that will decide whether you are going to watch the movie or not.

And for sure some features are more important than the others which are decided by the input weights had by the neurons so it gives the output prediction accurately.

For complex problems, you can use multiple neurons connected to each other.

multiple connected neurons

A neuron consists of functions which are known as Activation Functions which help to get the
output in a certain range depending on the function you are using.

Activation functions are one of the many parameters you must choose to gain optimal
success and performance with your neural network.

To choose the right activation function you have to understand the problem first that the
problem is of classification problem or regression problem.

The commonly used activation functions are:

  • Logistic
  • tanh ( hyperbolic tangent)
  • ReLu (Rectified linear units)
  • Leaky ReLu

Create a Neural Network model using Keras

Let’s do this, now you are going to create a basic Neural Network model using Keras.

And don’t worry if you don’t understand it 100%, it is just to show you how easy is to create a NN model. So basic role of the Neural Network is to find a relationship between two numbers. And this is how it differs from rule-based programming here you don’t have to write rules, you just need to pass the numbers and your model will find the relationship between those numbers.

In NN you feed the data with a set of X’s and Y’s and this should be historical data it is required to train a model and to find a relationship between the inputs(X’s) and the outputs(Y’s) so that it will predict you for any unknow input values with the help of the relationship found between the numbers.

Import Libraries

Let’s start by importing the required libraries.

import tensorflow as tf
import numpy as np
from tensorflow import keras
Provide Data

Let’s suppose you have a data of t-shirts business, 1 t-shirt is of cost of 10$ and for every additional t-shirt it will cost extra 5$ so for 2 t-shirts it is 15$ and so on.

X_train = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0], dtype=float)
Y_train = np.array([10.0,15.0,20.0,25.0,30.0,35.0,40.0], dtype=float)
Model Creation Phase

We are using the simplest model from Keras which is from the Sequential class and create the simplest neural network which has 1 layer and 1 neuron, and the input shape is 1 here. We are using a single Dense layer to build this model.

model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
Compiling the Model

Now we are going to compile this model, here we have to pass two functions loss & optimizer. Now, what our model will do is first guess on value and with the help of the loss function, it calculates the difference between the guessed value to the known correct value and measures how well and how badly it did, and then with the help of optimizer, it will minimize the loss by guessing closer value to the correct known value. It will repeat the task multiple times to minimize the loss.

model.compile(optimizer='sgd', loss='mean_squared_error') 

Here we are passing sgd optimizer and mean_squared_error loss, you will learn about this later.

Model Training Phase

In this phase the model learns the relationship between X_train(input) and Y_train(output) by using model.fit() method.

model.fit(X_train, Y_train, epochs=500)

epochs are the number times the model guesses a closer new value and minimizes the loss.

Model Prediction Phase

Now you have the model that has been trained on X_train and Y_train and learned the relationship between them. Now you can give any unknown input it will predict the output.

print(model.predict([8.0]))

The model is predicting the value of 45.32 which is very close to the correct value of 45. It is not 100% correct because it works on probabilities and requires a lot of data to train on.

Congratulations you have created your first Neural Network model.

4

4 thoughts on “What is Deep Learning?

Leave a Reply

Your email address will not be published. Required fields are marked *