Hello guys.
So we are going to continue a discussion with respect to Transformers.
And uh, in this video we are going to discuss about the architecture.
Uh, over here on the right hand side you can see this complex architecture over here.
Okay.
And obviously, uh, you may be thinking this is very, very difficult.
Uh, but what I will do is that just directly going and seeing this architecture instead of this, I
will try to break down the entire architecture step by step.
And as I said, what all things we are going to learn, right?
That entire plan of action that I've actually created to understand the architecture of Transformers,
then we'll be understanding self-attention, positional encoding.
We'll go step by step with respect to this.
To start with a basic transformer architecture, let's consider this particular block diagram.
So this is my transformer.
Uh, this transformer will be used to solve our sequence to sequence task okay.
And in this case, the task that I am probably considering will be, uh, language translation.
Language translation.
And I will be translating, let's say, from my English sentence to my French sentence.
Okay.
So I am planning to do this particular task.
Okay.
So here when I say input that basically means I'm giving I'm going to give my English sentence.
And this is probably going to convert into a French sentence okay.
So this is what a transformer does just by seeing this block diagram.
But the main thing will be that what is inside this particular block diagram.
So let's go ahead and first of all see this.
What is inside this particular block diagram.
So if you go down here inside this block diagram that is the transformer.
You have something called as encoders and decoder.
So this also follows a encoder and decoder architecture.
Decoder architecture okay.
It follows this specific architecture.
Now what is inside this encoder.
When we say encoder is there only one encoder.
Or when we say decoder is there only one decoder?
Nothing as such.
Inside this encoder you may have multiple encoders like this okay.
Like this.
You may have multiple encoders and your text input that you are specifically giving over here in this
encoder will be going from one encoder to the other encoders okay something like this.
So this is my entire encoder over here.
So this entire encoder I have actually drawn in this particular way so that you will be able to understand.
Okay.
So here I will be having multiple encoders step by step like in the research paper.
That is attention is all you need.
Uh, let me just show you the research paper.
So this is the research paper that we will be looking at.
You know, attention is all you need.
And this particular research paper, if you probably go ahead and explore it right here specifically,
we are going to talk about this particular transformer where we'll be learning about positional encoding,
self-attention, multi-head attention, feedforward, all these things.
Right.
So uh, this what is scaled dot product attention Multi-head attention.
So based on this particular research paper, I will be probably explaining each and everything.
So as I said, uh, when we talk about an encoder.
So here I will be having multiple encoders where my information will be passed from bottom to top completely.
And then from this entire encoder, I will be passing all the information to the decoder.
Similarly, decoder will also have.
Let's just not like one block.
It may have multiple decoders.
Okay.
Like this.
It may have multiple decoders one by one okay.
What is inside this decoder?
We will get to know in some time.
Okay.
And one by one will be passing this particular decoder information on the top.
And finally we should be able to get our output okay.
So this is what exactly it is.
Okay.
And you'll be able to see that from encoder will be passing the information to the decoder also.
Okay.
And this entire uh uh architecture, when I say right in uh, in the research paper it is shown that
we are going to use six encoders.
Okay.
Six encoders.
And parallelly there will be six decoders.
Okay.
So what is there in the research paper also, uh, it's not like it needs to be six, but in the research
paper when they created the research they have used six encoders and six decoders to do this entire
task.
Okay.
Now here in the encoder I will be giving how are you.
And then in the decoder should be able to give me the French translation of this English sentence.
Okay.
Now the question arises what is inside this encoder.
We should definitely understand.
So inside this encoder, if I go to my next block diagram here, you will be able to see in a single
one encoder in a single encoder.
So inside this particular encoder, you'll be seeing that there will be one self-attention layer and
there will be one feed forward neural network layer.
Okay.
Again, try to understand this basic level of understanding.
I have drawn this particular diagram in a very simpler way.
So there will be one.
Self-attention will be understanding what exactly is the self-attention.
We'll try to see.
Like what is the exact working of this as we go ahead then Then from this self attention is connected
to the feed forward neural network.
And if I consider just a single decoder, right.
So inside a single decoder here you'll be able to see that I will be having a self-attention.
Also I'll be having a feed forward neural a feed forward neural network.
But along with this I also have an additional layer which is called as encoder decoder attention.
Okay, so we will be understanding this entirely.
Don't worry.
But we just need to understand this basic architecture what exactly it is.
Now let's go ahead and let's try to see what this self-attention actually does.
And that is what we are going to discuss in this particular video.
Okay.
Why this self-attention is basically used okay.
Now with respect to this self-attention you will be able to see that if I go down and if I still explore
more about the encoder.
So here this is my encoder okay.
This is my entire encoder.
So as I said in my encoder I have a self-attention.
And then I have a feed forward neural network.
Now let's say that I have a sentence over here.
How are you?
Okay, so this is my this is my sentence that I'm actually giving it over here.
How are you then?
This self attention.
First of all, we need to convert this all the words into vectors.
Right.
So this is my vectors.
This is basically getting converted.
And here we can use vector embeddings.
Or we can use an embedding layer whatever layer we specifically want.
Right.
Let's say here we have like embedding layer We have a embedding layer.
And this embedding layer is responsible in converting a word into vectors.
So each and every word is basically converted into a vector over here.
Now as I pass this words to the self-attention layer, this will convert this particular vector into
a different vector.
And this vector is basically called as contextual vectors.
Okay.
So let's understand the differences between this vector versus the contextual vector.
This is really important to understand okay we will we'll try to understand this in the in in this coming
section itself.
Right.
So here the self-attention is doing a very simple task.
It is taking the vector of a words, and it is converting this entire vector into another vector like
z one, z two, z three.
And this vector is nothing, but it is called as contextual vector.
There are.
Why do we say this as contextual vector?
Because this vectors are not similar to this particular vector.
But this vectors you will be seeing that it will be with respect to context of different words.
Also it will consider the context of different words also.
Okay.
And that is the reason we will probably be getting a different vectors over here, which we specifically
called it as contextual vectors.
Okay.
So I hope you got an idea about this.
Okay.
And once we get this contextual vector we send it to the feed forward neural network.
So this feed forward neural network here you can see over here I will be passing this particular vector
over here.
here, here.
Okay.
And each and every vector will be passed to this particular feed forward neural network.
And I should be able to get my output, let's say this specific output that I am, I am getting right.
I will be considering it as my another vectors.
We will discuss about it why exactly this is required.
and then this will be sent to my next encoder.
So I will just try to draw this.
Or I will just try to draw in this way.
So this will be sent to my encoder two.
So this is my encoder two.
This is my encoder one okay.
And here it is.
Be sent to my encoder two.
Then again the encoder two will be having a self-attention.
Okay.
So here it will specifically have this self-attention again.
And along with the self-attention it may also have a feed forward neural network.
So it will still keep on continuing.
So I will not draw this diagram because you know that what it will be available in my encoder two.
Okay.
Perfect.
So this will be passed over here.
So here you can see that I will rub this.
And this information is going to pass over here.
Okay.
And this is my neural network.
This is my feed forward neural network.
Network?
Neural network.
Okay.
And here you can see all this information is basically passed to this is passed to this okay.
So this is the entire basic architecture about the encoder itself.
So let me just go ahead and repeat it.
So initially I had a transformer.
The transformer is nothing but it is a combination.
It is a having this encoder and decoder architecture.
So here I will be having my encoder.
Here I will be having my decoder now inside my encoder like this encoder.
It can have multiple encoders like this 12345.
And in the even in the research paper they have used six encoders in.
Similarly in the decoder you will be seeing that I'll be having six decoders over here which are stacked
one by one.
Okay.
Then what happens inside this encoder that we have.
It has two important layers.
One is the self-attention layer.
And then you have the feed forward neural network layer.
The self-attention layer.
You know we don't we don't use LSTM or RNN like how we used to use in the encoder decoder architecture.
Instead we have this self-attention layer in the decoder.
Also, you'll be able to see that I will be having a self-attention feed forward.
But between that there'll be something called as encoder decoder attention.
Okay, then if I go forward and try to understand what exactly the self-attention does, it takes a
fixed vector right of a word and then it converts this entire word into contextual vector.
The contextual vector is very simple.
Why we are actually changing it is just giving an idea that contextual vector means what all these vectors
that is basically getting converted over here, or whatever vectors we are getting, this will also
have this will be this vectors will be defined in such a way that it will be based on the context of
other words.
Okay.
Here.
What is the difference between this vectors and this vector is that here we don't have any context.
Right here they are fixed vectors.
If you are using some word embedding layer, how how word is basically determined by a vector that will
get converted.
Right.
How R is defined that will get converted, how U is defined, that will get converted.
But by using the self-attention, the vectors that I am able to get is that how will be having a vector
considering the context of the other two words?
Okay.
Similarly, this particular vector that I'm actually getting it will be based on the context of other
words.
How and you.
Similarly, the third word right.
And that is nothing but my contextual vector.
Now why do we require contextual vector.
As I said that whenever you have a longer sentence, it definitely helps you to work.
It helps you to get a model that will provide you an amazing accuracy.
Okay.
And that is the reason we are using this, right?
And the next important thing, as I said when we were discussing in encoder decoder, we cannot pass
the words parallelly, right?
One by one we pass it, then we generate the context.
But in this case, since we are using the self-attention layer here, all the words all the words will
be passed.
Passed parallelly.
Okay.
All the words.
So at a time we are passing it.
And this makes this entire architecture scalable.
Now my next important discussion in this particular video will be that let's discuss more about self-attention.
Okay.
Now what exactly self-attention does, we will try to discuss this at a higher level.
Self-attention at a higher level.
And that is what we are going to discuss in our next video.
But I hope you got an idea.
With respect to the architecture, what exactly it is.
Uh, the first thing that we will be discussing, that how this entire vector is basically getting converted
into a contextual vector, and why contextual vector is required because it gives a proper context of
the words that I'm actually passing.
And all the words are basically passed in a parallel mode, right?
So yes, this was it.
I will see you all in the next video.
Thank you.