1. Home
  2. Explore
  3. Computer Science
  4. Artificial Neural Networks

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Artificial Neural Networks

Transcript

Hey guys, today we are going to see how artificial neural networks work in our deep learning in a very simple step by step way. And even if you don't know neural networks already, I believe that by the end of this video you will have a complete foundation about neural networks . And I have tried to explain it in a way that you don't get scared of mathematical calculations and formulas. I have also explained why you shouldn't get scared of it in the middle. Okay So this video is going to be very interesting. I think that by the end of this video your knowledge will be improved compared to the knowledge you had 30 minutes ago So let's get started Hello everyone welcome to Applied With AI..

We have already solved many problems using neural networks Today we use ChatGPT, Gemini, Tesla's self-driving cars, at the enterprise level, a bank's fraud detection system, Behind all this are neural networks. But before we learn about our neural networks, let's take a look at the nervous system in our body as a small overview. Because our neural networks are built on this basis. So now I will tell you just one scenario. Let's say a car is coming towards us very fast As soon as we see this car coming, we think that we should jump from there and escape. But how do we make this decision? Our eyes see a car coming towards us at a fast pace. Our ears hear the sound of that car. So all these input signals are received and sent to our neurons. Right, some processing takes place in the neurons in our nervous system. Some calculations take place. As a result of this processing, only a few neurons are activated,

which makes us take a decision to jump from there. Okay. So, now let's say you are sitting on the sofa, relaxing and listening to some melodious music. That input signal is received by your ears and goes to our neurons. At that time, some processing takes place again. Some neurons become activated and make us feel relaxed. Now, when we make ourselves jump, different neurons are activated, and when we make ourselves feel relaxed, different neurons are activated. So, depending on which neurons are activated, our decision-making changes. Okay, so now we will apply this same concept to our deep learning. So, as I said , how does our neural network calculate which neurons should be activated? How does that calculation happen? Today, we are going to look at all of this We are going to look at it step by step. And another important update is the presentation I'm going to give today , the documentation of

all the concepts I'm going to talk about today, the complete detailed documentation I'll share all of this exclusively with my members. So if you want access to that too, there's a join button below the video. If you click on that and become a member of the channel, you'll have access to all the exclusive content I'm giving. I've already shared the code and documentation about AI agents. So today I'll also share about neural networks. So now let's start looking at how the architecture of our neural network will look like. So now we're going to look at an architecture like how a high-level artificial neural network works As I said before, a car is coming towards us at high speed, so we receive some input signals. Using that, our neurons do some processing and make us make some decisions . Right, to pass those inputs, there is an input layer in artificial neural networks. In this input layer,

we will pass whatever data we are going to use to train this neural network . Okay, so what should we do to pass this data? If so, all this data will pass to the next layer. Let's call the next layer our hidden layer. All the processing will happen in this hidden layer. No processing or calculation will happen in the input layer. Its job is just to receive the input and send it to the hidden layer. All the calculations will happen in the hidden layer. We will see what those calculations are in a moment. So, now how the input comes to the hidden layer, from all the neurons in the input layer, the input will go to all the neurons in the hidden layer. Okay. And as for the hidden layer, we can put as many hidden layers as we want in a neural network. And we can put as many neurons as we want in a hidden layer . Right, so now for simplicity I have said that there is only one hidden layer and two neurons in it. So now

the next layer is our output layer. Whatever output comes in this output layer, this is the decision of this neural network. Okay, so this output layer also gets input from all the neurons in the previous layer . Based on this input, a processing takes place in the output layer. A calculation takes place. Whatever outcome comes as a result of that calculation, that outcome is the decision of this neural network. Right, so now let's say our forward propagation , which starts at the input layer and reaches the output layer . But how can we understand this concept? Let's understand it with an example. When we look at the example, we can understand very clearly what data we are actually going to pass and what calculations are happening when we pass that data. Because only then will we get a context for our mathematical formula. When we directly go and read a formula, we don't know why we are reading this formula and why we are using this formula

