# Advance Machine Learning

- **Course:** 6103 - Advanced ML
- **Recorded:** 2026-10-27 18:31
- **Transcript:** 5671 segments, 10815 words
- **Made by:** colab import

---
Thank you. Okay, so we are starting. Thank you. In the last class, we have completed and I hope you have enjoyed that session about the CNN. Okay, so thank you and topic for today, I have planned for covering another very fundamental and advanced deep learning topic, RNN and LSTM. So, I have planned to cover both the models or the architecture, let's see what happens. So, starting with the CNN and you may be thinking, okay, so we have a CNN so powerful deep learning architecture. So, why we need another kind of deep learning network like RNN and LSTM, okay. So, very briefly, I will talk about the CNN is particularly very useful for vision applications or vision applications. When I call is vision application means it can handle the images and videos, images and videos very well, okay. Okay, or it's useful for non-sequential data. So, everybody is clear about two kind of data. We have a sequential data and non-sequential data, okay.

Where RNN and LSTM are very much powerful for a sequential data. Where if you try to apply CNN in the sequential data, it will not perform at all. So, since in real life, we have two kind of data, non-sequential data means data set having the records or items, okay. And every item, every entry is independent to each other, it is independent, independent to each other. We call it non-sequential data, non-sequential data. For example, images. So, suppose you have a CNN model and you have a data set having a lot of images, lot of images. Agree? Cat and dog and horse. You can, during the training, you can feed any of the image in any order. Any order. Order is not fixed. From the data set, randomly you choose the image and feed to the CNN for the training purpose. There is no dependency between the two images. So, suppose this is image 1, this is image 2. There is no dependency. No dependency. This is called non-sequential data.

But in the sequential data, like a stock market data, okay. The stock market data. Like IOT data. IOT data. Like a COVID data. Okay. Like a text. Like an NLP. Where every observation is associated and strong relationship with the previous observed data. This category we call a sequential data. So, that's why we have a sequential kind of data set. We require a different kind of model. So, that created a need of developing model that is different from the CNN. So, the RNN, LSTM and their family. The family also have a transformer. The same family. Transformer. Encoder, decoder. Encoder, decoder. All are the same family work with the sequential data. That is a background. So, moving to the next. Let me open a file. Yeah. So, I will explain the working of CNN with respect to the NLP. So, yeah. So, the things already covered in the NLP. Suppose this is the data set is given to you. Having a three sentence movie was enjoyable.

And second observation and third observations. This is the class sentiment is like a positive negative one or zero. So, we don't need to hear. How to give this text data to the RNN? I will explain the working of RNN with this working example. Okay. So, how to first we have to convert this text data into the vector. Suppose one hot encoding I am employing. So, how to do it? First, we have to find out the vocabulary. Vocabulary means unique words from the whole corpus. So, in this whole corpus, unique words are like that movie was enjoyable, disappointing and not. So, column is a feature. And also, we arrange the vocabulary as a row wise so that we can encode an individual word at a time, not a sentence at a time. Okay. So, movie is a word. Its equivalent vector is 1, 0, 0, 0. Was is another term equivalent vector is this one. So, this is the process by which we are converting your text data into the vectorized version.

Already, it was covered. So, it is the way you can mention the complete sentence like movie was enjoyable. So, movie one hot encoding vector is this, then for was for enjoyable. So, this is the equivalent sentence representation in the term of numeric number. Okay. Important part is whenever you feed data to the RNN, we have to pass additional variable here. It is a timestamp. It is not typical timestamp. Just understand, in the RNN, suppose I am passing data for a training. So, that data having a two-part, first is something, second is real data, whatever you are passing. Sometimes, we call it timestamp, but it is not timestamp actually. Okay. What is this? Let me explain with this example. So, another big problem, if you remember, the text data, the input size is not fixed. Everybody agree or not? Input size is not fixed. So, CNN, again, the second big difference I just recall, CNN work with the fixed size input.

Fixed size input. Fixed size input. You remember, if image size is 5 x 5, so all the images from that data set should be the same size. Okay. But, in the text, it is not fixed size. Everybody agree? Because input sentence may be, I am, I am Vivek, I, every time. The size of input is 2 tokens, size of input is 3, size of input is 1. Okay. So, how do you confirm and make it aware about the RNN to handle the variable size input? So, this problem we call it, to variable size input. So, that's why, what we want, I want, we feed the data to the model, data plus size. So, this first variable is the size. Okay. What happened and what is the benefit of this? Please be with me next 30 minutes, very crucial. So, look here, we have an input x1, x2, and x3. Under the x1, we have three tokens. Similarly, for other inputs, equivalent vector. And you see here, how to pass the input to the RNN. First, index talk about number of tokens.

Number of tokens. So, in this sentence, three number of tokens are there. Next sentence, three. Next sentence, four. Size of his token. It is fixed because it is a vocabulary. Size of his token is 5. So, what is the meaning of that? The moment I will say, like, the input is 3, 5. So, this is the size of input. So, it will define what number of neurons in input layer. Agree? Because, what is the biggest problem or the first problem in any network? First, you have to think about input layer. Agree? So, this is talk about, it's a vocabulary size of input layer. So, what do you mean by these three? So, you know, the concept of looping. Concept of looping. Suppose this is a hidden layer. For example, if you can recall the discussion at the beginning of the neural network, I talk about two kind of network. Feed forward network. Feed forward network. If you remember, feed forward network, then feed back here, recurrent network.

