• Home
  • Contact
  • Blogs
Gmail LinkedIn

Parthik Talks


If you really want Neural Network (NN) in a Nutshell, Neural Network is like a baby. Ya, there we go, in a nutshell, you can leave now!

Oh, you’re still here? Wanna know more? Ok then, hop in.




Just like a baby tries to stand or walk or use hands effectively or laugh or anything, it does not do it perfectly in the first attempt. It does something, it fails, it learns from its mistakes, takes our feedback and then does it again. And on the millionth try (damn that kid!), it succeeds!
Neural Network is just the same. It’s a model that tries to do something (mainly, predictions), fails at first, considers its errors and sometimes our feedback too (tuning the learning rate, we’ll come back to it later) and then tries again. And not in a millionth try (hopefully!), but after some tries, or let’s be a little technical over here, after some iterations, it finally gets better at its job.

I’m assuming you’re a layman so I’ll be explaining from basics in simple terms. What? You already know that? Well, you can totally skip ahead for the main treat.

The term “Neural Network” did not come from anything outside in the world, but from within us only. Our brain, the complexity king, contains billions of ‘Neurons’ which are nothing but basically nerve cells that are the basic building block of our Nervous system. But unlike other cells, Neurons are specialized to transmit information throughout our body. Well, let’s not go deep into the bio, it’s not a bio class after all (I’ve always hated bio!). So, Neural Nets are just an attempt to replicate the Neurons in our body. The stripped-down process of a Neural Network is:

Workflow (Neural Network Algorithm):
Take Info → Do some magic → Give output → Calculate the mistakes (errors) → Optimize the magic → Repeat
Now that you know the basic structure, let’s dive a little deeper!

Basic Building Block: Neuron

A Neuron (sometimes also referred to as a Node) is the smallest element of a Neural Network. Its basic functioning is to take some input, do some math-a-magic and then spit out some output. There we go, that’s it!

As you can observe, there are a few things that are happening here:

1. Each input is being multiplied by a Weight


2. The weighted inputs are being added together with an extra term, bias.


3. Finally, the sum is passed through an Activation Function.


Activation Functions:

An activation function is nothing but just a way to convert the inputs into a nice and scaled output which works better while predicting in a Neural Network training.
The most commonly used Activation Functions are ReLU and Sigmoid:
*not to scale




Simple Neural Network example:

Building a Neuron from Scratch in Python :

Github Gist
Great! We’ve implemented our first Neuron! Welcome to Machine Learning! And now that you had a little taste of it, let’s move forward to what exactly Neural Networks are.




Neural Network Definition

A Neural Network is nothing but just a bunch of Neurons packed together in some structure. Seriously!






As we can see, a NN is mainly divided into 3 parts:
  • Input Layer
  • Hidden Layer
  • Output Layer
Input Layer is the Input data we feed to a network that we want to do our predictions on.
Hidden Layer takes input from the Input Layer and then performs the math-a-magic and then spits out some numbers.
Output Layer takes the output of the Hidden Layer as input, does the math-a-magic again and then spits out the result. Cool..! Right?
And this my friend is nothing else but the complete Feed-forward Algorithm !!!

Note: The most basic NN is a 2-Layer NN with only 1 Hidden Layer. Though there can be multiple hidden layers, but only 1 Input and 1 Output Layer.
Therefore, the total number of layers, L = n Hidden Layers + 1 Output Layer
Though, the basic idea remains the same. Feeding the input(s), feed-forwarding through the neurons in each layer towards the output and getting out the predictions.

Representing the Dataset

We, for the sake of simplicity, will use a very basic Dataset.


Here, there are two Features and one Label. Can you observe how the labels have been marked?
Now, we have our Dataset and we have our NN structure too, what’s left? Yup….TRAININGGGG!!!!!

Feed-forwarding in Python

Github Gist



Awesome! Now that we’ve got our first predictions, let’s check our performance and move closer to optimizations (getting more accurate).

Cost Function:

Ok then. Things are gonna be a little trickier from here on. So, tighten your seatbelt. Vroom..!



Now that we’ve reached our first solution (hey man, the first solution? What do you mean by that? Don’t worry. I’ll explain everything). So where were we, yes, once we reach our first solution (hey man, the first solution? What do you mean by that? I said don’t worry. I’ll explain everything. Ok?). Ya, so, first solution…(umm…dude..? Arrgh! Shut the…).

We need to compute Loss! We need to come up with some way, some formula, some function to check how well we did. No, we can’t do that just by looking manually and comparing. Yes, we can do it in very small datasets with up to 5–10 examples (like our dataset), maybe even up to 15. But what will you do when the number of examples crosses 100? What about 1000? Tens of 1000s? A million?



Yes, the dataset CAN BE that big! Did you forget already? The more the Data the better the Machine Learning Model!



Enters Mr. Cost Function.