, and when we look at that formula, we don't have any connection. It will be very difficult to understand that concept. So first let's look at an example. Let's say that there is data of many people in this data set. I have displayed only the data of four people here. How many hours do they exercise per week? How many times do they eat junk food per week? How long do they sleep per day? How many liters of water do they drink? This is the data we have now. So let's call these four our features. So we have a label based on these four features of this data. This label is the information about whether this person is fit or not. So these four features are going to influence this label. So this is a binary classification problem. Because there are only two possible outcomes. One is fit or not fit . We are going to represent our one as fit. We are going to represent our zero as unfit. Okay, so let's

call this our labeled data. Right, so we are going to train our neural network using this labeled data . Okay, because we already know the outcome. Let's go ahead and train it. So after training, if we give just one person as input without our label, it should give a response if it doesn't fit that person or not . Right, that's what we are going to train for. So how are we going to do this training? We have four features. Right, we will give all these four features as input to the four neurons in our first input layer. Okay, so first time x1= 6, then it is nothing. 6hus of x per week is like that , we assign a value of 6 to our x1 input neuron . Okay, we have assigned all four values ​​in the same way. And this neural network, when we first pass a data, this neural network is like a baby, it doesn't know anything. It doesn't even know what data is coming in.

It just knows that there is a 6, there is an 8, there is a 2.5, that's all. It has to find out if this is a person's data fit or not, it doesn't know any of this. Okay, so let's see what happens first. For simplicity, I have removed these connections. That's when we have A little writing will make everything a little clearer. Okay, but that connection will definitely be there. So now this data needs to be passed to the neuron in our hit layer. Okay, before it passes, first what will this hit layer tell us about the data coming from this input layer? I will accept all the data coming from the input layer. But I will give higher importance to some data. I will give lower importance to some data, and that will be decided. How to decide that, I assigned a weight to each connection. Okay, so if I base this weight value on the weight value, I will give a lot of importance to that input. Otherwise, that input will influence my decision,

it will influence a lot. If there were random weights, this input or this feature would influence my decision. That's what it means. Okay. So if you ask how we assign these weights, first of all, when a piece of data comes in, all these weights are assigned randomly. Because as I said earlier, this neural network doesn't know anything. What data is coming in? How should it calculate it? It doesn't know anything about which feature to give importance to. So it randomly gives importance to some features. All those random weights are assigned here. Okay. So now we have the inputs. We have the weights required for it. Now let's see what calculation happens . What is the calculation of the hidden function? So two calculations happen. So the first step is to multiply our inputs and weights. So x1 x1 + x2* w2 So like this,

we multiply the inputs and weights from all the neurons in the input layer and add them all. Okay, that's the calculation that it's going to do and finally we're going to add a value called bias. I'll explain what this bias is in a little more time. It's going to be confusing if I tell you now . Okay, so now how can we define this calculation, this mathematical representation, in a simpler way? The equation is x* w+b, because we multiply all the x's and all the w's and add them. So if we want to make a simple representation, just sum x* w+b, this calculation is the first step, this neuron will process in this hidden layer. So now let's apply our numbers to this formula and see. If we apply it, we will get a result of 11.15. I have given a random value like 0.2 to BIOS. Let's see that later . Okay, so in the first step of calculation, the value of this neuron is 11.15. Now the next step is very important. A result has come, a number has come, but

now we make a decision whether this neuron should be activated or not. Activation means that if a neuron is activated, it is going towards a positive result. So now in this hidden layer, if this neuron is activated, it is going towards a response based on this input . Okay, that means if it is not activated, then it is going towards a response that is not fit . Okay, but how can we decide whether a neuron is activated or not? Just this 11.15, we have our activation function. It is a mathematical formula. So when we pass this number into that function, we get a result. Let's make our decision after that. Okay, so what is that function? There are some different types of activation functions. But for this problem, we are going to use a simple activation function like this. Okay, so let's not go too far after this. In our next video, when we solve a lot of use cases, you will start to understand clearly

