CS480/680 Lecture 19: Attention and Transformer Networks

Поділитися
Вставка
  • Опубліковано 15 тра 2024

КОМЕНТАРІ • 215

  • @pascalpoupart3507
    @pascalpoupart3507  4 роки тому +133

    The slides are posted here: cs.uwaterloo.ca/~ppoupart/teaching/cs480-spring19/schedule.html

    • @tarunluthrabk
      @tarunluthrabk 3 роки тому +7

      Hello Professor. Your explanations are amazing. Kindly pin this comment or add in description so that it is visible to everyone.

    • @majid0912
      @majid0912 Рік тому +1

      ّDear Pascal, I was wondering if you have any presentations to describe the article titled Neural Machine Translation By Jointly Learning To Align And Translate.

  • @tagrikli
    @tagrikli 3 роки тому +172

    This video just cured my depression.

    • @judgeomega
      @judgeomega 3 роки тому +22

      dont worry, im sure the next visit to a public internet forum will once again obliterate hope in humanity

    • @100vivasvan
      @100vivasvan 2 роки тому +3

      haha same here

    • @dilettante9576
      @dilettante9576 Рік тому +2

      Cured my ADHD

    • @Mrduralexx
      @Mrduralexx Рік тому +2

      This video gave me depression…

    • @UmerBashir
      @UmerBashir Рік тому +1

      @@Mrduralexx yeah its a different level of anxiety that it instills

  • @zengrz
    @zengrz 3 роки тому +193

    00:00 Attention
    31:32 Transformer
    47:15 Masked Multi-head Attention
    1:01:45 Layer normalization, Positional embedding

  • @SuperOnlyP
    @SuperOnlyP 3 роки тому +270

    Finally, Someone can explain simply what queries, keys , values are in the transformer model . Thank you Sir !!!

    • @mathisve
      @mathisve 3 роки тому +23

      Yeah, I don't understand why nobody else goes over this seemingly pretty important detail

    • @stackoverflow8260
      @stackoverflow8260 3 роки тому +14

      Wow, I was gonna ask, why didn't he explain or give an example for query, key, value in the case of a simple language translation or modelling example. Machine learning community is not very good at conveying their ideas, when you can't put stuff in rigorous mathematics at least use a lot of pictures and many examples at every possible step.

    • @andrii5054
      @andrii5054 3 роки тому +9

      I can also recommend this explanation: ua-cam.com/video/mMa2PmYJlCo/v-deo.html
      It has helped me a lot

    • @SuperOnlyP
      @SuperOnlyP 2 роки тому +1

      @@andrii5054 The video really simplify the concept. Thanks for sharing !

    • @Darkev77
      @Darkev77 2 роки тому +1

      Where was that?

  • @graceln2480
    @graceln2480 2 роки тому +3

    One of the best explanations for attention & transformers in UA-cam. Most of the other videos are junk with authors pretending to understand the concepts and just adding to the UA-cam clutter.

  • @cwtan501
    @cwtan501 3 роки тому

    By far the best I have seen to explain multiheaded attention

  • @utkarshgupta7364
    @utkarshgupta7364 3 роки тому +1

    Most awesome video on transformers one could find on youtube

  • @GotUpLateWithMoon
    @GotUpLateWithMoon 3 роки тому +15

    This is the best lecture on attention mechanism I can find! Thank you Dr. Poupart! finally all the details made sense to me.

  • @sudhirghandikota1382
    @sudhirghandikota1382 4 роки тому +54

    Thank you very much Dr. Poupart. This is the best explanation of transformers I have come across on the internet

  • @dennishuang3498
    @dennishuang3498 2 роки тому +1

    Very enjoyed your lecture, Professor Poupart! Very informative and simplified many complicated concepts. Thank you very much!

  • @drdr3496
    @drdr3496 Рік тому +9

    This is the single best video on "Attention is all you need", attention, transformers, etc. on the Internet. It's simple as that. Thanks Dr Poupart.

    • @bleacherz7503
      @bleacherz7503 Рік тому

      Why does a dot product correlate to attention?

    • @drdr3496
      @drdr3496 Рік тому +1

      @@bleacherz7503 a dot product between two vectors shows how similar they are

    • @seldan6698
      @seldan6698 Рік тому

      ​@@drdr3496 nice. Can you explain me whole query , key and value process for some example like " the cat sat on the mat". What is query, key and values for this sentence

    • @robn2497
      @robn2497 2 місяці тому

      ty

  • @sajalvasal5073
    @sajalvasal5073 3 роки тому +4

    You are a blessing, finally understood a very important concept.

  • @moustafa_shomer
    @moustafa_shomer Рік тому +3

    This is the best Transformer / Attention Explaination ever.. Thank you

  • @mi9807
    @mi9807 9 місяців тому

    One of the best videos!

  • @JMRC
    @JMRC 4 роки тому +24

    Thank you to the person asking the question at 28:49! The softmax gave it away, but I wasn't sure.

  • @AI_ML_iQ
    @AI_ML_iQ Рік тому +9

    In recent work, titled "Generalized Attention Mechanism and Relative Position for Transformer" , on transformer it is shown that different matrices for query and key are not required for attention mechanism in Transformer thus reducing number of parameters to be trained for Transformer of GPT, other language models and Transformers for images/videos.

  • @fengxie4762
    @fengxie4762 3 роки тому +5

    A great lecture! Highly recommended!

  • @aadeshingle7593
    @aadeshingle7593 8 місяців тому

    Thanks a lot Professor Poupart one of the best explanation for maths behind transformers!

  • @hamzaaliimran6441
    @hamzaaliimran6441 5 місяців тому

    one of the best and detailed lecture on attention on youtube I must say.

  • @jinyang4796
    @jinyang4796 3 роки тому

    Thank you for the clear explanation and well-illustrated examples!

  • @orhan4876
    @orhan4876 5 місяців тому

    thank you for being so thorough!

  • @momusi.9819
    @momusi.9819 4 роки тому +24

    Thank you very much, this was by far the best explanation of Transformers that I found online!

  • @TylerMosaic
    @TylerMosaic 3 роки тому +21

    wow! love the way he answers that great question at around 50:52 : “why we dont we implement the mask with hadamard product outside of the softmax?”. brilliant prof.

  • @sandipbnvnhjv
    @sandipbnvnhjv Рік тому +1

    I asked chatGPT for the best video on Attention and it brought me here

  • @underlecht
    @underlecht 3 роки тому +1

    I would call this the best explanation of attention/transformers on youtube i have found so far.

  • @ibrahimkaibi4200
    @ibrahimkaibi4200 3 роки тому

    A very interesting explanation (wonderful)

  • @richard126wfr
    @richard126wfr 2 роки тому

    The best explanation of attention mechanism I found on UA-cam is the making pizza analogue by Alfredo Canziani.

  • @benjamindeporte3806
    @benjamindeporte3806 6 місяців тому +1

    I eventually understood the Q,K,V in attention. Many thanks.

  • @giorgioregni2639
    @giorgioregni2639 2 роки тому

    Best explanation of transformer I have ever seen, thank you Dr Poupart

  • @SivaKumar-gs5ku
    @SivaKumar-gs5ku 2 роки тому

    This is the best video Internet about Transformers network

  • @vihaanrajput8082
    @vihaanrajput8082 2 роки тому

    His toturial video is my favorite timepass, specially at night,Hail to prof. Poupart

  • @brandonleesantos9383
    @brandonleesantos9383 Рік тому

    Truly fantastic wow

  • @ghostoftsushimaps4150
    @ghostoftsushimaps4150 7 місяців тому

    Bhaiji love from India. Is lecture ko araam se dekhunga

  • @weichen1
    @weichen1 4 роки тому +4

    I am not able to find a better video than this one explaining attention and transformer on the internet

  • @xhulioxhelilai9346
    @xhulioxhelilai9346 Місяць тому

    Thank you for the very comprehensive and understandable course. Being in 2024 I can say that I can understand even better and easier this course using GPT-4.

  • @Vartazian360
    @Vartazian360 5 місяців тому +3

    Little did anyone know just how groundbreaking this foundation would be for Chat GPT / GPT 4.

  • @jelenajokic9184
    @jelenajokic9184 Рік тому +1

    The simplest explanation of attention, thanks a lot for sharing, great lectures🤗!

  • @syedhasany1809
    @syedhasany1809 4 роки тому +3

    This was a great lecture, thank you.

  • @aponom84
    @aponom84 3 роки тому +1

    Nice lecture! Thanks!

  • @seminkwak
    @seminkwak 3 роки тому

    Beautiful explanations

  • @parmidagranfar4861
    @parmidagranfar4861 2 роки тому

    finallu understood what is going on . most of the videos are so simple and skipped math . i liked it

  • @goldencircle4331
    @goldencircle4331 Рік тому

    Huge thanks for putting this online.

  • @pred9990
    @pred9990 4 роки тому +1

    Cool lecture!

  • @firstnamelastname3106
    @firstnamelastname3106 3 роки тому

    thank you my man, u saved me

  • @cedricmanouan2333
    @cedricmanouan2333 3 роки тому

    very interesting and useful. Thanks Sir

  • @shifaspv2128
    @shifaspv2128 Рік тому

    Thank you so much, the brainstorming

  • @HeshamChannel
    @HeshamChannel Рік тому +1

    Very good explanation. Thanks.

  • @minhajulhoque2113
    @minhajulhoque2113 Рік тому

    Great video!

  • @benjaminw2194
    @benjaminw2194 2 роки тому

    I'm a novice and have been praying to get someone who discusses these papers. You're an answered prayer! Great lecturer.

  • @aileensengupta
    @aileensengupta Рік тому

    Big fan, big fan Sir!!
    Finally understood this!

  • @c.l.1269
    @c.l.1269 3 роки тому

    Great lecture! Thank you Professor!

  • @abhijeetnarharshettiwar6175
    @abhijeetnarharshettiwar6175 2 роки тому

    Thank you so much for great explanation, professor.

  • @faatemehch96
    @faatemehch96 2 роки тому

    thank you, the video is really useful. 👍🏻👍🏻

  • @gudepuvenkateswarlu5648
    @gudepuvenkateswarlu5648 2 роки тому

    Excellent session....Tq professor

  • @hariaakashk6161
    @hariaakashk6161 3 роки тому +1

    Great explanation sir... Thank You! Please post more such lectures and I would be the first to look at it...

  • @Antony25rages
    @Antony25rages 3 роки тому

    Thank you for this :)

  • @akashpb4183
    @akashpb4183 3 роки тому

    Beautifully explained.. things seem clear to me now .. Thanks a lot sir!

  • @fit_with_a_techie
    @fit_with_a_techie 2 роки тому

    Thank you Professor :)

  • @weiyaox6896
    @weiyaox6896 2 роки тому +1

    Best explanation

  • @MustafaQamarudDin
    @MustafaQamarudDin 4 роки тому +2

    Thank you very much. It is very detailed and captures the intuition.

    • @mathtick
      @mathtick 3 роки тому

      Could you explain what the model class looks like then? What is the capacity? What is the "unconstrained" version with higher capacity? I was full statistical learning theory style discussion in all pedalogical discussions. I don't understand how people think they understand this.
      If your life depended on it, would you feel confident in recommending one of these setups? What questions would you have to ask about the data, the model architecture, the observation process? You need worst case bounds, model complexity etc. I see none of that here.

    • @1Kapachow1
      @1Kapachow1 3 роки тому +1

      @@mathtick Well, in deep learning the theory is far behind engineering.
      When people say they understand this lecture, they don't mean worst case bounds (which I strongly doubt anyone in the world knows how to calculate for this, without adding so many relaxation assumptions which make it basically irrelevant, like convexity etc.),
      they just mean that:
      1. Engineering wise they understand how to build and use it
      2. They feel they grasp enough intuition to what is the purpose of each sub-block and why it was added.
      I don't think anyone truly "understands" much simpler models in DL than transformers, which perform in a far superior level to classical machine learning methods.
      For example, fully convolutional neural networks, trained with Adam optimizer, based on back-propagation, using BN.

    • @mathtick
      @mathtick 3 роки тому

      @@1Kapachow1 So can someone explain what the transformer is doing then in a precise way? I would accept answers that reference probability distributions and predictive goals or computation description of components like NAND gates etc.
      Also accepted would be anything related to the eigenvalues, stability, curvature etc.
      There are lots of people trying to talk about this stuff. For example arxiv.org/abs/2004.09280
      Or Vapnick.
      To be perfectly clear, I think today we tend to say there are only two things really: a) "data" i.e. observations usually dozens to millions from some process we take to be slowly changing at most and b) predicates/models/architecture/constraints ... "observations" usually less than dozens, usually manually constructure (from other experiments and observations sets perhaps). To each of these we usually have some sort of "narrative" about where each came from, a way of describing it in some way to humans.
      The second thing is what I'm getting at. "Architecture" is a model constraint. If it is just pulled from thin air without undestanding the problem, the meta-problem etc, it is quite likely that there are buried problems, secret reasons for architecture choices that are not being disclosed or realised.
      Getting better at describing these models/arch/predicates is how we progress.

  • @markphillip9950
    @markphillip9950 2 роки тому

    Great lecture.

  • @greyreynyn
    @greyreynyn 3 роки тому +1

    41:14 Question, on the output side, why isn't there an additional feed-forward layer between the masked self attention in the output and the attention to the input? And maybe more broadly what are those feed forward units doing?

  • @justinkim2973
    @justinkim2973 Рік тому

    Best video to watch on the first day of 2023

  • @yashrajwani3322
    @yashrajwani3322 3 роки тому

    great explanation

  • @sheikhjubair7133
    @sheikhjubair7133 3 роки тому

    Very clear explanation

  • @AnonTrash
    @AnonTrash Рік тому

    Beautiful.

  • @evennot
    @evennot 3 роки тому

    19:00 it's basically an exclusionary perceptron layer, isn't it? (also could be called fuzzy LUT) I'm sure it was used before for the attention emulation

  • @444haluk
    @444haluk 2 роки тому

    I heard queries, keys & values were primative concepts and counter-intuitive, but I didn't know it was THIS primative.

  • @nafeesahmad9083
    @nafeesahmad9083 2 роки тому

    Woohoo... Thank you so much

  • @aymensekhri2133
    @aymensekhri2133 Рік тому

    Thank you very much Sir!

  • @user-or7ji5hv8y
    @user-or7ji5hv8y 3 роки тому +1

    Does anyone know? Which NMT video has the previous intro to Attention the professor cites in this video? I couldn’t find his video on neural machine translation.

  • @hackercop
    @hackercop 2 роки тому

    This was a great lecture - really explained this to me thanks

  • @mohamedabbashedjazi493
    @mohamedabbashedjazi493 3 роки тому

    Softmax is computationally expensive, I wonder if this can be replaced somehow with another function to produce probabilities since Softmax is present in many places in all the blocks of the transformer network.

  • @yd42330
    @yd42330 3 роки тому +2

    Question about positional encoding.
    If we sum the Word Embedding (WE) with the Positional Encoding (PE) how does the model
    tell the difference between WE = 0.5, PE = 0.2 and WE = 0.4 and PE = 0.3 ?
    (Different words that are at different positions can yield the same value)
    Why not keep the PE separate from WE?

  • @soumyarooproy
    @soumyarooproy 3 роки тому

    Great point at 50:50 👍

  • @sienloonglee4238
    @sienloonglee4238 Рік тому

    very good video!😀

  • @chakibchemso
    @chakibchemso 11 місяців тому +1

    and thats how gpt was born my fellas

  • @opencvitk
    @opencvitk Рік тому +1

    the explanation of K,V and Q is great. unfortunately i lost him as soon as he started on multi-head. must be that the single head i possess is empty :-)

  • @evgenysavelev837
    @evgenysavelev837 3 місяці тому

    There is a better answer to the question asked at @1:04:30, regarding the positional encodings polluting word embeddings. If the positional embedding vectors are in a subspace of their own, then the addition of the positional encodings will never obfuscate the information encapsulated by word embeddings. Since the word embeddings are usually learned during network training, the network quickly learns to confine word embeddings to the subspace that is orthogonal or linearly independent to the positional encodings. So, TLDR, this is not a problem. In fact, it is advantageous, since information about position is evenly spread throughout all vector components, rather than being concentrated in a few coefficients in the head or tail. This removes a problem of having network nodes specialization, where some of the neurons become solely dedicated to deal with positional information.

  • @aricircle8040
    @aricircle8040 11 місяців тому

    Thank you very much for sharing that great lecture!
    Shouldn't it be the attention vector instead of the value? at 27:44

  • @abhishekrohra9457
    @abhishekrohra9457 2 роки тому

    Good explanation

  • @yen-linchen7398
    @yen-linchen7398 Рік тому

    Thank you!

  • @reuben3648
    @reuben3648 Рік тому

    Thank you soo much!!!

  • @prof_shixo
    @prof_shixo 3 роки тому +1

    Thanks for the nice lecture. I am still confused regarding how transformers model can replace RNNs or LSTMs for general sequence learning. The size of a sequence might be very lengthy in some applications rather than just a sentence (which can be designed to be fixed in length) so how to deal with this especially if we need to keep the complete sequence with us as there is no recurrence? If the answer is to divide the sequence, then how to link different chunks over time without a recurrence or a carry over? (Loops over time)

    • @JAKKOtutorials
      @JAKKOtutorials 3 роки тому +1

      transformers are able to "query the recurrencies", think of it as instead of repeating the operation as in RNNs you just query 'x' times a database of the possible values and its given inputs and check if it matches the requirements, and because it's not a recurrence, repetition, you can make multiple of these queries, each being a new operation, at the same time!! each operation can be resolved without interference creating new tokens, or pieces, which represent convergence points in the data universe you are travelling.
      it's a huge improvement.. confirmed by the models shown at the end of the lecture. hope this helps :)

    • @venkateshdas5422
      @venkateshdas5422 3 роки тому

      As JAKKO mentioned the transforms use the attention mechanism in a very efficient manner. The size of the sequence can be sufficiently longer than a sentence and still the attention mechanism will be able to capture the dependencies between the words at different positions. And this creates an efficient contextual representation of the sequence better than the normal input embedding vector. And this is how the complete input sequence is captured by the model without the recurrence.
      This is really a beautiful approach. (personal opinion)

  • @autripat
    @autripat 2 роки тому +2

    At 1:18:22, the professor refers to BERT and a "Decoder transformer that predicts a missing word".
    To me, BERT is a masked Encoder (not decoder).
    After all, BERT stands for bidirectional *encoder* representation from transformers.
    It's minor (and doesn't subtract from this great presentation), but can anyone comment?

    • @abdelrahmanhammad1020
      @abdelrahmanhammad1020 2 роки тому +1

      Great lecture. And I believe you are correct, it seems there is a typo here. I was questioning the same!

  • @amitvikramsingh327
    @amitvikramsingh327 3 роки тому

    Thank You.

  • @jaeyoungcheong1767
    @jaeyoungcheong1767 3 роки тому

    Clearly! Thanks

  • @kungchun9461
    @kungchun9461 3 роки тому +2

    This year should be the "tranformer year" as there a breakout in domain of CV.

  • @ephremtadesse3195
    @ephremtadesse3195 2 роки тому

    Very helpful

  • @alexanderblumin6659
    @alexanderblumin6659 2 роки тому +1

    Very intersting lecture. Something that is not totally clear on minute 46: these multihead presented intuitievely as explicit 3 various filterts as in cnn to produce 3 corresponding feature maps,but on previous part of lecture its being said that multi heads are stacked one after another to produce at first info from (word i,word j) and second pairs of that stuff i.e one is the input to another one. So how to understand it in the rightr way? Seems like on minute 46 the inputs to each of the linear are the same but on lecture part it looks like one is going after another and intuitevly the pair of pais and so one changes the ouput size.

  • @greyreynyn
    @greyreynyn 3 роки тому +2

    45:50 - For the multiple linear transformations, are we applying the same linear transform to each set of Q/K/V in a "head" ? Or does each Q/K/V get its own unique linear transform applied?

    • @knoxvoxx
      @knoxvoxx 3 роки тому +1

      Unique linear transform each time I guess.( In the original paper, under section 3.2.2 they mention that " h times with different learned linear projections to dk, dk and dv respectively")
      If we take repeat scaled dot product attention 3 times , then we will have total of 9 linear projections.

    • @ryanwhite7401
      @ryanwhite7401 2 роки тому +2

      They each get their own learned parameters.

  • @hemanthsharma5630
    @hemanthsharma5630 3 роки тому

    Saviour!!!

  • @mohamedabdo-dl9dd
    @mohamedabdo-dl9dd 2 роки тому

    thanks professor for easy explain ... can you share powerpoint with us ..

  • @greyreynyn
    @greyreynyn 3 роки тому

    46:45 - Also, the output shape is the same as the input shape right? ie, the size of the input sequence?

  • @datahacker1405
    @datahacker1405 Рік тому

    Thank you sir

  • @varungoel185
    @varungoel185 3 роки тому

    Around @29:50 mark, he first mentions that the key vectors correspond to each output word, but the slide mentions input word. Could someone please clarify this?

  • @ryandruckman999
    @ryandruckman999 4 роки тому +3

    Amazing lecture! I am learning a lot! I have some questions though:

    • @aymensayed7604
      @aymensayed7604 4 роки тому +1

      Hey Ryan, you can join one of the online events in this meetup group ;)
      www.meetup.com/Study-Of-Advanced-Natural-Language-Processing-Topics/

    • @mathtick
      @mathtick 3 роки тому

      Why do you think it is amazing? Can you explain exactly how transformers change the capacity, vc dimension, radamacher complexity, how they change the "hypothesis space" and is there an equivalent "regularization". Otherwise this is just explaining some construction with no understanding.
      I think they should always draw the "block" structure across the temporal dimension. This would make it clearer. So "Dense" connections vs attention layers etc. I don't get the sense anyone is actually trying to actually think about what this operator class looks like. Kind of disheartening.

    • @karthikvenkatesh3538
      @karthikvenkatesh3538 3 роки тому +1

      @@mathtick can you point me towards videos or readings with the transformer block across the temporal dimension?

    • @mathtick
      @mathtick 3 роки тому +1

      @@karthikvenkatesh3538 Dunno, that is kind my point. Always start with an SDE description in terms of functions and then describe the approximation class. I think it would help everyone quickly absorb things. It is easier to talk about the spectrum of the Hessian and whatever else one might try to think about abstractly when building approximation class structure manually.
      I think things like this might get into it arxiv.org/pdf/2001.08317.pdf

  • @samson6707
    @samson6707 Місяць тому

    46:11 i dont understand how there can be a concatention of the outputs followed by a linear combination. in my mind it doesnt make sense to do both. either the outputs are concatenated or added up in a linear combination but both...?

  • @diffpizza
    @diffpizza Рік тому

    Why not just a complex number for the positional embedding? The imaginary part could be keeping track of the position, and all multiplication and gradient operations should still work

  • @ryandruckman999
    @ryandruckman999 4 роки тому

    1:02:00 For the positional embedding, I am confused... It seems like the formula produces a scalar output (ie you put in a position in your sequence, you get out some sin/cos value). How does it become a vector?

    • @ryandruckman999
      @ryandruckman999 4 роки тому

      You could take the value for each dimension in your embedding and then you have a vector of values. But then it seems you'd be encoding the same information in every input, which doesn't seem helpful?

    • @venkateshdas5422
      @venkateshdas5422 3 роки тому +1

      @@ryandruckman999 Actually while doing that the values fed into the cos and sin function also takes the scalar position of the word. So each positional embedding vector will have different values which in turn captures the position / order of the sequence.
      refer this article : kazemnejad.com/blog/transformer_architecture_positional_encoding/