If you haven’t guessed it by now, Cost Function is a function that helps to compute the error in the predicted values. It is also represented by ‘J’ in mathematical representations.




Well, this is it. Simple isn’t it? Let’s just break it down to understand,

  • m: Number of examples our dataset has.
  • y_pred: The predicted labels (yhat, according to our code.).
  • y_orig : The original labels, y.
  • Σ: It’s a mathematical character that means ‘to take sum of’. (You’ll get it later. Chill.)

(y_orig - y_pred)^2 : It is known as the Squared Error.



C’mon, c’mon. Use your brains now. If that term is called Squared Error, what happens if we divide it with the number of examples? Huh? C’mon c’mon. Try.

Well, there’s no way for me to know what you answered, but if you said it’ll make the values smaller to work on, haha…



NOT AT ALL!



It converts the Squared Error into Mean Squared Error. Ok ok, I’ll explain. See, our loss function J here is simply taking the average over all the squared errors. Thus, ‘Mean’ Squared Error.

The better our predictions are, the less our loss will be. Or we can also say it like this,

The less the loss, the better the predictions.
Therefore, we only focus on one and only one thing while training a Neural Network. We try to minimize loss, cause that automatically gives us better predictions with higher accuracy.

IMPORTANT NOTE:
Although I’ve explained to you Mean Squared Error here, we might not be using it. Why? Because Mean Squared Error is used to calculate the loss when we’re dealing with a “Regression Problem”. But here, we’re dealing with a “Classification Problem”. So, we’ll be using this Cost Function,
I know I know this might be looking a little overwhelming. But bear with me, please. As much as I want to explain it here, I can’t. It’s already been a long article till now and there are more things that I need to explain. We’ll just be implementing this Loss function for now, and I’ll be explaining all of this and much more about Cost Function in another article. What kind of a Nutshell is this if I’ll start explaining everything in detail huh? Haha.

Cost Function from Scratch:
Github Gist

Now that we’ve got a way to calculate the error, the only steps left now are to work out some way to minimize the error.

Neural Network Backpropagation:

Now, we’ve got a clear goal, don’t we? Minimize the Cost Function. But how do we do that?

To answer that, let’s take backward steps and see how we reached that stupid Cost Function in the first place anyways:

  1. We took the inputs.
  2. We generated some Weights and biases.
  3. We multiplied the Weights and inputs and then added the bias, followed by feeding the output to some activation function. Basically, Feed-forwarding.
  4. We calculated the output of the final layer (output layer).
  5. We then computed the Cost.

So this was the progress we made so far right? Cool then. What next? And why did we went through the steps?



The answer is simple. What I want you to recognize in the above step the things/process which were in our hands. The things we could’ve have altered with.

We cannot change the input, obviously! You can’t change the question if you’re not getting the answer right. As simple as that! (Or can you?)



Secondly, we cannot tinker with the activation function. C’mon, it predefined.



So what can we do..? Tell me, what we want to do in the first place? Ya, minimize the Cost Function. Now tell me, what is influencing the Cost Function? There we go, the predicted output (’cause the other thing is the original label and that is fixed.) One last thing, how did we reach that particular predicted output? Yes? Yes? Yes, through Feed forwarding. And now the ultimate last question, what all things did we use in our Feedforward algorithm..?

Yup, you got it right! We can very well play with the Weights and biases that we generated ourselves. That means, they can be customized as per our convenience, so…let’s!


NOTE: This is the part where we need to do some advanced mathematics which I’m skipping for now as it is beyond the scope of this article. But if you really want to understand that, I’ll suggest you go through Backpropagation.


So, after having a dinner date with calculus, she gave us a present before leaving. She gave us a couple of parameters;

dW and db (for each respective layer)


NOTE: Just for the sake of quick understanding, dx indicates the small change in x.


So now, we’ve with us :



NOTE: The superscript [l] points to the lth layer of Neural Network with L layers. For example, W[1] are the weights of the 1st Layer, b[2] are the biases of the 2nd Layer.


Now that we’ve got the required changes we need to make to the Weights and biases, let’s change ‘em.

Ho Ho Ho, not so soon my friend, there is one last tini-tiny step remaining.

Gradient Descent:

If you’ve never heard of this term, I bet this must be scaring you. Have no fear thy friend, this might be the easiest thing to implement so far. Betcha!

I’ve already explained Gradient Descent in details, but to give you just a quick overview,

It is a process of finding the minimum value location of the Cost Function when plotted against Weights. And, how big steps we’re taking towards the minimum is determined by the parameter ‘Learning Rate’.



Gradient Descent
Gradient Descent from Scratch:

Github Gist


So if we iterate this over every Weight and bias correctly, we’ll see the Cost Function Graph decreasing over every iteration (hopefully!).

Baking the Pie:

Now let’s recall what was the Workflow of the Neural Network:

Take Info → Do some magic → Give output → Calculate the mistakes (errors) → Optimize the magic → Repeat

But now we’re not dumb as before, now we can use the correct technical jargon. So, defining the workflow again:

Taking Input → Generating random Weights and biases → Predicting the labels using Feed Forward → Compute the Cost Function to keep track of Prediction Error → Calculate the small changes to be made using Back Propagation → Updating the Weights and biases using Gradient Descent → Iterating over the process to reach the desired accuracy
Original Labels v/s Predicted Labels



This kind of Cost Function slope represents that everthing went well!
Congratulations, you smartass! If you can relate to every step mentioned in the above Workflow, I’m proud of ya.



Now, why don’t you visit my playground and give this a go yourself? Try to come up with better accuracy by tinkering with the parameters, and tell me in the comments if you get some good results!

And if you want the complete code, head over to my GitHub Repo (it's slightly changed though, but'll it won't be a problem 'cause you're a pro) and have fun!


Peace out.

I want to thank my good friend, Naveen Goswami, for helping me out with the diagrams with his amazing drawing skills. Thanks man, for staying up late with me to complete the job (without even any pay! haha). Thanks again, and I might need your help again so, buckle up! 


More Machine Learning Deep Learning Resources to refer:

  • Machine Learning Deep Learning Best Courses
  • Machine Learning Deep Learning - Siraj Rawal

More Machine Learning Deep Learning Books (Very Popular):

Share
Tweet
Pin
Share
No comments

When I was just starting myself, I was super confused between these terms. I used to hear them everywhere. “Another Deep Learning breakthrough”, “Machine Learning engineers created bla bla”, “Deep Learning is the new AI!” And I asked myself, what exactly is Deep Learning? And what exactly is Deep Learning vs Machine Learning? And just like you, I ended up swooshing through various blogs and YouTube Videos only ‘related’ to this topic but not exactly put up as I needed. So guys like me who’re having a hard time, you don’t need to go anywhere else!

First of all, to understand the basic difference “Deep Learning vs Machine Learning”,  you should have a basic and clear idea of what exactly they both mean individually.

Well if we go by Ms.Wikipedia’s definition,

Machine learning (ML) is the scientific study of algorithms and statistical models that computer systems use to perform a specific task without using explicit instructions, relying on patterns and inference instead.





Puzzled? Let’s just simply our definition…


Machine Learning is just another set of algorithms to write a program that opens a completely new world of opportunities for humans. It learns from past data and is able to predict the future! Isn’t that just amazing? And the best part is, without even having to program it explicitly, it can predict pretty accurate results.

And trust me when I say, It’s not like some evil AI robot that’s gonna destroy us. In fact, we are surrounded by AI robots already! Are we dead? I guess not! Personal Assistants like Siri, Alexa, Google Home, fitness trackers like FitBit and many more, what are those? You guessed it right! They’re nothing but ML Programs fed into a device/machine. Let me ask you this now, how else do you define a robot?

Let’s not go off track and into robots and machines and end of the world which is due until March 29th, 2063 (shh..).

But here’s a question, Machine Learning is a field in Computer Science, so how does it differ from traditional computational approaches? Well, the simplest answer would be that the traditional approach uses algorithms that are explicitly programmed and are used by computers to solve problems. Where on the other hand, Machine Learning algorithms allow for computers to train on data inputs and then use statistical analysis to return some predicted values within some range and accuracy.


So now that you have a general idea of what ML is, let’s just dive straight into the topic of this blog.


Deep Learning vs Machine Learning?

This is like asking how is Potato is different from vegetables? Or …or how is a Burger different from Fast-foods? Are you getting my point? No..? Ok, let me elaborate.

See, all Potatoes are a vegetable but all vegetables are not Potato. All Burgers are fast foods but all fast foods are not burgers. All Deep Learning algorithms are a Machine Learning algorithm but all Machine Learning algorithms are not a Deep Learning Algorithm!

That means Deep Learning is a subset of Machine Learning! Therefore, all the properties of a Machine Learning algorithm are carried out by Deep Learning algorithms but not the other way around.

Venn Diagram (kinda)

So coming back to our question again, what is Deep Learning anyway?

You probably must’ve heard this term a lot in the past couple of years. “Deep Learning is the new age of AI”, “DeepMind’s AlphaGo beats a human using Deep Learning”, “Deep Fakes are becoming a threat.”

Let me introduce you to the power of Deep Learning first (deep learning applications), and once you start to finally respect this thing, we’ll move forward.

‘Go’ is a 2,500 years old Chinese board game that still is very popular and played all around the world as “the most complex/hard Board Game.” Just to give you a reference, the lower bound on the number of legal board positions in Go has been estimated to be 2 × 10^170, whereas the total number of atoms in the universe are approximately 10^80. Now can you relate how complex Go is?

In 2015, Google DeepMind’s bot ‘AlphaGo’ beats the world Go champion Lee Sedol with the end score of 4–1. And in 2017, the newer version of AlphaGo called ‘AlphaZero’ beats AlphaGo with the end score of 100–0. Can you believe it? 100–0!! I was super surprised when I heard it for the first time. And this was all the magic of Deep Learning.

And they not only stopped there, recently enough they build ‘AlphaStar’ which has beaten the world’s top players of “StarCraft II” which is considered to be more complex than Go.


Cool? Isn’t it? And this was just a single example of the many Deep Learning Example s!


Deep Learning is nothing but the evolution of Machine Learning.

Yes, I agree that a Machine learning model does get progressively better over time in whatever they are being trained on, but they still need some guidance. When the ML model starts giving wrong predictions (high error), an engineer has to step in to tinker with some parameters to optimize the algorithm further, manually.


How does Deep Learning work? Patience my friend..

Whereas, a Deep Learning algorithm is intelligent in its purest form. It fixes its error itself, i.e, it optimizes itself when it starts getting wrong predictions with no human intervention through its own Neural Network.


A Deep Learning model is designed in parallel with a Human Brain, i.e a DL model can analyze data with logic just like a human would draw conclusions. For example, how would you recognize a square? You’ll check for its basic properties. You’ll check it the figure contains exactly 4 lines or not, if the lines are connected or not, if the lines are equal or not, if the lines are perpendicular to each other or not…and a few more things. And then you’ll be able to predict if it's a square or not. And that my friend is the same approach a DL model takes. Surprised?


Deep Learning achieves this using a layered structure of algorithms called Artificial Neural Networks whose design is inspired by the Human Brain (this is how the DL model is designed in parallel with a human brain, and is one of the many types of Deep Learning techniques) which gives it an edge over classic Machine Learning Algorithms. An ML model will not be able to create marvels like AlphaGo or AlphaZero.


Though, a DL model as to outperform an ML model requires a lot more training and a lot more Data. But if given the right ingredients, it can outperform ML models like crazyy!


Who wins in the fight of Deep Learning vs Machine Learning?

Now wondering when to use deep learning vs machine learning?


The primary difference between Machine Learning Deep Learning systems is the way the data is fed to them. ML systems require a structured form of data (mostly) to work on, whereas DL systems just rely on the layers of their network structure (ANNs, DNNs, CNNs, RNNs etc).


Again, ML systems learn on the data fed to them to work out some prediction, but, they need human intervention when the error margin starts to increase i.e the predictions start to move away from the actual results.

This, however, is not a problem faced in a DL system. A DL system is capable enough to work out something from the data thrown at it and even optimize itself without any human intervention when the predictions start to deviate.



Now comes the amount of data. If we don’t have large amounts of data, DL might not outperform ML systems!

But let’s assume the scenario is now reversed. Now we’ve got a huge database, just as seen previously, it’ll be a wiser option to go with DL systems rather than solving it again with ML systems. The real applications of Deep Learning are on a very big scale. They are more suitable to perform heavy and complex calculations.


Problems too complex for Machine Learning can be solved by Deep Learning easily. Though a Deep Learning system to work smoothly requires high computational power for training Deep Neural Networks.


Ok, I got it. What's next?

A very simple answer which you might have figured out by now yourself, Deep Learning is the future!


But again, the most important aspect to keep in mind is that Data drives everything. The quality of data determines how well we can do magic with it. Andrew NG, one of the rockstars in the world of AI said that,

If the AI model is a Rocket Ship’s engine, then the Data is rocket fuel. Without a good amount and quality of rocket fuel (data), we won’t even reach the orbit and without a good engine (AI model), we won’t even take off!



I want to thank Mr. Tapas Mishra, my mentor, my guide and the best big brother! He's the one person without whom I wouldn't even know what I be doing right now. He gave me more than just direction. Thank you bhaiya, for believing in me when I couldn't even do that for myself, for seeing things in me which I could never have figured out on my own. There's nothing I can repay you with for what you've done for me. You're the best.



Next Read: Neural Network in a Nutshell (from Scratch)




More Deep Learning vs Machine Learning Resources to refer:

  • Deep Learning vs Machine Learning vs AI - Krish Naik

  • Deep Learning vs Machine Learning quora


More Deep Learning Machine Learning Books (Very Popular):

Share
Tweet
Pin
Share
4 comments
Newer Posts

About me

A minute please

Heyaa! Enjoying the blog? I hope so. My name is Parthik Bhandari and I'm a Machine Learning Enthusiast, currently enrolled in Btech (Cliche, right..?) Haha.

Anyways, I would love to hear your feedback, so don't forget to leave one, ok?



recent posts

Follow Me

  • LinkedIn

Created with by ThemeXpose | Distributed by Blogger Templates