Illustrated Guide to Transformers Neural Network: A step by step explanation

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

КОМЕНТАРІ • 621

  • @MinhNguyen-ro6lm
    @MinhNguyen-ro6lm 4 роки тому +680

    I must say you’ve given the best explanation on transformers that’ve saved me lots of time studying the original paper. Please produce more vids like this, I would recommend the BERT family and the GPT family as well 👏👍

    • @xtremechaos5771
      @xtremechaos5771 4 роки тому +13

      I agree. I can't seem to find a good explanation on the BERT model

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

      Sorry to be offtopic but does anyone know of a tool to log back into an instagram account??
      I stupidly forgot the password. I appreciate any tips you can offer me.

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

      @Matias Santino I really appreciate your reply. I found the site through google and Im trying it out atm.
      Takes a while so I will reply here later with my results.

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

      @Matias Santino It worked and I actually got access to my account again. I'm so happy:D
      Thank you so much you saved my account!

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

      @Ronnie Adam you are welcome :)

  • @Leon-pn6rb
    @Leon-pn6rb 4 роки тому +232

    this is great but would've loved if you could have taken a sample sentence as an input and show us how it transforms as it moves through the different parts of the transformer.
    Perhaps an idea for the next video!

    • @tunisitherapie3078
      @tunisitherapie3078 2 роки тому +5

      @The A.I. Hacker - Michael Phi please do !

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

      The video actually led me to expect this example as well! It would be highly beneficial.

  • @Random4Logic
    @Random4Logic 2 роки тому +160

    There is actually a small mistake at 12:56: The Ecnoders Output are the VALUES and keys! for the Decoders second self attention.
    So it is: Value and Key from Encoder with Query from Decoder are combined.
    from the "Self Attention is all you need" paper: "In "encoder-decoder attention" layers, the queries come from the previous decoder layer,
    and the memory keys and values come from the output of the encoder."

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

      Ik that's true but still it doesn't make sense, What's the use of the masked attentions score that we just computed in that Multi-Head attention layer since it's not carried forward

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

      yes you are right

    • @vineetsrivastava4906
      @vineetsrivastava4906 Рік тому +7

      I asked chatgpt (GPT4) for the same and look at the response:
      "Let's break down the process:
      Encoders in Transformers:
      They take the input sequence and process it through multiple layers of self-attention and feed-forward networks.
      The final output from the last encoder is used as the "Keys" (K) and "Values" (V) for the subsequent decoder.
      Decoders in Transformers:
      Decoders also have multiple layers.
      In the first self-attention mechanism of the decoder, the target sequence (for example, the partially generated translation) attends to itself. This is analogous to the self-attention in the encoder but has a slight difference. In the decoder's self-attention, future tokens are masked, so they can't be attended to. This ensures that the prediction for a particular word doesn’t depend on future words in the sequence.
      In the subsequent multi-head attention mechanism, the "Queries" (Q) come from the decoder's previous layer, and they attend to the "Keys" (K) and "Values" (V) from the encoder's output.
      This essentially means that the decoder is using the information from the encoder to help generate the next token in the sequence.
      So, your statement is correct: "Value and Key from Encoder with Query from Decoder are combined." In the Transformer's decoder, for every step in its layers, the Queries (Q) from the decoder attend to the Keys (K) and Values (V) from the encoder output."

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

      Unless it’s a decoder only transformer

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

      indeed it is like this as the dot product of the keys and querries construct the relation between the input and the already generated output if noy K and Q where from the encoder it wouldn't capture the relation between the input and already generated output

  • @sank_y
    @sank_y 4 роки тому +160

    12:56 encoder has hiddens state of key-value pairs, and in the decoder, the previous output is compressed into a query. The next output is produced by mapping this query and the set of keys and values.

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

      this is critical! I was pretty confused on this for awhile until I realized he swapped the Query and Values on accident.

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

      ah someone else realised it. this comment should be pinned ^^

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

      you are correct

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

      @@mrexnx Correct me if I'm wrong but the only reason you put the mask so it doesn't attend to "future" words in the sentence is cause of the nature of the Ebglish language..since English is written left tor ought unlike other languages. Otherwise you shouldn't have thst mask because you would need to attend to words on right or maybe left also?

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

      @@leif1075 I also thought something like that, that means, in case of Arabic, this direction of masking should not work !

  • @abail7010
    @abail7010 Рік тому +7

    I have been struggling with this architecture for an eternity now and this is the first time I really understood what's going on in this graphic. Thank you so much for this nice and clear explanation!

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

      What about the architecture made you struggle if I may ask?

  • @TheUmaragu
    @TheUmaragu 11 місяців тому +4

    A complex process- I need to listen to this multiple times to fully understand this.

  • @lakshman587
    @lakshman587 2 місяці тому +3

    Man this guy made a video on Transformers 4 years ago!!
    You are awesome!!
    Perfect explanation!!!!!
    Thanks a lot for the video!

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

    This is THE BEST transformer video I have encountered.

  • @jenishah9825
    @jenishah9825 4 роки тому +5

    This video marks an end to my search for one place explanation of Transformers. Thanks a lot for putting this up! :)

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

    This 15 minute video is the best explanation of transformers I have found.

  • @Dexter01
    @Dexter01 4 роки тому +58

    This tutorial is absolute brilliant, I have to see it again and read the illustrated guide, there are so many infos!! Thank you!!!

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

    Honestly this is the best explanation I've ever seen on transformers and attention

  • @mitch7w
    @mitch7w Рік тому +4

    Best explanation I've seen so far, thanks so much! 😃

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

    This is by far the best explanation I’ve ever seen on Transformer Networks. Very very well done

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

    This seems to be one of the best videos on Transformers

  • @valentinfontanger4962
    @valentinfontanger4962 2 роки тому +7

    I used multiple sources to learn about the transformer architecture. Regarding the decoder part, you really helped me understanding what was the input and how the different operations are performed ! Thanks a lot :)

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

    This is the best explaination on transformers anywhere on the web

  • @user-oq5ki8ml2r
    @user-oq5ki8ml2r Місяць тому

    The animation of the matrices actually helped a lot! Quality explanation video!

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

    This is literally the best explanation of Transformers I have ever seen!

  • @architkhare729
    @architkhare729 4 роки тому +12

    Wow , this was great, I have watched a no of videos on the transformer models, and they have all contributed to my understanding, but this puts everything together so neatly. Amazing, please keep making more such videos.

  • @mauriciolopes8502
    @mauriciolopes8502 Рік тому +15

    This was not just the best transformer explanation, but the best explanation in general that I've ever seen. You know what to abstract for a fluid and clear explanation. Congratulations. You should do more videos like this.

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

      check our video on transformer as well and please provide feedback on our ai4u channel

  • @BlueSky-b9o
    @BlueSky-b9o Місяць тому

    I didn't see any other video explaining this concept this beautiful and clear. Also visual animations helped so much
    Thank you 🙏🏼

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

    One word excellent , none of the explanation will match this in UA-cam ....stunned

  • @dnaphysics
    @dnaphysics Рік тому +15

    Good explanation. What boggles my mind is that this architecture can not only produce reasonable sentences, but there can be some logic going on behind the sequence of sentences as we've seen in chatGPT. It is mind-boggling that there must be some amount of deeper conceptualization represented in the embeddings too! amazing

    • @DS-nv2ni
      @DS-nv2ni Рік тому

      No, and it's not even understandable how you got to such conclusion.

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

    This transformer tutorial is more than meets the eye

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

    amazing explanation, honestly this is the first time i understand how Transformers work.

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

    This is the best explanation of transformers models, please keep going on this channel. There are lots of models still need to explain!

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

    If you only knew how relevant this would be 2 years later. Thank you!

  • @-long-
    @-long- 3 роки тому

    My first read about Micheal Phi was "Stop Installing Tensorflow using pip for performance sake!" in TowardDataScience blog (as I recall you was "Micheal Nguyen" at that time). My first impression was like "oh this guy was good at explanation". Then I read his several blogs, and now here I am. I never knew that you have a channel. You are one of the best educator I've ever known. Thanks so much.

  • @martian.07_
    @martian.07_ 2 роки тому

    Best video ever on transformers, trust me I tried others, just positional encoding is missing, but rest is gold.
    Thank you.

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

    This is by far the best explanation that I have seen.

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

    Your videos are the BEST, I understood RNNs, LSTMs, GRUs and Transformers in less than an hour.
    Thankyou.

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

    Half of it went through my head. Just beautiful. I'll watch it many more times.. That's how I know the content is gooood.

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

    Thank you so much for the step by step explanation. This is a good starting point for ML dummies like me to get a grasp on the transformer model architecture.

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

    I watched many videos, but I'm 100% sure that this video is only the best among those in explaining the transformers

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

    Best video on transformers on UA-cam, thank you so much

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

    Thanks for your explanation, very clean and well built in every argument about transformers. I was so lucky to get this video randomly on UA-cam. Good job!

  • @NockyLucky
    @NockyLucky 5 днів тому

    This is incredible! You explained transformers so well!

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

    Now i have two great heroes that explain complex concept using mindblowin visualization, first is 3b1b for complex math topics, then Michael Phi for complex machine learning architecture! Just wow ... salute sir! thank you so much!

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

    This explanation is INCREDIBLE!!!

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

    I watched a second time not for better understand the video, but to appreciate it. It is very well done and pretty clear. Thank you.

  • @theaihacker777
    @theaihacker777  4 роки тому +39

    Correction: The sine and cosine functions for the positional embedding are applied to the input embedding dimension, not the time steps! oof!
    For the readers check out the written version of an illustrated guide to Transformers here towardsdatascience.com/illustrated-guide-to-transformers-step-by-step-explanation-f74876522bc0

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

      thanx man . i was gonna ask have you written a papper for it like you did for LSTMs

    • @Cat-vs7rc
      @Cat-vs7rc 4 роки тому

      Also the positional embedding in the illustrated guide is incorrect. Its alternating between even and odd

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

      Your video is the best explanation of Transformers I have ever seen

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

      How do we actually split the queries and keys into multiple values for multiheaded attention?

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

      haha thanks micheal, I was like wtf eveything i learned is wrong at 4:18 until i scrolled down

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

    One of the most clearest explanation of Transformers I have ever seen

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

    Thank you for this amazing explanation. It really helped after an insufficient explanation from my DL lecture. The prof did not even mention that the final part is a classification over the vocabulary for an nlp task!

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

    hands down the best explation for transformer models !

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

    The best video ever for Transformer.

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

    Woah! Exquisite, It's a 15 min video but I spent over an hour taking notes and understanding. You have done a great job, keep it up. Thank you so much! Such explanations are rare. ;)

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

    This is the best video I have seen about transformers. Very articulate and concise. Great job

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

    Brooo you are seriously my god😭😭🙏🙏...thanks a lot for this video...no one... literally no one could teach me transformer and your video just got drilled into my mind...please make other videos like this for bert gpt xlnet xlm etc etc... I'm really thankful to you

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

    Thanks for the effort you put into making the animation on the slide.

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

    One of the best explanation of attention mechanism

  • @helloWorld01010
    @helloWorld01010 Рік тому +4

    You did an amazing job explaining the workflow … looked for more similar stuff… please continue … I hope you will be back to help people like me

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

    Very clean visualisation, thank you

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

    You literally solved ALL my doubts about transformers

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

    Your explanation of q k and v is the thing that finally did it for me, I get it!

  • @InturnetHaetMachine
    @InturnetHaetMachine 4 роки тому +60

    Wow, by far the best explanation. Teaching really is an art where even experts with their blind spots can be very bad at explaining (even if they know it well themselves). Well done. It's really too bad your previous video was a year ago. I really hope you make more videos explaining other deep learning papers such as Faster RCNN etc. Thanks for posting this.

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

      Yes it was through this video that I finally got my head around Transformers. Now I can read through more resources and the Paper itself

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

    Quick Q : Say at 5:58, on the left side of the slide, QKV are inputs to linear layers, but on the right it looks like positional encodings are passed to the linear layers and Q,K,V are outputs of the layers. I guess the left is just a typo and right side is correct representation. Can you please help confirm. By the way this is the best explanation i have found, you are just amazing. Thank you so much brother.

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

      You are correct. That was a typo. Positional encodings matrix are passed to each of the three linear layers to produce Q, K and V respecetively.

  • @shivanandroy5339
    @shivanandroy5339 4 роки тому +43

    That's absolute genius ! You made it so easy to understand such a mighty concept.

    • @theaihacker777
      @theaihacker777  4 роки тому +5

      Thank you. Appreciate the kind words 🙏

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

    This video clears all the doubts about transformers model. please make some more detailed videos on other topics waiting for your reply pls.

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

    Bro you need to post more nowadays, we need you!!

  • @JulianHarris
    @JulianHarris 10 місяців тому

    Amazing. I still don’t really understand how the Q K and V values are calculated but I learnt a lot more about this seminal paper than others provided - thank you! 🙏

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

    12:55 A small mistake: K and V should be encoder stack's output, and Q is the first Multi-headed Attention sublayer's output. Still, this guide is really awesome! Thanks for your effort bro!

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

    I keep coming back to this video. It's great.

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

    Thanks, I particularly liked that you went into as much detail for the decoder as for the encoder.

  • @mrowkenesser
    @mrowkenesser 2 роки тому +5

    Man thanks for this video, reading a paper for newbie is super difficult, but such explanations like you've posted for key, value and query as well as reasoning for masking is very, very helpful. I subscribed to your channel and am looking forward for new stuff.

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

    Best illustration on transformer.
    Subscribed for many more to come.

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

    Perfect explanation of the Transformes !!! Thanks.

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

    This is the best explanation on transformers. Thank you so much for the video.

  • @azharkhan-tr1wj
    @azharkhan-tr1wj 6 місяців тому

    best explanation with good visualization

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

    I am not technically skilled on ML and I understood on a high level how this work. I feel so grateful for this video 🙏

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

    Very Very thanks for this gem of an explanation.

  • @Scranny
    @Scranny 4 роки тому +8

    Wow Michael, this is a superb explanation of the transformer architecture. You even went into detail about the meaning of the Q,K,V vectors and masking concepts which were hard for me to grasp. I bounced around through 3-4 videos about the transformer arch, and for each one I claimed it was the best explanation on the topic. But your video takes the cake and explains it in half the time as the others. Thank you for sharing! Also, great job on the visuals which are on par with 3blue1brown's animations.

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

    Brilliant explanation with visually intuitive animations ! I rarely comment or subscribe to anything but this time I instantly do both after watching the video. And how coincidental it is that this was uploaded on my birthday. Hope to see more videos from you.

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

    Best Transformers Explanation I have seen thank you very much, Liked the video and Subscribed !! Keep it up :))

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

    sir u r superExplanation teacher ever

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

    感谢! Thank you so much, I've looked up all the resources on the Internet but still messed up with the mechanism. It's really a clear and detailed explanation.

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

    Very clear and clean explaining. Thanks.

  • @yashgajjar4838
    @yashgajjar4838 6 місяців тому

    Thank you so much! Very well Explained, cleared most of the doubts.

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

    Wow..one of the best videos I have watched on transformers...so simple to grasp. Please make more videos.

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

    the best explanation that I've seen. 👏

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

    Great deep dive into transformers. Helped me understand this architecture.

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

    This is one of the best introductory videos I've seen on this subject. Thank you!

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

    Favourite video on the topic! I'm reasonably knowledgeable on ML, but the other 5-10 videos I've tried so far all resulted in increased confusion. This is clear.Nice one 👍🏿

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

    Best explanation I've seen - thanks !

  • @jaceju283
    @jaceju283 10 місяців тому +1

    In 7:27, In the right the attention wieghts is a 4*4matrix while value matrix is 3*4, a 4*3 matrix for value will be more appropriate

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

    While I still have some questions, this is a pretty good explanation, I mean I actually have an idea of how this works! Gonna watch it like 2 more times.

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

    That's most clear and breif explanation about the key idea of 'transformer', especially on how transformer works and how self-attention self attended why self attention is self attention.

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

    Very deep explanation, brilliant talent to give somebody an intuition

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

    The best explanation so far. Loved the animated illustration.

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

    This was the best video i saw on attention . Thank you so much

  • @ViratSingh-nq7ok
    @ViratSingh-nq7ok 3 роки тому

    Simple and coherent explanations. Brilliant

  • @Controllerhead
    @Controllerhead Рік тому +5

    Incredible video! I hope you are doing well and find the time to make more, especially with the recent popularity explosion of AI.

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

    An outstanding video. Clarified a number of things for me.

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

    you are a legend, took me a week to understand this!

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

    Incredibly interesting. It is amazing how much processing and storage is required to achieve this.

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

    In "encoder-decoder attention" layers, the "queries "come from the previous decoder layer,
    and the" keys "and "values" come from the output of the encoder. This allows every
    position in the decoder to attend over all positions in the input sequence. This mimics the
    typical encoder-decoder attention mechanisms in sequence-to-sequence models such as
    [38, 2, 9]. -- Attention is all you need

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

    You have such a sweet and pleasant voice. Thank you, mate, for the good explanation. 😊

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

    Amazing pictorial illustration! Well done.

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

    This is the best explanation of a transfomer or any architecture I have ever watched. Highly impressive how such a complex topic is dismantled into visually appealing and understandable explanations.

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

    Thanks a lot for the intuitive introduction. But at 6:29, shall we transpose the matrix of Q, K here? In the video, multipling a 3x4 matrix and a 4x3 matrix leads to a 3x3 score matrix instead of 4x4 one