Thank you. Good evening, everybody. Am I audible? Good evening. Am I audible to all? Great. Thank you. Good evening. Okay. So, we are starting our class. In the previous session, we have completed two very fundamental but very powerful deep learning model that was, if you remember, RNN and LSTM. Okay, so there were some few problems with RNN, particularly RNN is not able to learn the long-term dependency. Long-term dependency. So, to solve this problem, so to solve this problem and also it suffer from, I think, radiant exploiting and radiant vanishing problem. Okay, so we try to solve this problem with the advanced deep learning model, LSTM. So, what we have done LSTM, like in RNN, we have only single hidden state. We have a single hidden state, in RNN, we have two states, in RNN, we have two states, cell state and hidden state, if you remember. So, cell state, we represent with the C and hidden state, we represent the H. Okay, and we also seen the new idea with LSTM to using the gates, using the gates. In LSTM, we have a three type of gate, if you remember, the forget gate. We have an input gate, and we have an output gate, just a revision of previous class, output gate. So, these three gates control what information is not important, and during the learning, we feel the information we don't need to carry forward, so we start forgetting it. So, it does not forget in binary web manner, it just filters out the unnecessary information. Input gate was for, suppose new information, new learning is need to store in the cell state, so if the coming information is important, try to carry forward or try to save in the cell state. So, these are the three kinds of gates, we have seen in the previous class, that was related to the LSTM. Okay, today, we are going to discuss a very interesting topic, that is a fundamental of many advanced models. Today, we are going to cover the encoder-decoder, encoder-decoder, sometime we also call it sequence-to-sequence model. Okay, why it is important, because this is very much fundamental of, very much fundamental of attention model. It is very much fundamental of transformer. It is very much fundamental of BERT. Okay, so what I want to convey, like we have seen, are the CNN. CNN is the most fundamental based model and other advanced models are based on that. Similarly, encoder-decoder is a fundamental of transformer, BERT and attention model. So, I will cover this architecture of encoder and decoder in Gen AIS. So, in detail and later, very briefly touch upon the transformer. Because transformer is nothing but a simply, if I say transformer means what? Transformer, BERT is a kind of transformer. So, transformer means what? Transformer will be encoder-decoder, encoder-decoder plus attention. That is the difference only. So, encoder-decoder is a fundamental. If you use the concept of attention on the encoder-decoder, you will call it transformer. So, here the transformer and BERT, we are not going to discuss in detail. Just we will see in the coding class. So, starting with the encoder-decoder. So, if you remember, we have seen variant of RNN like 1 to 1, if you remember, 1 to many. Many to many. Many to one. And many to many. If you remember, many to many. Under the many to many, we have seen the two versions. So, this come here. This is the topic we are covering. Sequence to sequence model or encoder-decoder. We are here. Agree? Great. Okay. So, what is the specialty with encoder and decoder? You can say, sir, we had a fundamental model of RNN. We have a model life LSTM. And similar, we have a GRU. Okay. So, what was the problem with this one? Okay. So, why there is a need of encoder-decoder? Why we need it? Okay. So, there is one problem understand. Applications where this kind of demand. Applications where input, what the input you are giving, it should be in variable length. And it should be a sequential data. It should be a sequential data. Two properties require. And whatever the output we are expecting, it again a variable length. Again a variable length. Plus its output should also be a sequential. This is the need. So, you may be asking, sir, where is such kind of need? So, applications like a language translation. Like a language translation. Where you are typing a sentence into, in the Hindi. Suppose it has a hundred character or hundred words. May be possible. You are converting Hindi to any of the another language like English. It may have 80 words. So, what is the meaning of that? Length is variable. Output, input length is variable. Sometime sentence may be a hundred words. Next may be a twenty words. Next sentence may be a fifty words. Like variable length. And all are the sequential input data. Output may be a seventy word, eighty word, fifty word, like that. So, output also in variable length. And it is a sequential data. So, if it is a requirement, typical RNN cannot do it. This architecture does not support it. LSTM, GRU. These are the very famous powerful model. But they cannot fit on such a requirement. Requirement is what? Requirement is that variable length input, variable length output, sequencer input and sequencer output. Okay. So, because of this property, we also call sequence to sequence problem. And the problem that solved with the encoder decoder, that's why we call it sequence to sequence model. Okay. So, that was the background. Okay. So, let me, this is the document I will upload. So, let me read out something for you. I will go this topic very slowly, slowly. Complete day, I will cover this topic. Because it is very much fundamental. Sequence to sequence model are the neural network model. We agree that transfer one sequence into another. Input and output length may be different. Okay. So, it process the input sequence and generate the corresponding output sequence. It handle the variable length input and output already covered. It is very much useful in NLP where the machine translation, speech recognition, time series predictions are the basic application area of the sequential model. This is very brief, very high level flow of working of encoder decoder. So, what it says that left hand side, we start assuming this is the input. You can consider this is the text. Okay. So, like the two names are given encoder and decoder. So, that's why there are two components. Okay. One component we call it encoder. Another component we call it decoder. Okay. So, it carry the two component that works. What does encoder? Encoder is just, what is encoder? What is the architecture of the encoder? I will discuss later. Because understand the high level understanding, it is one component. And it receives the input. Suppose it is a text sentence input. It encodes. Encoder means it transforms the representation of the input data to something else. In something else, we call it context vector. Another way I can say the input of the encoder is input from the data set like a text sentence. Output of the encoder is a context vector. So, it is converting input to another form of representation. And that representation will call it context vector. How it is converting? I will discuss. Later, the encoder task is over here once we have a context vector. And then, once we have a context vector, we start giving context vector as an input to the decoder. So, decoder receive context vector as an input and offer the desired output. So, maybe this application is for a summarization. So, input may be of 100 lines and output may be of 10 lines. Or you can consider input is Hindi or equivalent English is output. Okay. So, now let me elaborate again in more detail. Like we have seen many to many, many to many. We have seen the two versions. Okay. What first input is given like that, like that, like that. It will process, it will process, it will process. Then, it will generate the context vector. Context vector. Once it is over, this is called encoder. Once it is over, then rule of decoder start. Then rule of decoder start. Decoder will give you output that we are expecting. So, this is called decoder. Both are converting the representation. Both are converting. How? Input may be a text is given to the encoder. Encoder will give you output as a context vector. So, what it is? It is transforming input to the another representation context vector. Then further, what we are doing? In the context vector, we are considering as an input and giving to the decoder. Decoder also transforming context vector to the output. Output may be a text. Okay. So, that is the idea. So, we need to understand two basic components of encoder and decoder. And what is the purpose of it? How they are doing the things? We will discuss. First, understand the purpose. Okay. So, this is just an example I have given. I think everybody understand. In machine translation, what we do, we have a supposed sentence in how are you that contains the three words and its equivalent language may have two words together. So, that we have seen. Similarly, for speech recognitions, the input is in the term of voice recording. It is a sequential input. And given to the model, the model will convert voice to the text. Okay. So, this is again one of the application of sequential model or encoder decoder. Similarly, image caps name. Okay. You have also seen the subtitle generator. In the movie, different languages and subtitles you might be seeing nowadays in Netflix or any other OTT platform. So, data are generated automatically. So, that here also involves the encoder decoder. What is the important part? Yeah. So, let's see in another example. So, the source sentence is written in one language. See in the just green color box. And below it is equivalent output that we are expecting in the English. So, encoder is here. We will give the input in one language. Okay. It will encode. After the encoding, context vector will be given to the decoder. Decoder will try to predict its equivalent representation of another language. Okay. So, that is one idea. Okay. Yeah. This is now very important. Slowly, slowly I am just covering a detailed discussion. So, everything I have written here I will also explain. The encoder process the input sequence token by token. Updating its internal state at each step. After processing the entire sequence, one input. One input may have N number of words. So, what I try to explain. Suppose input is 1.0. So, what I try to explain. Suppose input is 1.0. 1.0. this into a context vector. Context vector. So what we learn? Input sentence where each token will be given one by one, let them understand the thing. Typical way of RNN. Just recall the RNN. Encoder job is to process the entire input sequence one token at a time, one word at a time. Don't forget it. It does not produce an output at each step. Very much people are confused. Encoder, the moment you feed the token to the model, the model will start giving the output. No. It will wait. Complete input is given. Complete input means not complete dataset. Complete input like I love ML. One sentence is a complete input. So one input is given. So it keep on updating their internal state like a hidden state. It understand the complete sentence that given from the dataset. Then it converts the whole understanding from the input sentence to a vector. That is summarized vector. A very rich vector. The semantic vector that is called context. text. So if I try to explain, suppose I have written a very long sentence. I love movie that was released in 1997 and add. Very, very big sentence I have written. Okay. Suppose 100 tokens are there, 100 words are there. Okay. So encoder task is to given as an encoder. Encoder understand all the stuff, relationship between the terms and trying to summarize in a vector, dense vector. That is a small and dense vector. Dense vector. So maybe the size may be 10. Size may be 10. So whatever the sentence you are feeding of 100 word, it go token by token to the encoder. Encoder try to understand it, summarize it and try to represent in very semantically rich vector of a smaller size. That is a dense vector. This size may be 10. Got it? It's a numeric number only. Like this. Very, very important point. Very, very much important point. Please understand. Input size is, input size is, input size is variable. Agree? Input size is variable. Similarly, output size is variable but, this is very big but, context vector size is fixed. It is not variable. Context vector size, whatever you decide, up to you, it is fixed. It is fixed. Once you decide the size of the size of context vector you are using of size 10, it doesn't have any relation with the size of input and size of output. Whatever the input you are feeding, that need to be converted into the size of encoder only, encoder vector. So based on the varying size of input, context vector size doesn't change, doesn't change at all. What is token? In this process, it is equal to yes. Token means individual word. Already, during the NLP, we have covered in detail. Okay? So, size of context vector is clear to everybody. It is not variable. It is fixed. Okay? Now, you may be worried about what is encoder actually? What is encoder? You are talking about encoder, decoder. What is encoder? So, now let me have a discussion on encoder. Or, encoder can be anything. Encoder can be anything. It can be a series of RNN. It can be made by using the RNN. It can be made by using the LSTM. It can be made by using the GRE. So, RNN is already covered. LSTM is already covered. GRU is very similar to the LSTM. So, it is up to you. The way you want to implement the RNN decoder. Decoder is not something new. It's kind of arrangement. You can arrange multiple RNN, multiple LSTM, multiple GRU together and start calling it encoder. Similarly, decoder is what? Decoder is same. It can be RNN. Put multiple RNN together. It can be LSTM. It can be a GRU. Is it clear? Encoder, decoder is nothing a new idea. It's just arrangement. Arrangement can be made of using RNN, LSTM and GRU. So, important part. If you are using RNN in encoder, then it is important. You should also use similar RNN. RNN, similar RNN in the decoder. That's very important. If it is LSTM, the encoder is made of LSTM. Decoder should also be made of LSTM. Is it clear? Is it clear? Very important. So, here you see first time in the diagram, I'm using LSTM, multiple LSTM in the encoder and you are giving input like the weather is nice. So, you remember the encoder have two states. H means hidden state, C means cell state. So, output of the encoder will be what? Two states, hidden state and cell state. Okay. So, now you will be very much surprised to know what is the context vector. From the very scratch I am covering, people don't cover it. Okay. So, suppose your encoder is here. Suppose your encoder is here. Encoder is made of LSTM. Okay. So, there will be multiple LSTM. What is the final output of the LSTM? You know, it contain the C, it contain the H. Agree? Is it clear? From the last class, it maintain the cell state and the hidden state. Or make it more simpler. Make it more simpler. For example, suppose your encoder is made of RNN. So, RNN, every time it generates the output, we call it as hidden state. Agree? Up to this moment, things are clear. This is the context vector. Context vector is not nothing new idea and this is called context vector. So, output of the LSTM like cell state or hidden state, output of the RNN like a hidden state, nothing but a simply, it's a vector, context vector. The context vector is nothing but simply output of either RNN and LSTM in the term of cell state, hidden state or hidden state. Agree? So, size is always fixed. If you remember, size is why always fixed? Suppose this is your input layer. This is your suppose hidden layer. Agree? So, we feed input. Okay. So, output of hidden state, we are maintaining a vector HT. If you remember, the size of HT is always fixed. It depends on the number of neurons in the hidden layer. Input size may vary. Got it? So, this is the vector. H is a vector. C is a vector. H is a vector. Agree? So, now you'll understand very interesting part. Encoder is RNN. Agree? It is giving HT as a context vector. Context vector. Then, we have a RNN decoder. Decoder. Now, you tell me what is the input in the typical RNN? Typical RNN recall. This is input from the data set. Agree? And input is coming from the previous state. Agree? So, two input we give in the RNN at a time. Is it this concept is remember everybody? So, this is the RNN decoder. So, one input I will give you from the data set here. And another input is coming from the encoder. That's why if here is RNN, then here also should be RNN. If you keep LSTM here, how will you? Because LSTM requires what? Let me explain. Suppose we have here, for example, RNN. Suppose I am taking the RNN here as an encoder. It gives the HT as a context vector. Then, we have a LSTM suppose as a decoder. We change it. So, LSTM what demands? STM demands first input from the data and it expects two inputs. C and H. Agree? So, if RNN is a decoder, it will give you one input ST. Then, CT is missing. So, this architectural difference, it is mismatching. So, it doesn't work. So, both sides in encoder, decoder, similar architecture is supposed to use. Okay. Now, let me go with the detailed discussion. Similarly, similarly, we are going in a detailed discussion. Look. So, what I talk about, suppose RNN is a unit in the decoder. And, suppose we have the input, input have three tokens. I love movie. Got it? So, here, typical RNN working, I am explaining. What I am explaining? Typical RNN that already you are aware. So, three inputs, three tokens from the same input, X1, X2 and X3. I love movie, you can assume. So, what we do? We feed first token I to the RNN and it is a first token. So, we assume a random vector, hidden vector first time. And, it will process, it will give you H2 as a next hidden state. So, H2 will become input to the next life cycle. Next cycle, you can say. A next cycle will wait until we feed the next input from the data. Similarly, that process will continue. Once the complete sentence is given, it will give you output. Output means next hidden state. So, assume that it is H4. So, this H4, we call it the context vector. Agree? Now, once the complete input is given, it is understood by the RNN or encoder and the summary represented as a dense vector context vector. This vector will be given to the decoder. Decoder again, a stack of RNN. So, here a very important point. Again notice, architecture or model selection of encoder, decoder should be same. Like, if encoder have RNN, decoder should also have the RNN. But number of unit, if you are thinking, it may differ. So, it depends on the number of loop. And also, you may have a different number of hidden layer. Okay. What I want to convey. Suppose this is your decoder. Sorry. Very detailed. Suppose decoder is, suppose this is your input layer. Okay. Then you have a hidden layer H1. Then we have a next hidden layer H2. Then we have a next hidden layer H3. Suppose. One second. So, this is your encoder. It may be possible. So, this is your RNN. Then it gives the context vector. Now, we require a decoder. Decoder should have also RNN. But here, size of context vector will decide the size of input. Suppose size of context vector is 5. Agree? So, 1, 2, 3, 4, 5 is the input layer. Then it may have a different number of layer. Here, we have only two hidden layer. RNN with the encoder having the three hidden layer. Decoder is also RNN. But here, architecture of RNN may differ. Here, we have only two hidden layers. So, with this I want to convey. Don't get confused like exactly similar architecture is required at the board size. No. Families should be similar. Like family is RNN. The decoder should also have RNN. That's very important part. Okay. So, here you can see it. So, let me explain with similar example. Suppose, the input is to the encoder. The weather is nice. What it works? Typical recall the RNN working the word. First word, the will be sent to the encoder. Suppose, it is RNN. It process it and it will produce the hidden state h1. So, this is hidden state h1 here. Similarly, next word weather, then is, then nice and continuous. Once complete sentence is given, it will create output of the RNN. It is nothing but a simply again a hidden state. We call it a context vector. Then context vector will become input to the decoder. So, what happened in the decoder? So, this is okay. We got it because we are family with RNN. So, we know what is the decoder. Okay. So, decoder is a bit tricky and let me explain it's working. So, the decoder takes the context vector as an input and generate the output sequence one token at a time. It's very important, very important. It does not give the output, complete output at a time. Okay. It gives the output one by one. Suppose, input was, I am learning output is some another language. So, it will produce the output this one, then second word, then third word. Okay. So, it gives the output one by one. Okay. Ultimate decoder is a predictor. Very interesting part. So, let me explain about the decoder. Decoder. Agree? Decoder is going to give you output. Okay. Ultimate it is predicting. People are not able to understand why it is predicting. It is ultimate a classifier. Ultimate it is a multi-class classifier. Multi-class classifier. It is bit confusing. Why? Because what do you mean by the classifier? Classifier means what? It will predict, I think everybody agree, it will predict a single output at a time. Agree? Single output that is a class level. That is a class level at a time. At a time. Very important. So, if it is predicting a classifier, classifier will give single output at a time. Then, how it is generating variable length output? How it is generating variable length output? My question is clear to everybody? Very interesting question. Okay. Ultimate that's why this sentence is written. It give output one output at a time. One output at a time. So, suppose I have written. I am vivek. Okay. Desired output is what? Desired output. I want to convert this English sentence in the Hindi version. Okay. So, encoder, I don't need to explain about the encoder. You know, it is typical example of RNN. In the decoder, what happen? So, decoder, what happens? Yeah. So, decoder, what happens? This. Yeah. It will predict in one go, it may predict may. There is a one classification. Single output. Next iteration, it can predict be weak. At a time, it will predict only the single output. Single output, but different timestamp. Next time, it can predict the hmm. Agree? Again, single output. So, don't get confused with this question because interviewer try to confuse during the process. Like, decoder is a classifier and classifier has to predict one class at a time. So, how it can predict the sentence sentence having the multiple words. So, yes, it iterative process. Okay. It's kind of looping. So, in every loop, it will predict only one class. Second loop, next class. So, every word is a class here. So, let me explain. All possible tokens, all possible tokens or vocabulary, better to say, are classes. Target classes. Target. Classes. Agree? So, you may be worried about what are the classes. Because the vocabulary of that language, suppose your objective is to convert English to English from the data set, English to Hindi. So, data set must have the Hindi sentences. So, you need to consider the vocabulary. Those vocabulary, we call it a target class. So, there are many target class, maybe 20,000 target class, 20k target class. Task is not easy. Normally, you have seen the classifier having 2, 3, 5, 10 classes at the most. But here, individual token are the classes. They may have 20, 30,000 of classes. So, the process is a bit difficult. Okay. So, decoder-like look. I have already explained. The decoder is in slice with encoder context vector. It will become the input to the decoder. Okay. It will become as an input as a hidden state. Agree? There's two important words. During decoder, there are two words. Can the word order change in the encoder decoder? Yes, because you cannot say here in an example, I am BVX. So, I, you don't confuse. It doesn't convert one word at a time. It doesn't convert like that. Okay. So, input may be in any sequence. Output may be become any sequence. It is not one to one conversion. Got it? Why? Because suppose you are, you are summarizing your object, objective, just summarizing. You have given one story. One story. Have 1,000 words. Agree? Summary may be 10 words. But it is not possible to convert one word equivalent to another word. Got it? So, it just understand, then write their own way. Got it, Rahul? Gyan chan sarva. Hit and try. Answer, hit and try. Already answer such questions. There is no thumb rule in machine learning. So, two important parts in decoder, the term start and end. This is very important during training. During training, it is important. So, again, I am covering about the concept of the decoder. Decoder. During training, we have to explicitly use start as a token and end as a token. So, that decoder can understand, once it see the start, it will start giving the output. It will start giving the output. Once your decoder see the end means stop giving the output. Otherwise, it is in finite loop. Otherwise, it is in finite loop. Is it clear? So, two additional tokens we feed to the decoder, start and end. Agree? It can be any symbol. It can be anything. Just it can be any symbol. Just tell your objective is to inform the decoder. The moment it can see the start or similar symbol means start giving the output. And end means just don't give the output. Stop it now. It's a part of training. I will cover. Okay. So, yeah. So, it is here. The decoder use the hidden state. Predict the first word. Ideally predict. Okay. A very important part is... Okay. So, what theory says that... Understand here. Very important. The most important part I am discussing. Theory says that... of the decoder... Please understand here. This is output from the encoder. And this is first symbol. I am passing the start. Okay. And suppose here the input sentence is... I am Vivek. Okay. So, that was given to the encoder. Okay. Output. Correct output is... May... Vivek... Okay. So, it will give you the output. Suppose it has given the output. Vivek. Okay. So, output. Now, you know... In the decoder again... A lot of loops are there. In the second time, what we do? It creates a hidden state. ht plus 1. Because it is a RNN. So, input is ht from the previous state. Then ht plus 1. ht plus 1. What is the new output from the data set? So, theory says that output made by your model will become input. Your model will become input. Agree? So, put it has made the output next. May. So, now... As t plus 2. This will become as an input to the next cycle. May. So, same theory is written here. The decoder use the hidden state means from the previous context vector and start. Clearly, previous context vector and start or any other symbol you have to feed. Predict the first word. Maybe Hindi. Maybe Japanese. Okay. Ideally, it predicts the... If it is a correct output. Suppose, any correct output you are explaining. Je. So, like that. And produce a new hidden state. We remember the hidden new hidden state means this, this, this new hidden state. Agree? The next time stamp. I am talking about this time stamp. Next time stamp. As t plus 1 become the input. It takes the word. Practically, it is not true. But theoretically, it just predicted the previous word. The previous word like Vivek. So, Vivek become input in the next cycle. Previous hidden state as input. Then it predicts the next output. It will continue until it encounters the AND. You can do it. That is a theory says that. That is a theory says that. It works also. It is not a wrong theory. It's not a wrong. It also works. But in this case, training takes a lot of time. In this case, training takes a lot of time. A lot of time. So, what is the solution? It's not a problem. So, I will talk about it optimizing. How can we make it better? So, the concept is very important concept. Favorite question in the interview. Teacher forcing. Teacher. Forcing. What do you mean by teacher forcing? Let me explain. So, this is a concept of the teacher forcing. So, during the training. The teacher forcing is commonly used. Why? Instead of feeding the decoder on previous prediction as input. Like I was talking about here. What I say. When decoder is predicting Vivek. Then we are feeding Vivek as input to the next cycle. And if your decoder is predicting May. So, I am feeding May as input to the next cycle. So, whatever your model decoder is predicting. We should not use as input to the next cycle. Teacher says that. Teacher theory says that. Understand here. Decoder. Decoder output should not. Should not feed as input to the next cycle. Next cycle. Agree? Question is why. Question is why. So, answer is that. Because model alert is in during the training. So, model output may be wrong. Their higher chance. The model output may be wrong. During the training. It's learned slowly, slowly. Agree? So, here I want to say. Suppose the model is predicting here. Vivek. And suppose Vivek is not correct output. Because it is a classification problem. Vivek is not correct output. Okay? It is a wrong output. So, wrong thing you are feeding to the model to the next cycle. Okay? So, here the teacher training says that. Teacher training says that. Teacher training says that. Teacher training says that. Give correct output. Give correct output to the next cycle. Agree? So, correct output means from the data set. From the data set. This is the idea. I will explain with the example. So, benefit is what? It accelerate the training process. Your model learn the things more faster way. And we require less number of the back propagation. So, here let me explain with another example. Yeah, yeah, yeah. Look. Suppose sentence is given here as English sentence once upon a time. So, embedding means what? Embedding means you need to convert first input into the vector. Which vector? By using one-hot encoding, bag of word, tfidf, ngram, any, any, any, any, any, any, word2vec, anything else. So, you cannot feed the text directly to the LSTM. You know the fundamental NLP. The vectorization process is required. So, that here we call it embedding. One word at a time we need to feed to the LSTM. Since this encoder is LSTM. So, that's why two states we are maintaining HT and CT. Agree? So, it will go the sentence time to time. So, there are four terms. So, that's why four cycles will be there. Time t1, t2, t3, t4. Once output in context vector is nothing but a simply hidden state and cell state. Decoder start. So, look, it has to convert the input once upon a time to the equivalent another language. So, input, the first input to the encoder is what? Decoder is what? Understand, start or any other symbol. And context vector. It will give you the output. Suppose this output. So, typically what we say? This output will become input to the next cycle. Output is this one. This output will become input to the next cycle. Okay? So, this is the concept of using not teacher forcing. If you are not using the teacher forcing. Here, we don't require here like correct output from the data set. Because you are feeding the output of decoder as an input to the next cycle. Okay? So, yeah, it is written. Yeah. So, suppose the input is I am a student. It will go to the decoder. Decoder will give you the hidden vector. RNN hidden vector is this one. Okay? So, same thing, same thing. I have explained same thing. Okay? So, what is ht? Actually, people are talking about ht means the context vector. So, if you recall the RNN discussion, ht means what? Two input we give in RNN at a time. One ht-1 means previous hidden state input. And ht means input from your data set. Associated the weight matrix. So, here weight matrix means between the looping. Here weight matrix means input layer to the hidden layer. Whatever the activation function you want, you can use. Normally, we use the 10 h activation function. Okay? So, this ht, you are calculating in every step. Every step. Here t1, then ht plus 1, then t2, ht plus 2, like that, like that, like that. Okay? So, you can refer to our previous class where I have covered it in detail. Okay? Again, I have written any unit, either RNN, LSTM, GRE, you can use as encoder decoder. Okay? Not talk about encoder vector is completed decoder. So, in the decoder, what happened? This is the context vector given by the encoder. We will give to the decoder. And we also have output from the decoder. Another equivalent output from the decoder. It is not completely written, understand here. What it is saying? It is a bit confusing. Here, you are assuming input to the decoder is coming from the previous hidden state. So, this is the previous hidden state, ht minus 1 and corresponding weight vector. So, here you think about in decoder, we have only single input. Okay? Input from the previous state or from the encoder context vector. But it is not. We also give what? We have two options. Here, we have two options. Either decoder output will become input to the next cycle. Or you can give, if you are using the teacher forcing concept. So, correct output from the text, you can give. So, there are two options out there. Okay? Ultimate last output is a classifier. So, that's why I normally use shortness function we use. Shortness function is what? The last layer, last layer, last layer is what? Weight matrix plus hidden state. So, it will give you your class. One of the token is output at a time. Okay? So, I have one example. Yeah. So, it's again very high level understanding is given. Like, nice to meet you to the encoder, context vector, then decoder. I have another very important. Yeah. So, it is again, if unit is LSTM, you can do it in LSTM to hidden vector. We are maintaining CT, ST. So, this is also covered in the last class. Okay, okay. Okay. So, again, this is the example of, okay. So, this example of encoder. So, we are giving our objectives to convert English to Hindi. So, nice to meet you. So, complete input will be given to the LSTM. This encoder, encoder. Once the sentence is over, we have a context vector. That is made of ST and CT. That's great. Then, this is a example of without teacher forcing. So, ST and CT coming from the encoder. First input is start. Whenever your decoder see the start, it will start giving the output. So, output made by, it is again, output means softmax function. Softmax function is written here. Softmax function will give you output in one of the class. So, of say is a one of the class. So, this in the second iteration, this hidden state will become the input to the next cycle. And output made by the first time is term of say will become the input. Okay. So, this is the continue and continue offering the output and it will end it. End means we stop giving the output. Okay. So, everything is written here. What happened in here? T1, T2, T3. I have very important discussion. Yeah. So, this is a complete picture. I have one more detail. Yeah. This is very important. Okay. So, here with one example, I want to explain the complete working of encoder, decoder and softness functions. Very interesting. It's very important. It's very interesting. Everybody must focus over here. So, the question is how big models like GPT work on decoder only or if you use encoder, decoder only. Don't we need to encoder, decoder for those models? Yes. So, JGPT also inspired by the encoder, decoder, but architecture is totally different. So, in the coding class, I have asked Mayank to cover the JGPT or the transformer. You will realize it at that time. And one question is about start and end. It can be a symbol. So, start means I think confusion is suppose start is also a token. Start is also a token from the dataset. So, you can use this symbol. Whatever you're writing between it, it will give you a hint through the model start giving the output. So, any symbol you can use like add the rate s, okay? This you can use start any symbol you can want. So, that should not be a part of your dataset. Agree? It should not be a vocabulary from the dataset. Cut it. So, here you will get, you may have a lot of confusion. Give me only next 10 to 15 minutes. I will cover it. So, here look, this is the dataset. Suppose you have given and you want to convert English to the Hindi. So, English is written thing about it and Hindi version is Sochlo. Okay, it is typical Sochlo in Hindi. Next dataset is Kameen, Andarajao. Okay, so, okay, these are the dataset. So, how we are going to use this dataset for encoder-decoder training? So, what is the first step? What do you think? What should be the first step? Tell me. From the screen, just you are writing the code. What you will do? First step. Yes, encoder-decoder are the part of transformer. Yes. So, ultimate, we are covering the transformer, ultimate. Yes. First is tokenization. Correct. Correct answer. Correct answer. Correct answer. So, for the English, how many tokens are there? 1, 2, 3, 4, 5. So, 1, 2, 3, 4, 5. These all are the tokens. Agree? Similarly, for output, Hindi also applies for the tokenization. So, in this dataset, vocabulary will be so much low under AJA5. So, we have to apply the vectorization in both the place. So, input and output also. So, input is English, output is Hindi. At both the place, tokenization or vectorization is mandatory steps. Agree? Great. So, you remember, suppose one hot encoding we have adapted for vectorization. So, we have a 1, 2, 3, 4, 5. 5 vocabulary size is 5. The size of vector will be what? Automatically 5. Okay. So, think is encoded like this one. About is encoded like this one. It is encoded like this one. This frame or this table is clear to everybody. Simple vectorization. It is encoded like this one. Great. Similarly, it's an interesting part about the output Hindi, agree? So how many vector, how many tokens in the output language we have? How many tokens, 1, 2, 3, 4, 5, agree? But actually how many are here, 7, why? The size of vector at the output vector is 7, because two symbols are additional, start and end, it can be anything, agree? So it is also we need to consider as a vocabulary and will become a part of vectorization, people forget it, people forget it, agree? Okay, so now we have all that part. Is it clear to everybody? This is very simple, why two additional symbols are there? The vector size will be different. Is it clear to everybody? Okay, so it will be easy. This is the most critical slide. I will try to explain. If it is clear means you have all clarity about the encoder decoder. So suppose the sentence is what I am the first sentence I am sending, think about it. What is the first sentence? Think about it. Okay. First I have to send a vector of think. Think about this vector 1, 0, 0, 0, 0, 0, 0, 0, 0. Look the first vector, first token I am sending that is a think. Think is represented with 1, 0, 0, 0. Okay. Then the last token it, that is a 0, 0, 1, 0, 0, 0 for example we have given. So this process will over, 3 times loop will get executed and this is the context vector. Context vector is CT and ST if it is LSTM otherwise it will be HT only in the case of RNN. Okay. Up to this things are very simple because it typical RNN LSTM concept. Here things bit different. So you remember in the decoder first we have to pass the start. Agree? What is the vector of the start? This one, 1, 0, 0, 0, 0. Okay. So at the decoder we are passing first time by default start. It will go to the start then vector from the previous state. Okay. It will output of this LSTM or RNN will go to the sort max function. Okay. How many classes are there as an output you tell me? How many classes are there? You have to write how many classes are there. What I talk about the vocabulary of the output language is the class is 7. Agree? So, if you know the sort max function, if you know the sort max function, number of classes are 7, 1, 2, 3, 4, 5, 6, 7. It will predict the probability of the each class. Agree? Sort max function will give the probability of the each class. Suppose probability is 0.1, 0.3, 0.31. Assume that it is a 0.56, then 0.2, 0.1, 0.01. Agree? Which will the final class you tell me? Final class will be the final output. Highest probability. Agree? Suppose class 1 was start. This was, let me take Sojlow, okay. So this is suppose Sojlow, this is low, okay. What is the next? Andar. This is Andar, okay. So what will the output? Output of here Andar. Agree or not? Up to this moment things are agree? Pretty critical part. Great. This is happening here. This is happening here, yeah. So look, vector size. Vector size means this 1 to 7. This is, this is 1 to 7, okay. So this is what my model is predicting, okay. For first class or first word, 0.2% probability, then 30%, then 50%, then 10%, then 10% like that. Is it clear? Why predicted? Is it clear? Okay. So first, which one is the highest? You give me. You tell me. 50%. 1, 2, 3. So third class is what here? 1, 2, 3. Low. It will predict the low. Agree? It will predict the low. But what is the correct output? What is the correct output? Correct output is this one. 0, 1, 1. 0, 1. Correct output is SOCH. My model is predicting wrongly because training just started. My model is predicting this class low, but the correct class is SOCH. Agree? So I have given the correct output and predicted output both in this screen. Yeah. This is my model is predicting. This is the correct output. Agree? So what my model is predicting? It is written low. And what is the correct class? SOCH. Got it? Up to this moment things are clear. Is it? If we are not adopting the teacher forcing this low, low will be the input. Low will be the input to the next class, next iteration. Agree? And suppose you are adopting the teacher forcing. So the correct output you need to give, correct output is SOCH. Correct output will be given input to the next cycle. So that's why SOCH. Agree? That is the crux only. That is the crux only. So this process will continue until your model rate trend. At the last, we have to predict the AND. AND means stop here. So every time what your model is predicting, what is the correct output you need to compare. And you need to feed the input to the next cycle based on either you are adopting the teacher forcing or not. Okay? Any question? It is, you can say, the transformer. Here only attention concept you have to apply, it will become the transformer. So it is the backbone of BERT, transformer, attention model. So encoder decoder is the most important part. Because when we explain about the BERT, transformer, we will not go in that detail. If output after the first iteration is wrong and we have modified before giving to the next state, then it is called teacher forcing. If output after the first iteration, first iteration is wrong and we have modified. We have not modified. If the output is wrong, we are not feeding the wrong output to the next cycle. We are giving the correct output to the next cycle. That is called teacher forcing. Okay? Giving the correct output to the next cycle, we call it teacher forcing. Anything else? From my side, encoder decoder is completed. And this notes is very detailed. I will share and you can just pick it for your understanding. It was interesting or not, encoder decoder. I have gone very slowly, slowly. I have covered everything. Okay. If you have any question, please ask. Otherwise, we can end it. It's fine. Thank you so much. If we were to deliver mass beide, we can turn it down to an intermediate part from the previous test. So... Exactly. It was useful for us to take a few seconds, we are erecting. So... Check. So, yes... Thank you.