So, this is RNN is here. RNN is a feedback or recurrent network. Feed forward network is a CNN. So, recurrent network means, again recall the concept, we required a cycle, we required the loop, we required the feedback. Are you able to recall that discussion? So, this is the input layer is connected with the hidden layer, hidden layer will have a loop. Okay, understand that part, that is a crux of RNN, that is a crux of RNN. So, question is how many times this loop execute, you tell me, question is how many times loop will execute, will execute. That is a big problem or not, otherwise it got infinite. Like in C++, how do you, for i is equal to 0, i less than n, n number of times execute. So, here loop execute will be defined by first index, here 3 and 5, agree? So, whenever you feed input to the RNN, first index is talk about number of time loop execute, agree? So, suppose the sentence is written, I am Vivek and this is 3, 5, 5 is vector size, 3 means, 3 means, number of token, number of token in that sentence,

it is correct, it is correct, it is correct, size of sentence, that is also correct, same thing, okay? Or, number of, number of time loop execution, all are same thing, agree? In the detail, I have a discussion. So, yeah, so, now, it is architecture, where we don't have any loop, okay? We don't have any loop. So, how to do these things? So, movie is the first, first, during the training, X1 is the input. In the X1, the first token, X11, you are passing to the network. And in the input layer, we have a 5 neurons. So, X11, you are passing to the input layer. So, first, we have one hidden layer. So, it is a fully connected layer. So, there will be the weight between the input layer and the hidden layer. Size, the weight will be stored in the term of matrix, agree? So, matrix is 5 cross 3, already the same concept, we have already had a discussion. Then, we have a second weight matrix that contain the weights between the hidden layer and the output layer.

So, that part already, you are familiar. The interesting part is what here. So, whenever you feed input to the network, I am discussing the RNN, it will go to the hidden layer. Understand, the size of hidden layer is up to you. So, first important declaration, you may have a 3 neurons, you may have a 5 neurons, you may have a 10 neurons. So, this is the hidden layer. Suppose, here we have a 3 neurons. I am talking about the looping because this is the loop that is making different from the other kind of network. So, loop says that output of this first neuron, output of this first neuron of the hidden layer, will go back and become input of all the neurons of the same hidden layer. Agree? So, there is no 3 different outputs. This first neuron will have a same output. It is going the same neurons, second neuron of the same layer, third neuron of the same layer. Is it clear to everybody? So, there, the first time it is not producing the 3 outputs.

Single output going to all the neurons of the same layer. Got it? Similarly, for second neuron also, output of the second neuron will go back to all the neuron of the same layer. Similarly, for third neurons. So, this will apply for all the neurons of the hidden layer. It is a looping. It is a kind of looping. Is it clear? So, here, very, very, very, very, very important part of today's discussion. Ultimate, you can assume, you can assume, this is like this. Here, you have to imagine what is happening during the looping process, during the cycle process. Three neurons, hidden layer, output of the three neurons are going to the same neurons of the same hidden layer. So, you can visualize. It is not physically. We have two hidden layers. We have only single hidden layers. But it concept of the time. So, it is a time 20. Now, it is a time T1. Agree? So, time start means what? It is a time 20. This is a time T1. What is happening in the time T1?

Same neurons outputs coming from the same neurons output from the previous time T0. So, you can visualize this kind of connections between the same hidden layer in a different time. The diagram is clear. It is not physically we are going to copy the hidden layers multiple times. This is just looping with respect to the time. Is it clear to everybody? So, are you able to see this kind of network? Virtual network? So, network have a connections. Fully connected networks. So, this during the looping, it also have the weights. These are the connections. So, look. I have written here. Yeah. Loop also have the weights. So, there are three neurons. Output of the three neurons are going as input of all the three neurons means that there are total nine connections. Three cross three. Agree? So, there are three cross three connections. It also contain the weights. Yes. Wait. So, it will go three times. I will discuss. Wait for a minute.

So, three means three times it has to execute. You are correct. You are correct. Yes. Yes, Abhishek. Same neurons. Three times if input size is three. Three times this loop has to execute. I am discussing about the first time. Just visualize it. And it also has the weights. That's very important. This loop. This virtual loop also has the weight. Don't forget about the weight. Now, we have a three weight matrix. Agree? How many weight matrix? This is the weight matrix between input layer and the hidden layer. We have a second weight matrix between hidden layer to the output layer. And third weight matrix that normally not we don't able to see it physically. This is what loop. Loop also having the weights. Cut it. So, we have a three different matrix. Yeah. Bias. No, no, no. It is an input. One is an input. How to decode the movie? It is a 1, 0, 0, 0. Okay? Now, how really happened during the training? It's the most tricky part of the discussion.