what activation function to use for which use case . So now this relu activation function is nothing like that. Just the maximum is the value we found 11.15. Okay, so the maximum is 11.15, so 11.15. Okay, so now this 11.15 is happening, the result of this activation function is always positive, but if you ask me, there is no chance that in many scenarios, the weights will be negative . Then there is a chance that this pair of values ​​will also be negative . So the work of this activation function is that if a negative result is received, then this neuron will not be activated. If a positive result is received, then that positive result will remain. This neuron will be activated. Okay, so now the value of this neuron is 11.15, which means that this neuron is activated . The fit is going towards such a response. Okay, so we can assume that our second neuron will also have some weights.

Let's say the value is 7.95. Because we have applied different weights to it. We applied this calculation to that weight and got a value of 7.95 . So now the processing of the hidden layer is finished. Now we need to use these numbers and make a decision in the output layer. Say if this person is fit or not. So now we will assign the same weights to the output layer. And first of all, again these weights are all random. What the output layer is saying is that I will give this neuron a little less importance. But I will give this neuron a little higher importance. Right, so no matter how you look at it, both neurons are activated. So when they apply two positive weights to it, this one will also be activated. But let's see how it will come. So now I have assigned these two weights and I am assigning the bias to 0.3. Don't worry about that now. So now if we apply our same formula here again,

I will write the value of this z again and write everything. This value of z comes and we get 14.146. Okay, so now we have the value of z. We have to apply the activation function and decide whether this neuron will be activated or not. Because this is the output neuron. Okay, if this is activated, this person is fit. If this is not activated, this person is unfit. That is, that is the result of this neural network. Okay, so this is a binary classification in the output layer. For binary classification, it would be better to use the Sigmoid Activation Function rather than using the Reluta Activation Function in the output . Because what the Sigmoid Activation Function does is it fits this value within a range of 0 to 1. Okay, if you look at the formula for the Sigmoid Activation Function, 1/1+ e^-z z is the value we already found. Okay,

don't worry too much about this formula. What this is going to do is it will plot your z value from 0 to 1, and wherever you plot it, it will find whatever number you want. So when we apply this formula, we get a value like 0.99. Which means now the value of our output neuron is 0.99 and its possible values ​​can be anything from 0 to 1. Because we have applied this sigmoid activation function. So if the result of this activation function is 99, then we will say that our neuron is activated. That is, according to the sigmoid activation function, the result of this neuron was between 0 and 0.5, so the first half of the first hop, this neuron is not activated. But if this result is between 0.5 and 1, then we will say that this neuron is activated. Okay, what does it mean if it is activated, our results come in and this user bit has a response like this to this data. Okay, and how confident is this fit? The more closeness there is to one, the more

confident it is. So now it is 0.99 99, so what is this output neuron saying? I am very confident that this user fit is saying that. But we know that according to this user's data, this user bit is correct, so now we are going to start seeing real interesting things . Because this neural network is starting to learn. It's going. Now the forward propagation is complete. That is, our data has reached from the input layer to the output layer . We have a result in the output layer. So the forward propagation is complete. Now how are we going to tell this neural network ? You have predicted the value wrong. So adjust all your weights and before we see how we are going to tell you, I think I want to show you one important thing . Because we have seen a lot of mathematical calculations so far . So that it doesn't become overwhelming for you, all the mathematical calculations we have done so far can be written in just a two-line program when we write our program. We will mostly develop

this program using Tensor, Tensor Flow and Keras libraries . Or you can use any of your choice, such as By Torch. But if you see these two lines to build our neural network, we have said that we should use the Relu activation function in the first layer. We have said that we should use the Sigma activation function in the second layer . Okay, this is the hidden layer and this is the output layer. So, just write these two lines. This program will automatically do all the mathematical calculations that I have been doing for so long . So don't get overwhelmed by the math . The reason I'm talking about formulas and calculations is because when you write a program, you need to know what is happening in the neural network behind it , because only when you know that can you train the neural network effectively. Okay, so what are we going to do in the next section? We're going to do back propagation. That is, we're going to compare