Okay? Please have a look over here. Don't ask any questions next five minutes. Just see. Otherwise, you will miss a lot of things. Look. First time. This is the training. is just starting. I am giving the first token from the X1 input. That is a movie. Look here. The first input I am passing. Please remember this terminology. Yeah. X1 first input. The three tokens are there. First token I am passing. Okay? So, time T0 or T1. You can give any kind of nomenclature. That doesn't make any big difference. So, T0. First time. I am passing the first token of the first sentence. Okay? It will go to the input layer. Through the weights. It will go to the hidden layer. Agree? Each input will give you output. I think everybody agree? Now, these are going through the loop. Same hidden layer neurons. I am representing here only. Just for visualizing purpose. It is not physically. Just visualizing purpose. Same. Same diagram. This diagram. I am representing in this way.

This hidden layer. Under the loop. The same hidden layer is there. Output of each neuron is going to. As input to all the neurons of the same layer. Got it? Is it clear? Now, the important part is here. This, at this time, they will wait. It will not execute. Means, otherwise, it is infinite loop. So, output of neurons becoming the same input. It will wait for a next input from the data set. Next input from the data set. So, it is time 20. First token. Got it? Time t1. Second token. It is 12. Movie was. So, I have passed first word movie. Then, second term was. Cut it. So, now, the neuron will get the two kinds of input. One from the data set. One from the hidden state. We call it hidden state here. Previous state. This diagram is clear to everybody. Bias always be there. Don't worry about the bias. So, every time, two kinds of input will be given to the neurons. One from the previous loop or you can say the hidden state.

It is hidden. And one from the data set. These two concepts are clear to everybody or not. Then, we have to pass third and final input of first. Yeah. So, first sentence. What I mean to say? If I try to explain again. It is very important part. So, okay. Let me explain again. Suppose sentence was movie was good. Great. And this is your architecture. So, three. First time, we have a three input. Agree. I call it x11, x12, x13. It will feed to the network at time to zero. This is for time t1. This is for time to. It is order. It is not exact time. It is order only. Okay. So, what happened? First, this is the input layer. Okay. So, here I am passing. It is time t0. Okay. I am passing input movie. That is x11. Great. It is going. We have hidden layer. Hidden layer having only three neurons. Agree. So, now, it output of each neuron for the hidden layer will go back to the same layer. Agree. So, this is the loop. Execution first time.

What I say? It has to wait. We have to pass second input from the data set at time t1. Second input is was. Agree. That is x12. So, this is the input coming from the data set. Agree. Now, output of this hidden layer will again go back. No. Okay. This, this and this. Agree. So, this is now time t2. We have to pass movie was. Good. X12 from the data set. Agree. now loop is ended so here because sentence ended so we have process t0 we have process t1 we have process t2 or you can say x11 x12 x13 sentence end sentence end means what now what is the next of hidden layer what is the next of hidden layer suppose output layer so now this output will go to the next output layer agree until so another way if i say this is the input i am passing to the rnn rnn it has to go for multiple time end time once end time is over it will go to the next layer next layer got it internal working of rnn is clear to everybody this great now i have a question for you please ask sora

so how you got the bias added here so this is a fundamental please uh uh uh visit the already recorded videos when i have started the neural network so it is not a right time to ask this fundamental question okay bias means additional input will be there the size of matrix will change only so 5 x 3 means 6 x 3 got it additional input will be there so please visit that part anything else okay so when t2 is feed then it will have a input from the from t1 input from t1 no i never explain you see clearly i am passing first as a t1 then next time t1 then next time t2 what is the confusion every time input from the data set first the input was movie then input was movie was then good got it first input w where is a w mohit i am not clear you just use the terminology what is visible to visible here at your screen first input weight input is w is weight is not input input from the data set we don't need to feed the input we don't need to feed the input we need to feed the input where i have written

the weight in this discussion you see here movie is not a weight input is movie was uh uh input is was input is good where is the weight cut it i'm not feeding the weight i'm i'm just giving the input from the data set anything else anything else anything else already i talk about anuja number of size of input is three the three time it has to go for looping then to the next layer so so depend on the size of input size of input is three three time it has to loop anuja you are correct anything else no and whatever you want you can write if we have loop then weight will be updated yes weight will be updated during the back propagation so mohit you are getting a lot of confusion it is a back propagation it is a forward have you calculated the lost have you calculated the loss here have your model given the output at this time final output will be given by the output layer then you have to calculate the loss

i have already covered then propagation back propagation start then you have to update the weight why you worry about this time you are in the wrong place here we are in the forward propagation we have not started the back propagation yes sorry you are correct now great so rnn is a bit confusing so but but we revisit that recording every minute things that i supposed to explain i had done it for t2 i think you are not understanding whenever i explain so look for t2 for time t2 the loop from t1 i am feeding as a input to the same layer so this diagram is still everything is clear the sequence is clear whenever i explain please listen at that time you think about here what is happening for time t2 new input from the data set and previous layer output got it saraab now clear it is clear sequence for t2 hidden state comes from t1 hidden state comes from t1 for t1 hidden state comes from t0 simple from both so have you seen any connection from the both