the predicted output and the actual output that we've already found and create a loss function. What is that loss function going to say? So how far is this predicted output from the actual output? How far is the loss ? Okay, so for that loss function, we are going to use our binary cross entropy, a loss function. There are many types of loss functions. Since this is a binary classification, we can use binary cross entropy . And after finding our loss, this neural network backpropagation goes back one layer at a time and finds out how much each weight contributes to that loss, and does a mathematical calculation to find out and adjust that weight . Okay, so for that, we are going to use a function called our gradient descent . Right, before looking at both of these, because there are a lot of mathematical calculations involved in this. If I write a program and find the loss, backpropagate it and update the weights,

what program will I need and how many lines of code will I write? Because the next Maxlam will be a little advanced. I will show you that code right now so that you don't get overwhelmed by it . That is also a two-line code. We will mention in the program what loss function to use, such as binary cross entropy. And we have mentioned what optimizer to use to update all the weights, such as gradient descent . So, it is enough to mention this code. This program will do all the calculations behind the neural network automatically. Okay, so all we need to know is what activation functions are there, what optimizations are there, what loss functions are there, what loss function is correct for which scenario, which activation function is correct, which optimizer is correct, and so on. We will know that and pass it to the correct program , and the program will do all the other values ​​and finish. And of course, when

we clean and prepare the data properly, and pass it to this neural network, this neural network will automatically Learn. Okay. So, now we see this line, we know that these are two lines. Everything is coming from now. So, now how is the backward propagation going to happen? Let's see how this neural network is going to learn . So, now we were saying that we are going to find our loss value in backward propagation. Correct, we were saying that we are going to use binary cross entropy for that. I have displayed the formula for binary cross entropy here. In this formula, y is our actual value 0 or y is our predicted output 0.99 99 Okay, so when we apply these two values ​​to this formula, we get a loss value of 4.6. So how do we understand this 4.6 ? If the loss value is close to zero , it means that our predicted output is either the correct output or very close to the correct output. If our loss value is very far from zero, then our predicted

output is a very incorrect output. It means that it is very far from the correct output . But 4.6 6 is a very high loss. I will explain why that is. For example, if our predicted output was 0.99 and not 0.5, if we had applied this y cap value to our loss function, our loss value would have been 0.69. Okay, so now we have 4.6, that is a very high loss. Right, so if this output had been 0.1, 1, which means this neuron would not have been activated, right? Because sigmoid activation, what I was saying, does not activate from 0 to 0.5. It only activates from 0.5 to 1. So, if it had been 0.1, it would not have been activated. Which means we have given the result that is not correct. We have given it correctly. If we had applied that value to our loss function, we would have got a loss of 0.1. Which means the loss would have been close to zero. That is, a very small loss. So that means we are going towards the correct result

. Right, what binary cross entropy does is that if our neural network makes a mistake, it will give a heavy loss for it. So when we give a heavy loss, if we do our back propagation and go back, all the weights will be adjusted properly. Okay, so how are we going to adjust all these weights. That is why we are going to use our gradient descent. Right, I'll display the formula for gradient descent like this. Don't be afraid of it. So what we're going to do is calculate new weights. So, as I said in back propagation, we take this loss value and this predicted output and go back one layer and calculate how much each weight contributes to this loss . This weight is adjusted accordingly. Let's take our junk food example. x2=6, so this person eats junk food six times a week, that's information. So, we assigned a positive weight of 0.5 5 to this . Now what are we going to do using this formula? So how much does this particular weight contribute to my loss

? And how much do I adjust this weight ? Okay, so this is what the new weight is, we're going to find the new weight and w is what the old weight is, we're going to find the weight we already gave, 0.5 5 right minus n here is a symbol like learning rate. Learning rate So what are we doing in back propagation? We're using gradient descent to update the weights . Why are we updating the weights? We're using gradient descent to update the weights to get our loss as close to zero as possible . Right, when this goes close to zero, it won't go to just one data. We'll keep using a lot of our data and training it over and over again. So little by little, little by little We will gradually reduce this loss value. That is the learning rate we are going to give here. So , no matter how many steps our neural network learns each time and each step, this learning rate is how many steps it takes to get to zero.