just just sort of see this connection at a time loop from the previous layer only so there is not multiple connections are there so just from the previous first understand what i am explaining there will not be any confusion at all have you seen any time t at the time t2 anything i am giving from the t0 no it is in the sequence everything you have to process in the sequence very simple input was movie was good simple first input this then loop then give the input this then loop then input this simple it is connection like this ok so we should move ahead you need to visit more sources and videos to understand properly ok so this is about now in better way i can visualize it is about the unfolding of rnn very interesting ok so there is a one important part i missed somewhere ok so you may be worry about the first time this is a hidden layer very important question nobody have asked i was waiting this is a hidden layer three layers ok three neurons hidden layer

i have given input from the previous layer ok got it then we have a loop then we have again same hidden layer suppose input was movie so this is this is one then next input is movie was ok so how many kind of inputs are here you tell me how many kinds of inputs are here at this place right on the chat box otherwise it will be again a big question for you ok is it clear how many type of inputs are here answer first two correct answer at this time how many inputs are there at this time here one it is a mismatching or not sometime you are feeding single kind of input some you are feeding two kinds of input how the architecture will manage it during the execution system doesn't know what is happening sometime you are feeding the two input two kind of input sometime the single kind of input so answer is here we also have a two kind of input agree architecture always same for a hidden layer every time two kinds of input here so random we assume that random loop first time also

assume the random loop so it would have a hidden state also have the hidden state that is a random that is a random agree so in another way if I explain so this this is word movie okay I am passing to the hidden layer okay this is time two zero also have a input ht zero this is assume that random loop is coming from the previous time stamp so this is the first time we are feeding we don't have any hidden state so I will I will consider a random that is a random hidden state we have a initialize random hidden state agree so it will consider output from the previous cycle this is output from the input from the data this is input from the data set it also having a two kind of input at the first time to zero got it then we don't have any problem next time input from this input from the data set two kind of input it is clear so this input I am calling h1 previous state input this is previous state input ht0 like that this is the basic terminologies so there is a one good concept in RNN is unfolding what do you mean

by unfolding so what happened in the CNN or typical architecture you just see here suppose in typical it is not RNN it is normal perceptron you can assume that we have an input layer suppose we have a three hidden layer so how it happen input goes from input layer then process by the first hidden layer then output goes to the second hidden layer then third hidden layer then at the last output layer a simple perceptron is it clear to everybody it is clear to everybody okay so but in RNN what happen hidden layer you can assume multiple time you have to execute this hidden layer at the time 20 time t1 and time tn agree so here same hidden layer need to be executed by multiple time depend on the size of n is it clear to everybody this is one big difference from typical neural network and with the RNN same hidden layer need to be executed multiple time n time okay so that's why this is a normal symbol logo of RNN you can see whenever you will see in the internet and in the book it says the input then hidden layer then multiple time goes for the looping process how many time

loop n number of time then it go to the next layer it is not output it is next layer ultimate it is the correct picture suppose you have a hidden layer multiple hidden layer also possible in the RNN you may you should ask this question so what happen if you have a multiple hidden layer in the RNN like suppose this is your input layer okay got it first hidden layer got it then second hidden layer it is not looping it is a hidden in the third hidden layer then output layer so suppose I have an input of like again same input movie was good what do you mean by it will execute three times then output will go to the next layer it also execute three times then output to the next layer then also execute three times then output to the next layer Anujay already I have covered this question how do you decide hidden layer size of hidden layer in earlier models you tell me I have a question for you Anujay how do you decide the hidden layer size in normal network same answer is here okay hit and try you have to do all kind of possibilities number of neurons which setup will give you the good result you need

to keep it there is no formula okay I already covered this question same question you are asking means you are not referring the recording hidden layer size okay hit and try hit and try already I have answered there is no formula there is no mathematical formula okay now it should be clear to everybody clear Anujay yes Moeid you are correct Saurabh Kumar Pandey sir any criteria to decide the number again same fundamental question you are asking random is what random weight initialization the same question you can ask sir how to decide the weights matrix 5 cross 5 weights are there how to decide the weights random agree so ultimate first time first time what is happening time to zero it is assuming this is the hidden layer it is giving output if it is random may be 0.01 may be 0.02 may be 0.03 agree with input from the dataset got it this is the random output so any small number you can assume the way you initialize the way it same concept got it not possible Hrithika not possible so in hidden layer only output come one from the hidden state we call it hidden state got it one come from the

dataset so only two type of input possible answer is Hrithika clear okay in LSTM in LSTM three kind of input possible I will cover it three kind of input possible I already covered Saurabh I already covered your answer you are not listening at the way you are asking I already covered what is this if you have multiple hidden layer each hidden layer will execute three times if n is three okay already I have covered this look in the case of three hidden layer every hidden layer go for the same number of looping depend on the size of input got it great normally people don't cover RNN in this kind of from scratch and basic fundamental so you are asking the question that's a good sign but whenever I explain be attentive only so you will have very less questions okay so moving ahead okay yeah so low okay I'm going to again have a detailed discussion to everybody it's again very critical part first understand carefully don't ask any questions once it is over then you can go for the questions so look here we have three inputs okay so we have three inputs three tokens in the first input x11

x12 and x13 okay we are passing to the network the first input we can start with the time 20 or t1 it doesn't make any big difference the first input we have to give then second input we have to give then the third token we have to give okay so what is happening it's very important please everybody so what is the terminological time t1 means first time so don't confuse with the sometime i'm using time 20 sometime i'm using the time t1 so here time t1 means the first time i'm just starting the training so suppose this is your network agree i'm passing x11 first token through the weights w1 means weights between input layer and the hidden layer it is clear yeah first input this is the weights between hidden layer input layer and the hidden layer it will go to the hidden layer hidden layer will give you output hidden layer output i'm going to store in the vector o ok so for example this is hidden layer i'm passing x11 through w1 matrix the way you can present this w1 matrix it will give you output i'm going to save this output into the into weight matrix or the vector you can

say o1 agree so what will the size of o1 only 3 because 3 neurons each neurons output i'm going to save a vector o is it clear yeah now next time stamp next time stamp so the output of this will go to the same hidden layer same hidden layer okay i'm explaining with is like a weight matrix here h1 so this is the weight matrix between the loop this is weight matrix between the input and the hidden layer agree so now we have a understand the second timestamp the new input x12 from the data x12 from the data and one input is coming from the previous timestamp or hidden state o1 okay so now in this time we have two input previous loop input and the input from the data set okay so now look over here this is a very important formula how to calculate the output of the hidden layer i think everybody know how to calculate the output of the hidden layer simply this is a net input multiply with the weight matrix simple neural network formula simple perceptron okay so this net input net input i am passing with the activation function of the hidden layer agree so output of this process it will give you

output of the hidden layer got it the three outputs got it is it clear or not this and suppose input is here 1 0 size input is 3 so we have also weight okay like this w1 w2 w3 so what is the output of neuron is weighted sum and this is called net input it is very basic and net input we have to pass to the activation function agree so it will give you output of each neuron that i am going to save with the vector o so this i have extended the formula input was 1 0 that is a token first token movie that was vectorized with 1 0 so each input with associated with each input with associated with each input associated with you have to pass so this is will give you net input net input to the activation function of the same neuron it will give you output got it now here two inputs are coming agree so two inputs are coming first input from the data set x12 and another input from the previous hidden state and both the input we have to multiply with their weights both input we have to multiply with their weights so where are

the weights okay so let me explain this last important part I am explaining this is the first version okay then looping okay looping so this weight I am representing with the H agree and this is the input x12 coming from the data set I am representing with the W this weight matrix is W this weight matrix is H input here this is the O here this is the X suppose this is X so it is going over here it will have activation function F first net input means X dot W plus other input O dot H O dot H agree you solve it you will find the output of the second iteration that's it is written in formula data set coming input from the data set weight matrix previous layer output and weight matrix looping weight matrix agree similarly it will go layer by layer everything I have written okay any question at this moment now any question now you can ask whatever it is visible in the screen based on that you can ask the question okay one thing is missing okay one thing is missing where is the second input at the first

time because I what I talk about in every time hidden layer will have two inputs okay so I have not mentioned here actually it is there actually it is there yes answer is here look we assume first time literally it don't have any previous layer output there is no hidden state but we assume here so it is a random number okay so ultimate calculation and matrix of formula in every time size wise it will be sent so actual actually this thing is going to happen these are the way so previous things if it is clear to you these are the red color points I have written these we have to consider as a random input we assume that we have previous states and the random output of the hidden layer neuron we have to consider as got it random output anything 0.11111 through whatever the three value you can consider if the size of hidden layer is three so assume that yeah so first time input is x11 there is no actually previous previous loop so you can assume any of the output from the previous layer any output

you can assume okay so that is called random output for the next time we have a correct output or correct output which means measured output okay so that was the part of the RNN I have covered it it is not enough I know just I have given the idea so that if you refer any of the book video channels other website you will able to understand the discussion and where rarely you will find that detailed discussion okay got it yeah so normally you will find this kind of diagram or symbol for represent the RNN so let me explain that is the most famous is this one all are same what is happening first timestamp I'm giving the input from the dataset then you have output that I call h0 hidden state output then next timestamp next input from the dataset and output from the previous state will become input to the current state and like that like that if you are giving output to the next layer it will become y0 otherwise it is s0 both are same don't get confused if you want to really print the

output then you can print output as a y0 otherwise you can send to the next layer or vertically you can also explain similarly vertically x0 then h0 it will become input to the next timestamp like that so this diagram is clear to everybody now very famous way of representing great now I will explain okay so this is simple already I have explained mathematical part it is not important yeah so now it's the time to cover the type of RNN okay so next I'm going to discuss about the type of RNN one to one one to many many to one and many to many okay so yeah where it is it is here it's very important it is very interesting so okay let me explain here okay type of RNN so first one is suppose one to one one to one one to one means we have input always have a single input we have to give to the network RNN understand here RNN is here giving you one output if this output is very single so that is called one to one this is also called vanilla neural network very famous term so somebody will ask what is a vanilla neural network

RNN so it is one to one we will have a single input and single output another condition is that this single input should be non sequential it is non-sequential output should also have a non-sequential output so actually this is normally you can think about like a perceptron and it doesn't realize or demonstrate the real power of the RNN so but this is one of the fundamental type of neural network RNN okay example if you say the left hand side okay example is what in vanilla neural network or one to one RNN we have one input and one output at a time and input should be non-sequential and output should be non-sequential example is image classification so what happened in the image classification if you are using the RNN if you are using otherwise CNN is the best but just for technical purpose if you are using the RNN so image at a time how many images you send during training one one image at a time output will be what either it is cat either it is a dog either it is a horse at a time only one output

so this is one to one so these are the class at a time you will predict the single class we have a single output that's why it is one to one RNN ok next is one to many one to many means what we have a single input we have a single input to the RNN will give you multiple output multiple output agree so this single input should be a non sequential but output given by your RNN model must be a sequential multiple output so you can think about how it is possible so can have you seen this application of RNN image captioning image captioning so what happen in the image captioning you feed an image to the RNN model the single image as a time single image a single input RNN will create a caption caption means text about the image like image a cat is sitting on table that is a very famous application of the RNN whatever happening in the image it can explain in the term of text so here multiple output agree we have multiple output multiple tokens and this would be a sequence here one to many is clear to everybody now so yeah second is one to

many this image captioning or many other examples now many to one many to mean many to one means in RNN we have multiple inputs we have multiple inputs we have many input to the RNN and RNN will give you single output we have a single output so it should be a sequential input should be a sequential and output should be non sequential okay what are the applications are there sentiment analysis sentiment analysis what happen we give the feedback feedback in the term of or review in the term of review text these are the sentences you feed to the RNN will give you answer it is either it is a positive sentiment it is a negative sentiment or it is a neutral okay so output is what a class a single class that's why output is single so this concept is called one to many to one okay now we have two versions of many to many and many to many we have two versions okay it's very interesting please it's very interesting understand here many to many to many I am going to discuss about version one version one says that I am giving I am giving

multiple input multiple input multiple input like that from the data set assume that it is a text okay it is a text once all the input is processed by in one go suppose sentence is given once your input is ended then your model will start giving output like y1 y2 y3 and yn agree like this so this structure is what we are giving many input this is again a sequential because text we are giving output at a time multiple output it is again a sequential text agree so this is called many to many you can recall the application of machine translation machine translation how it work suppose you are giving you have given a text in Hindi agree complete sentence first you have to provide once complete sentence has been entered then your model will start converting sentence in one language to the another language agree yeah so machine translation or language translation is an example version 2 many to many version 2 many to many so what is happening over here the same example I am taking you have a input x1 x2 x3 dot dot

x1 many input at a time you are giving to the model if model is giving output the same time the moment you give the input start giving the input you should not wait to end it this is called another way okay oh one thing I forget this version 1 this version 1 this version 1 is nothing but a simply encoder decoder encoder decoder have you listened this name this is encoder decoder first version of many to many where first input let it completely given to the model later it will start giving the output we call it encoder decoder okay so this this another version so example working example is what frame level frame level video classification video classification agree for example video contain a lot of frame a single video contain a lot of frame suppose this is a frame 1 this is a frame 2 this is a frame 3 just hypothetical example I am making in the frame 1 suppose a cat is visible frame 2 again cat is visible frame 3 dog is visible frame 4 horse is visible you give to the model frame wise model will predict it

is a cat it is again a cat it is a dog it is a horse got it so this is called a second version of many to many RNA sequence to sequence same this encoder decoder sanjay this is many to many sanjay you have written about that encoder decoder first version of many to many got it we call it sequence to sequence please yeah so the sequence to sequence is very famous name so encoder decoder or we also call it sequence to sequence very famous name sequence to sequence version please remember this word okay so I have covered it yeah it's very important now I am just I am sorry loop is still there in every process sequence yes loop will be there loop will be there sorry you are correct you are correct yeah loop always be there always be there so whenever I am writing this this is the RNA architecture it can have a single hidden layer it can have a multiple hidden layer got it this is total RNA architecture yeah thank you so now I am bringing you from RNN to the LSTM next model so there are some problem with the RNN there are

some issues with the RNN those issues can be solved in the LSTM so let me explain the background about the issues okay so Anujay I will I have a plan to cover encoder and decoder okay so in the coming classes your answer will be given at that time got it so in there are two kind of problems I think I have covered it earlier or not vanishing gradient problem or exploiting gradient problem exploiting gradient problem very famous questions and favorite questions in the interview it is the characteristics or problem that can with any deep learning model so do not consider this is the concept of the RNN it is the concept of machine learning these two kind of problems any deep learning model can suffer understand any deep learning model can suffer but RNN suffer with this problem with very frequently very frequently that is a problem any you cannot say there is there is a there is a one model that never suffer from this kind of gradient descent gradient vanishing or vanishing gradient or recording gradient

involved there may be any model can suffer with this problem but RNN suffer very frequently why so what are the problem first recall the back propagation recall the back propagation in the back propagation what happen we start updating the weight we start updating the weight okay understand RNN suppose let me take the example of sentence okay sentence suppose sentence size is 30 agree a very simple sentence size is 30 and the network RNN network suppose have a 5 hidden layer how many hidden layer 5 hidden layer okay so first hidden layer how many time the loop will be executed how many times the loop will be executed 30 times second hidden layer this again executed 30 times similarly for H3 very very small network I have taken 5 hidden layers very small network I have taken this is 30 times 30 times this is 30 times so between these how many loops are there 150 times agree 150 times so assume that 150 times ultimate a lot of loop a lot of loop lot of loops are there and every loop we need to during every loop we need to update

the weight we need to update the weight in reverse order so look how many times we have to update the weight very small network we have to small network suppose this is so we have to update the weight here first time then we have to update the weight we update the weights we have to update the weights similarly how many times dot dot dot 150 times at least is it clear back propagation is clear to everybody and how to update the weight w new will be I think everybody agree w old plus alpha gradient of the loss with respect to the weight okay yes Anuja yes during the back propagation your model during the forward propagation remember everything how many times you have executed the loop it will remember it will maintain during back propagation same number of time you have to update the weights so Anuja you are correct is it clear Anuja yes so you just think about how many loops will be there so if there are 30 loops 5 hidden layers then for first input you have 150 loops will be there so 150 loops you can unfold that is why I have

discussed unfold agree this is unfolding with the time so how to update the weight so normally this is very small number if you practice it it is a very small number this is again very small number very small number and it this you are propagating from layer to layer layer to layer layer to layer layer to layer layer to layer layer to layer layer to layer and every time what you are multiplying you are multiplying very small number multiplying very small number agree so it is making making very very very small number the problem is clear to everybody yeah so what happen at the initial layer at the initial layer of your network initial layer of network suppose these are the initial layers for example these are the initial layers so your weights so what happen weight new will be weight old plus alpha this thing and it will become 0 or near to 0 so what are you meaning of that new weight is equal to old weight got it so no weight update no weight update no weight update means

no weight update means no learning no learning got it so this is called vanishing gradient problem just opposite is exploiting gradient problem exploiting gradient problem just opposite suppose this is it is rarely happened this is a big number you have taken already derivatives are big in case understand and alpha is also you have taken like hundred big number alpha normally it is a guideline alpha is normally you keep very small number but suppose you have taken hundred it is again a big number so what is the meaning of that you are multiplying with big number multiply with big number ultimate super big number super big number means now think about weight update will be w old plus very big number very big number means your weight update is very drastically drastically okay so in this case your learning will be slow or not good learning not good learning this is called exploiting gradient problem okay so yeah another RNN problem the third problem I am discussing it it does not

learn long dependency long dependency it's very important concept long dependency long term dependency so let me explain here everything is written you can go through it yeah long term dependency so what happen you need to understand in the particular text particular text suppose text set return a lot of terms text have lot of term 20 21 so suppose you are processing this term you want to encode or you want to translate or you want to classify anything so sometimes this term may be dependent depend on the previous term by 10% or may possible the decision you are making at this time can be taken from the term that appears long before and the relation is very strong 90% so this is called long term dependency the term or word at this moment may not be heavily depend on the previous terms it may heavily depend on the terms that appear much before so this concept we call long term dependency okay so this is RNN fail RNN cannot learn the long term dependency so what do you mean by the long term dependency

I will explain with one very good example look so look this is the sentence please have a look on screen Ram studies in the 10th class sentence and dot he is a good boy what is he this term is he or she is referencing for what class or 10th or studies or Ram you answer whenever the RNN is processing this term he what RNN should understand he means what Ram it is a long term dependency it is a long term dependency he is good boy and attend the class daily sentence and again he he means what he means again a term appears much before at the beginning Ram got it now he lives in Agra that famous for Taj Mahal sentence and which now what is which here the RNN has to learn automatically which means not Ram here now which means Taj Mahal so RNN has to forget everything and develop the new relationship okay so that was built in the year 1700 it is a symbol of love it means Taj Mahal this is the example great so all these problems are in the RNN and we solve this problem by using LSTM so LSTM is a solution LSTM so let me explain

with LSTM okay so yes very interesting in RNN please understand RNN what happen we have a feedback this is one loop agree we call it hidden state agree we call it hidden state okay it is clear in LSTM we have one extra loop one extra kind of loop we call it cell state that is a one big difference between the RNN and LSTM we have a hidden state in the RNN we have additional one state in the LSTM I'm covering about the LSTM have additional state we call it cell state agree so hidden state also the name short term memory hidden state in review of RNN we call it short term memory short term memory and in LSTM we will have cell state this is called long term memory long term memory got it that's why LSTM full form of LSTM is what long short term memory because it have both short term memory and long term memory agree so let me explain again with this very beautiful example yeah so just focus over here during the learning sometime okay so during the learning during the learning understand the aspect first we have to forget something we have to forget something I think you have to say yes or no

if you are agree forget something that is not important that is not important or relevant I think everybody agree or not also we have to add or learn new thing new concept yeah new thing that is relevant that is relevant or important I think everybody agree or not for example this so he is important and relevant he is important relevant whenever you enter the next sentence we have to forget the relationship between he and Ram we have to add the new relationship which and Taj Mahal it with the which it is the Taj Mahal this is the new relationship we have to learn earlier relationship we have to forget slowly okay so this is the concept is implemented generated by rnnn okay so look this is the architecture of the rnn okay please understand here look architecture of the rnn so here this is one line ht ht-1 means h0 typical rnn this is one layer I am maintaining typical rnn we have additional state cell state so two states at a time we are maintaining hidden state and the cell state and these two states have to communicate with each

other so that's why we have three kind of gate so rnn all about the rnn is the gate concept rnn having three gates forget gate input gate and output gate what is the functioning of each gate let me explain forget gate think about if something is not important right now something is not relevant like the relationship between he and ram at this current position is not important not relevant we have to forget it we have to forget it so information that is no longer important we don't want to convey we want to delete it we want to remove it an important part is that please understand whenever we remove something we forget something or we add something it cannot be a binary you can say sir forget 90% things you can forget about that relationship you can remove or forget 80% of that relationship you can say 10% of that relationship if that relationship is not important at all you can say 0% don't remember if this relationship is 100% you can say 100% keep it like that so here it is not binary because somebody will ask this is he and

ram at the beginning the importance is 100% agree it may happen at the later this he and ram is not coming together in the story we slowly start forgetting first forget 90% then forget 80% then 70% like that if again he and ram appear in the sentence we can add it we can add it through the add gate so it is not like that if you forget about he and ram you cannot add it next time if it appears in the data set you can add it okay Narayan that was your question so forget gate is about forget something that is not important input gate is means whenever you feel the information is something relevant important you add to the memory it is happening to the cell memory only cell state I am just discussing about only the cell state because hidden state is as it is we have discussed with the RNN as it is so you can think here in LSTM we have two kind of state LSTM so this is the hidden state hidden state that we have seen in the RNN then we have a next state cell state cell state it is new and there is also communication between hidden state and cell state here we have three kind of gate okay so like forget gate input gate

and output gate so this is the architecture very interesting architecture look yeah so very simplest one in this is input is coming from the data set it is previous state output typical RN previous state output it will go to the network then output will go through the this operation and it will check cell state if this is like a he and ram relationship is important or not if it is important it will keep at is it as it is if it is not important it can reduce by 90 percent by 10 percent or completely forget okay similarly the input will go to the next two operations and it is called as input state it will decide during the training the input the new relationship like it and taz mail at this time suppose it can decide this new relationship okay you should learn it so it will add to the cell state forget state sorry output state means how much of hidden state and cell state by combining you can give as output of the hidden state so there will always be the two output so here you can think about somebody will ask how many input in the RNN having the three inputs at a time how many inputs in the LSTM RNN having

two inputs at a time in the LSTM the three inputs at a time so input from the dataset hidden state input and the cell state one additional input similarly in the RNN we have a single output that is called HD hidden state output here we have two output cell state and hidden state these are the operations these are the operations these are the operations point wise operations these are the point wise operations okay look here one more diagram a lot of things are everything I have written here whatever I have explained more detailed picture is here yeah this is look this is simple sigmoid function this simple sigmoid function sigmoid function what does output value will be between 0 to 1 okay so what is the meaning of that so this is suppose hidden state is input is suppose st 0 I am passing from the data set it has calculated something suppose he and gram agree he and it is going with the sigmoid operation sigmoid operation means what it ranges between 0 to 1 agree so this is the vector output vector hidden state output vector is what three values will be there agree and suppose this value

is 10 this value is 20 this value is 30 agree it through passing through the sigmoid operation this operation output value will be what output value will be suppose it is 0.1 it is 0.2 it is 0.1 again agree so this is your output this is your sigmoid state output you need to multiply you will see output is what 1 0.4 0.1 0.4 0.3 agree so it is reducing or not it is reducing or not please focus on the screen it is reducing or not it is reducing it if it is important so it will keep 1 so if it is important 1 means now you can see the multiplication will be 10 20 30 so means everything we need to retain everything we need to retain everything suppose it is 0 during training it model will learn then output will be 0 forget everything forget everything very interesting so just in this PPT I have so these are the simple operations that you can go through it in PPT I have discussed every operation in detail every operations forget gate what is happening what are the activation functions already covered okay so I will upload this PPT for your reference you can refer to it so any use case we should

prefer RNN over the list despite our drawback more hidden layers means there are more chance of vanishing yes Ritika you are correct you are correct so sort of I don't have any direct answer but if the data set don't have any long term dependency in such case you can use the RNN and you have only very few number of hidden layers otherwise there is no such case where RNN you can say always be better than LSTM more hidden layers more deeper model so Ritika you can ask the question like that if model is more deeper more chance for vanishing gradient problem is it clear Ritika okay so time is also over I will upload all that notes to the Moodle you can refer to it you need to learn you need to refer a lot other videos and sources the RNN and LST are bit tricky okay thank you okay so thank you so next class maybe one announcement next class maybe I promise I request one of my scholar Dr. Asis Patel it will take one class maybe in the next class I think next Tuesday maybe next Tuesday about sequential modeling sequential modeling it is given in your course by using ARIMA or relevant model okay

so next time maybe next Tuesday Asis will be there for handling one class of sequential modeling in detail okay thank you is it clear so I talk about this important part so maybe I just stop sharing this is so next class maybe about sequential modeling where the machine learning algorithm that is extension of the linear regression ARIMA or SARIMA kind of model will be explained by one of my scholar Dr. Asis Patel he will cover about this thing in the next Tuesday may be possible okay please remember thank you