Our learning rate is good for us. I will tell you why . Let's say this is the gradient descent curve. Now, if the learning rate is reduced, then when we pass each step and each user data, our loss will come and be somewhere in this place. The loss will come and come a little bit closer to zero. In the next step, it will decrease a little bit more. So step by step, it will start decreasing. Let's say our learning rate is too high . Let's say our loss is here now, so the first time it will come this far from here. The second time it will go this far from here, thinking that I will not get close to zero. Then instead of going close to that zero again, the loss will be right again. Again it will start coming from here till this far. So it will come and start going in an oscillation mode. So the learning rate will decrease step by step, as we put more and more data, the value of the loss will keep decreasing. The weights of our neural network will be updated properly. Right,

that's why we have to put a learning rate limit. And this derivative function, let's call it our derivative. This is differential calculus. Okay, this is not division. This is differential calculus derivative. Right , and we don't need to be afraid of this. This derivative is like this. My weight, now the weight that I have given to the current, how much does it contribute to my loss? Such a calculation. This calculation, that is, when we apply our weight and our loss function to this differential calculus, we get a value of 5.94. That's all we need to know for now. So if you want to know the mathematical background of how this derivative works, you can go and study differential calculus and understand it. Okay, so now the result of this formula is -0 094. Which means that I have already given a weight of 0.5 and now it is updated to -0.094. Okay, what happens then is that we should give priority to junk food, but it

should not have a positive influence on the fit. We have found out in our first step what negative influence it will have. Right, now if we do many similar steps, this negative value may also increase. Which means a user eats a lot of junk food, then it will have a lot of influence. But it will have an influence in the negative direction. Which means I want to go towards my beloved. This neural network will start learning little by little. One data pass . Right, this is the procedure that comes and uses gradient descent to update the weights. And as we have already seen, this is just two lines, but now we have understood the process behind it. Okay, this is the procedure for training a complete neural network. First forward propagation, we get an output from it . We will base it on that and find our loss. We will base that loss value on backward propagation and adjust all the weights. This is the first pass. Again, the second data pass. This process continues.

In this way, when you pass a 100s of data, thousands of data, millions of data, etc., this neural network will learn little by little and all these weights will be updated and finally this generalized model will be ready for you. That is, you give a new data without a label, then this neural network can take such a decision whether that person likes it or not. With good accuracy, it cannot be said that it is 100% accurate. But with very good accuracy, this Neural networks can make decisions. So this is how our neural networks are automated. Okay, so in this video we saw how this neural network is trained with our numerical data . In the next video we will see how we can do image classification. Why do I say image classification specifically? As we know, neural networks can only take numbers as input. No matter what neural network is there, whether it is machine learning, it only understands numbers. Right, if there is an image, how can we do image

classification? In my AI Learning Roadmap video, I had already mentioned a project called Handwritten Digit Recognizer . And this is a binary classification, but in the next video, what we are going to see is a multi-class classification. Because the digits are going to be from 0 to 9. The neural network is going to find out which digit we have in our image now. Okay, that's a multi-class classification. So if you think this video was useful for you, then share it with all your friends . Share it with everyone who wants to learn. Let it be useful for everyone. And as I already said, today I am going to share the complete documentation with all the concepts we saw exclusively with my members. So if you also want access to that, there is a join button below the video. If you click on it and become a member of the channel, you will get access to all the exclusive content I have posted . And as I said at the start of the video , I believe that your knowledge will have improved a little bit compared to what you had half an hour ago . If there are some things that you do not understand correctly, then tell me in the comments. If you understand everything well, then tell me in the comments. So, let's meet in our next video. Thank you, bye.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent