Decoder-Only Transformers, ChatGPTs specific Transformer, Clearly Explained!!!

Поделиться
HTML-код
  • Опубликовано: 14 янв 2025

Комментарии • 389

  • @statquest
    @statquest  Год назад +5

    To learn more about Lightning: lightning.ai/
    Support StatQuest by buying my books The StatQuest Illustrated Guide to Machine Learning, The StatQuest Illustrated Guide to Neural Networks and AI, or a Study Guide or Merch!!! statquest.org/statquest-store/

  • @razodactyl
    @razodactyl Год назад +96

    Bruh. This channel is criminally underrated.

  • @ayush_stha
    @ayush_stha 9 месяцев назад +15

    This explanation is essential for anyone looking to understand how ChatGPT works. While more in-depth exploration is necessary to grasp all the intricacies fully, I believe this explanation couldn't be better. It's exactly what I needed.

    • @statquest
      @statquest  9 месяцев назад +4

      Thanks! I have a video that shows how all of these calculations are done using matrix algebra coming out soon.

  • @peerbr7849
    @peerbr7849 Год назад +22

    And I thought you'd stop at ChatGPT. Thanks for never stopping to learn and teach!

  • @who-n7e
    @who-n7e Год назад +12

    Haven't had a single stats course in over 3 years but I still keep up with this channel from time to time! Neural networks are way more complex than what I've ever had to deal with, but you manage to break down even these topics into bite size pieces...Bam!!

  • @gvlokeshkumar
    @gvlokeshkumar Год назад +4

    Quests on attention, transformer and decoder only transformer are of immeasurable value! Thank you so much! Keep the quests coming!

  • @nerisozen9029
    @nerisozen9029 6 месяцев назад +3

    Was stuck on a stupid detail about the architecture for a couple of hours. Your elaborate illustrations helped me make it clear in my mind right away! Thanks, keep going :)

    • @statquest
      @statquest  6 месяцев назад +1

      Glad it helped!

  • @byuncomics
    @byuncomics Год назад +4

    Congrats on 1 million subs statquest!! All the Love from Korea!!

    • @statquest
      @statquest  Год назад +1

      Thank you very much!!! :)

  • @Nana-wu6fb
    @Nana-wu6fb Год назад +1

    Thanks!

    • @statquest
      @statquest  Год назад

      Thank you so much for supporting StatQuest!!! BAM! :)

  • @huiwencheng4585
    @huiwencheng4585 Год назад +2

    謝謝!

    • @statquest
      @statquest  Год назад

      Thank you so much for supporting StatQuest!!! TRIPLE BAM! :)

  • @karlnikolasalcala8208
    @karlnikolasalcala8208 Год назад +2

    YOU ARE THE BEST TEACHER EVER JOSHH!! I wish you can feel the raw feeling we feel when we watch your videos

  • @spartan9729
    @spartan9729 Год назад +2

    Oh my. Thanks for the recap, it was so necessary for this video. It made the concept extremely clear.

  • @al8-.W
    @al8-.W Год назад +13

    This video is proof that repetition is prime when teaching advanced concepts. I've watched many similar videos in the past and could never get all of these numbers to finally make sense in my mind. With your previous transformer video, I was getting closer but somewhat got lost again with the QVK values. Having to this second video to watch in a row made it clearer for me what all these numbers do and why we need them.

  • @namunamu5258
    @namunamu5258 Год назад +4

    Thank you so much! It is an amazing video and I haven't seen a video teaching AI/ML techniques like this anywhere! You're talented. And my research areas span Efficient LLM (LoRA, Quantization, etc). It cannot be better if I can see those concepts

  • @jazzeuphoria
    @jazzeuphoria Год назад +2

    Bedankt

    • @statquest
      @statquest  Год назад

      HOORAY!!!! Thank you so much for supporting StatQuest! BAM! :)

  • @sidereal6296
    @sidereal6296 Год назад +2

    I just want to say you are AMAZING. Thank you so much. I would personally love to see a video on backprop to train this, or even just training an RNN since we saw multi dim training, but not training once we get the state machine / unrolling involved. Loved the whole series 🎉

    • @statquest
      @statquest  Год назад

      Thanks! I have notes for training an RNN, but the equations get big really fast. That said, it really is the exact same techniques presented in other videos, just a lot more of them.

  • @SS-ve1jm
    @SS-ve1jm 2 месяца назад +1

    Liking this video before i even start watching it as i know the content is simply brilliant!🎉

  • @aseemlimbu7672
    @aseemlimbu7672 Год назад +18

    Triple BAM ❤❤👌👌

  • @dineth9d
    @dineth9d Год назад +6

    Hey Josh, I’ve been really digging your videos! They’re not only informative and helpful for my studies, but they’re also super entertaining. In fact, you’ve played a big part in my decision to continue pursuing AI Engineering. Could you please do a video about low-rank adaptation(LoRA). I am not good with that.

    • @statquest
      @statquest  Год назад +3

      Thanks! I'll keep that in mind.

  • @EGlobalKnowledge
    @EGlobalKnowledge 4 месяца назад +1

    It summarized how GPT style of transformer architecture works and also helps us to understand how ChatGPT generates the text. Simply beautiful

  • @konstantinlevin8651
    @konstantinlevin8651 Год назад +1

    Woahh, this is actually cool. We appreciate it a lot Josh!

  • @bhaskersuri1541
    @bhaskersuri1541 Год назад +1

    This the most brilliant explanation that I have seen!!!!!! You are just awesome!!!!

  • @ID10T_6B
    @ID10T_6B 7 месяцев назад +1

    This is the only video on youtube that explains how such a complicated thing works so simply.

  • @antonindusek3725
    @antonindusek3725 Год назад +10

    Hello Josh, i am enjoying your videos as they are helping me so much with my studies as well as entertaining me. You are kinda a reason i decided to continue studying bioinformatics. Since you are covering chatGTP and stuff now, could you maybe make a video about AlphaFold architecture in the future? I understand it might not be your topic of interrest, but i would love to lear in more deeply (pun intended). Thanks either way!

    • @statquest
      @statquest  Год назад +2

      I'll keep that in mind.

  • @chihhaohuang9858
    @chihhaohuang9858 11 месяцев назад +1

    BAM... You really killed it. Thanks for your explanation.

  • @ciciparsons3651
    @ciciparsons3651 Год назад +1

    awesome, really helpful. Can't wait for another exciting episode!!

  • @colmon46
    @colmon46 Год назад +1

    Your videos are awesome! I've never thought I could learn machine learning in such an easy way. Love from china

  • @ayseguldalgic
    @ayseguldalgic 11 месяцев назад +1

    Hey Josh! You're a gift for this planet 😍 so thanks this awsome explanations..

    • @statquest
      @statquest  11 месяцев назад

      Wow, thank you!

  • @somasundar8030
    @somasundar8030 Месяц назад +1

    I immediately rushed to amazon and purchased your book. Will get it in few days.

    • @statquest
      @statquest  Месяц назад

      Hooray!!! I also have a new book coming out in early January. It's all about neural networks.

  • @asheeshmathur
    @asheeshmathur Год назад +1

    Delighted to watch one of the Most Brilliant videos. Hats off. Will join the channel tomorrow, first thing. Meanwhile do you have a one on Probability Density Function.

    • @statquest
      @statquest  Год назад +1

      All of my videos are organized on this page: statquest.org/video-index/

    • @asheeshmathur
      @asheeshmathur Год назад

      Thanks, All are good, may be I could not find a one on P Density Function. Could you please point me out that specific video.

  • @tejkiranv4056
    @tejkiranv4056 5 месяцев назад

    Wonderful Explanation! With great Visualisations!!!

  • @YumanKumar
    @YumanKumar 10 месяцев назад +1

    Amazing Explanation! Double Bam 😊👍

    • @statquest
      @statquest  10 месяцев назад

      Thank you! 😃

  • @gabip265
    @gabip265 Год назад +2

    Another great video as always! Would be amazing if you could continue with Masked Language Models such as BERT in the future!

    • @statquest
      @statquest  Год назад +2

      I'll keep that in mind.

  • @Lzyue0092youtube
    @Lzyue0092youtube 10 месяцев назад +1

    your series almost save me...love from China💥

    • @statquest
      @statquest  10 месяцев назад

      Happy to help!

  • @victorluo1049
    @victorluo1049 9 месяцев назад +1

    Hello Josh, thank you again for your video !
    I had one question concerning training the model on next token prediction:
    As training data, would you use "What is statquest " or "What is statquest awesome" ?
    What I mean by that, is when training the model by feeding it an input prompt such as "What is statquest ", do you also feed the model the word that comes after it (for calculating the loss), here "awesome" ?

    • @statquest
      @statquest  9 месяцев назад +1

      The training inputs were "What is statquest awesome", and the labels were "is statquest awesome ". I'm working on a video that goes through how to code a transformer and how to prepare the training data. Hopefully it will be out soon.

    • @victorluo1049
      @victorluo1049 9 месяцев назад +1

      @@statquest Thank you for your answer. I see that the decoder also learns to embed the input then (here, on the input , the label is "awesome").
      I'm looking forward to your next vide !

  • @josephsueke
    @josephsueke 11 месяцев назад +1

    incredible! this is such a clear explanation. thank you!

  • @danberm1755
    @danberm1755 Год назад +1

    Thanks again Josh! I noticed that many GPTs are decoder only. Thanks for clarifying!
    BTW saw that Yannic had a video on history rewrites. Probably not a topic for this channel, but still pretty cool 😁

  • @r.walid2323
    @r.walid2323 2 месяца назад

    Endless thanks to your awesome explanation. Would you mind clarifying the next confusion to me? You've mentioned that the normal transformer uses masked self-attention only during training and normal self-attention during inference, while according to other resources, including your iterations through the examples (I think you followed the masked self-attention mechanism), and in 34:20, how are we supposed to know the next tokens during training (parallel training) while we are restricted by the mask?
    and thank you in advance.

    • @statquest
      @statquest  2 месяца назад

      We only apply masking to the attention mechanism. For more details, see: ruclips.net/video/KphmOJnLAdI/видео.html

    • @r.walid2323
      @r.walid2323 2 месяца назад +2

      @@statquest Understood, thank you very much for your quick answer. bam! :)

  • @TheTimtimtimtam
    @TheTimtimtimtam Год назад +2

    Sir Josh, Thank you for making this public. May God Bless you.

  • @tzhynt
    @tzhynt 9 месяцев назад +1

    Greate explanation. It help me a lot. A million heart for u!!

  • @ruksharalam173
    @ruksharalam173 Год назад +1

    A thorough explanation 😀

    • @statquest
      @statquest  Год назад

      Thanks!

    • @ruksharalam173
      @ruksharalam173 Год назад

      @@statquest if possible, could you please do a video on structural differences between llama and GPT?

    • @statquest
      @statquest  Год назад

      @@ruksharalam173 I'll keep that in mind.

  • @gustavsnolle8424
    @gustavsnolle8424 Год назад +2

    What an awesome video and channel😁👍. Would you consider doing a video on deep q learning models? I believe everyone would benefit from a video on such a fundamental topic. Thank you for your invaluable work🤩

  • @mitch7w
    @mitch7w Год назад +1

    Thanks for the excellent explanation!

  • @brucewayne6744
    @brucewayne6744 Год назад +1

    Perfect video! Quick question, how are you drawing your lines? This line style is awesome!

    • @statquest
      @statquest  Год назад +1

      I do everything in "keynote".

  • @jugsma6676
    @jugsma6676 7 месяцев назад +1

    This is a god level YoutTube channel

  • @MM-vu6gw
    @MM-vu6gw 4 месяца назад +1

    Very good video, thank you!

  • @iProFIFA
    @iProFIFA Год назад +3

    would love to learn about bidirectional transformers next ;-)

  • @101alexmartin
    @101alexmartin Год назад +1

    Thanks for the great video, Josh. I got a question for you. What should drive my decision on which model to choose when facing a problem? In other words, how to choose between an Encoder-Decoder transformer, Decoder-only transformer or Encoder-only transformer? For instance, why ChatGPT was based on a Decoder-only model, and not on a Encoder-Decoder model or an Encoder-only model (like BERT, which has a similar application)

    • @statquest
      @statquest  Год назад +1

      Well, the reason ChatGPT choose Decoder-Only instead of Encoder-Decoder was that it was shown to work with half as many parameters. As for why they didn't use an Encoder-Only model, let me quote my friend and colleague, Sebastian Raschka: "In brief, encoder-style models are popular for learning embeddings used in classification tasks, encoder-decoder-style models are used in generative tasks where the output heavily relies on the input (for example, translation and summarization), and decoder-only models are used for other types of generative tasks including Q&A." magazine.sebastianraschka.com/p/understanding-encoder-and-decoder#:~:text=In%20brief%2C%20encoder%2Dstyle%20models,other%20types%20of%20generative%20tasks

  • @张超-o2z
    @张超-o2z 8 месяцев назад +1

    Hey, fantastic video as usual! Getting hard to find new ways to compliment, haha.
    Just one quick question since you mentioned positional encoding. When generating embeddings from GPT embedding models (e.g., text-embedding-3-large), do the embeddings contain both positional encoding layer and masked-self-attention info in the numbers?

    • @statquest
      @statquest  8 месяцев назад

      I believe it's just the word embeddings.

  • @RayGuo-bo6nr
    @RayGuo-bo6nr Год назад +1

    What a wonderful video!!! BTW, When will you publish your CD? I will buy it too😄Thanks!

  • @hoangminhan460
    @hoangminhan460 Год назад +1

    that's perfect. Can you do more lectures on LLMs? Thanks a lot.

    • @statquest
      @statquest  Год назад +1

      I'll keep that in mind.

  • @juaneshberger9567
    @juaneshberger9567 Год назад +1

    great vids, any chance you could make videos on Q-Learning, Deep Q-Learning, and other RL Topics! Keep up the good work!

  • @tamoghnamaitra9901
    @tamoghnamaitra9901 Год назад +1

    Great Video. If possible, please do a video on model fine-tuning techniques like PEFT/LoRA

    • @statquest
      @statquest  Год назад

      I'll definitely keep that in mind.

  • @leoqiao1187
    @leoqiao1187 4 месяца назад

    Hi there! Thank you for the awesome video. It is very helpful and clear. I have a question about the part around 34:10, where you are talking about how normal transformer uses Masked Self-Attention in training. I did not quite understand how that is Masked Self-Attention (i.e. looking at the tokens before). Is the Decoder still looking at the input tokens, or is it looking at the output tokens that come before it? Thank you very much!

    • @statquest
      @statquest  4 месяца назад +1

      During training we know what the output should be, but we don't let the decoder look at tokens that come after the one it is currently processing. So if the output is "my name is fred", then, when we calculate attention for "name", the decoder can't use "is" and "fred". What's going on here might be more obvious if you look at how the math is done with matrix algebra in this video: ruclips.net/video/KphmOJnLAdI/видео.html (and if you are not already familiar with matrix algebra, see: ruclips.net/video/ZTt9gsGcdDo/видео.html )

  • @AndreasAlexandrou-to5pw
    @AndreasAlexandrou-to5pw Год назад

    Had a couple of questions regarding word embedding:
    - Why do we represent each word using two values? Couldn't we just use a single one?
    - What is the purpose of the linear activation function, can't we just pass the summation straight to the embedder output?
    Thanks for the video!

    • @statquest
      @statquest  Год назад

      1) Yes. In these examples I use 2 because that's the minimum required for the math to be interesting enough to highlight what's really going on. However, usually people us 512 or more embedding values.
      2) Yes. The activation functions serve only to be a point where we do summations.

  • @jossevandekerchove1020
    @jossevandekerchove1020 Год назад +1

    Can you please make a video about GNN? You are reaaallyy good at explaining

  • @yuanyuan524
    @yuanyuan524 Год назад +1

    Thanks for clear explanation

  • @julianh7305
    @julianh7305 Год назад +1

    Hi Josh, great video, as always. I was wondering if you would also make a video about Encoder-only Transformers, like Google's BERT for instance, which can also be used for a great variety of tasks.

  • @pfever
    @pfever 8 месяцев назад +1

    I don't understand why we need the residual connections.... =''( isn't the word and position encoded values information already included in the masked self-attention values? or is most of the information lost so we need to directly add the word and position encoded values?

    • @statquest
      @statquest  8 месяцев назад

      In theory you do not need them, but in practice they make it much easier to train large neural networks since each component can focus on it's own thing without having to maintain the information that came before it.

    • @pfever
      @pfever 8 месяцев назад +1

      @@statquest Bam! Thank you!

  • @adam.phelps
    @adam.phelps 10 месяцев назад +1

    I really enjoyed this video!

  • @mohamedthasneem7327
    @mohamedthasneem7327 5 месяцев назад +1

    Thank you sir.

  • @laythherzallah3493
    @laythherzallah3493 21 день назад +1

    Thank you for a deep explanation, I have a question , does the size of output layer equal the size of the vocabulary ?

    • @statquest
      @statquest  21 день назад

      yes

    • @laythherzallah3493
      @laythherzallah3493 21 день назад

      If the size of the vocabulary is 5 million, then I need 5 million neurons at the output layer ?

    • @statquest
      @statquest  21 день назад

      @@laythherzallah3493 Yes. But usually vocabulary sizes are much smaller (in the range of tens of thousands of tokens, rather than millions).

  • @exoticcoder5365
    @exoticcoder5365 Год назад +3

    Hey Josh ! Would you mind making videos about graph neural networks ( GNN ) or graph convolutional network ( GCN ), and most importantly, the graph Attention Network ( GAT ) ? I have briefly gone over the maths these days, I already knew the matrix manipulation stuff but I think with your help, it would be much clear like your Transformer series, especially on the attention mechanism in the graph attention network ( GAT ), many Thanks 🙏🏻🙏🏻🙏🏻🙏🏻 appreciated !

    • @statquest
      @statquest  Год назад +1

      I'll keep that in mind.

    • @nahiyan8
      @nahiyan8 Год назад +1

      GNNs really only have two main elements to them, the aggregate function and the update function. The different choices of these two functions give rise to the different variants, GCN, GAT, etc.

  • @garychow7719
    @garychow7719 Год назад +1

    thank you! the video is really nice

  • @Cld136
    @Cld136 Год назад +1

    Thank you, Josh, for yet another excellent video on GPT. I find myself slightly puzzled regarding the input and output used to train the Decoder-only transformer in your example. In the normal Transformer model, the training input would be "what is statquest ," and the output would be "awesome ."
    However, in the case of the Decoder-only model, as far as I understand, the training input remains "what is statquest ," but the output becomes "what is statquest awesome ." Could you help to clarify this? If my understanding is correct, I'm wondering how the Decoder-only transformers know when to stop during inference, considering that there are two tokens within the generated response.

    • @statquest
      @statquest  Год назад +1

      Because the first is technically part of the input, we just ignore it during inference. Alternatively, you could use a different token to indicate the end of the input.

  • @cosmicfluke3718
    @cosmicfluke3718 Год назад +1

    We dont have to ask gpt to know stat quest is awesome reply from gpt BAM!!! BAM!! BAM!!

  • @dandanzhang2891
    @dandanzhang2891 Месяц назад

    Hi Josh! Thank you for your clearly explained work! You did a great job. I'm a big fan of you! I have a question about the embedding position. Here, you use two activation functions to encode the word to a vector, so that is why for the position embedding, you only use two sine and cosine to encode each word. Am I right? I found from the previous video: Transformer the foundation of chatGPT, you use four activation functions to encode each word, and later, you use four sine and cosine squiggles for the position embedding.

    • @statquest
      @statquest  Месяц назад +1

      Each word embedding value needs a positional encoding value. So the number of sine and cosine squiggles that you use depends on the number of embedding values that you create for each token.

    • @dandanzhang2891
      @dandanzhang2891 Месяц назад +1

      @@statquest Thank you for your explanation ! Have a nice day!

  • @MrHummerle
    @MrHummerle Год назад +1

    Hi there!
    Came to YT in hope you had a nice video of Rank Robustness. Would be amazing, if you wanted to make a video about it!
    Keep it up!
    Also: nice Dinosaurs!

  • @harryliu1005
    @harryliu1005 2 месяца назад +1

    Another amazing video! So the fully connect layer basically maps two dimensional vectors to 5 dimensional vectors, in this case, is the size of the vocab(collection of tokens). Is that correct?

    • @statquest
      @statquest  2 месяца назад

      Yes, exactly!

    • @harryliu1005
      @harryliu1005 2 месяца назад

      ​@@statquestGreat! I have another question: How does a fully connected neural network map vectors representing different features (dimensions) to vectors that represent the indices (dimensions) of tokens in the vocabulary?

    • @statquest
      @statquest  2 месяца назад

      @@harryliu1005 I'm not sure I understand your question since the video shows exactly how the fully connected layer works. If you're not already familiar with the basics of neural networks, check out these videos: ruclips.net/video/CqOfi41LfDw/видео.html and ruclips.net/video/83LYR-1IcjA/видео.html

  • @enchanted_swiftie
    @enchanted_swiftie Год назад +2

    You didn't use the innocent, cozy, soft bear for softmax 🧸😢 _(in most of the parts)_

    • @statquest
      @statquest  Год назад +1

      Good point!!! I think I need a smaller bear. :)

  • @lolserm
    @lolserm 7 месяцев назад

    Josh, why in min 19:34 the similarity value for "Statquest" is lower for itself than for the word "What"? It shouldn't be larger to itself as is the self-similarity?

    • @statquest
      @statquest  7 месяцев назад +1

      Unfortunately, this example is really too simple to really show off the nuance of what the actual numbers represent.

    • @lolserm
      @lolserm 7 месяцев назад

      @@statquest:( wak wak. Thanks though :)

  • @cromi4194
    @cromi4194 Год назад +3

    Wow this series culminating in a perfect explanation of GPT is the most magnificent piece of education in the history of mankind. Explaining the very climax of data science in this understandable step-by-step way so I can say that I understood it should earn you the noble prize in education! I am so grateful that you never used linear algebra in and of your videos. Professors at university don't understand that using linear algebra prevents everyone from actually understanding what is going on but only learning the formula.
    I have an exam in Data Science on Friday in a week. Can you make a quick video about spectral clustering by Wednesday evening? I will pay you 250$! :)

    • @statquest
      @statquest  Год назад +2

      Thanks! If I could make a video on anything in a week, that would be a miracle. Unfortunately, all of my videos take forever to make.

  • @random-ds
    @random-ds 10 месяцев назад

    Hello Josh! First of all thank you for this great video, as usual it's very simplified and straightforward.
    However, I have a little question. I saw your videos on transformers and this one, but every time I feel like the output is already there waiting to be embedded and then predicted. I mean that why the answer can't be "great" in stead of "awesome", what was the probablities given by the model for "great" and for "awesome" to make the final prediction. Here I gave the example of one extra word (great) but in real life it's the whole dictionary of words that can be predicted. So when generating the output, does it compute the "query" and "key" of the whole dictionary of words and then hopefully the right word has the best softmax probability?
    Thanks in advance for the clarification.

    • @statquest
      @statquest  10 месяцев назад

      no, you only calculate the queries, keys and values for the input tokens and the output as it is generated. However, in practice, instead of training on just a few phrases, we train on the entire wikipedia. As a result, the transformer can be much more expressive.

  • @terryliu3635
    @terryliu3635 9 месяцев назад

    Another great session, thank you!!! Quick question, how do we decide what numbers to use for the Keys and Values?

    • @statquest
      @statquest  9 месяцев назад +1

      For the weights? Those are determined with backpropagation: ruclips.net/video/IN2XmBhILt4/видео.html

  • @AndrewChico
    @AndrewChico 7 месяцев назад +1

    Hi Josh, excellent video. I only recently found you but your channel is amazing.
    It looks like you inadvertantly copied over the example value for "is" from the value for "what" starting around 1925 and this continues forward through the video.
    I mostly say this in case you ever adopt these notes directly into a book.

    • @statquest
      @statquest  7 месяцев назад

      Thank you! I've corrected my notes and do, in fact, plan on including it in a book soon!

  • @nivethanyogarajah1493
    @nivethanyogarajah1493 10 месяцев назад +1

    Incredible!

  • @xspydazx
    @xspydazx Год назад

    Chat gpt is still a dialog system at its heart and has many different models which it gets results from . It softmaxes the outpits acording to the intent , ... So intent detection plays a large role in the chatgpt response .. the transformers are doing major works .. its super interested despite bqttling away with vb net !

  • @daringcalf
    @daringcalf Год назад

    Great explanation! Btw, what is the manuscript that first described the original GPT?

    • @statquest
      @statquest  Год назад

      I believe it is called "Improving Language Understanding by Generative Pre-Training"

  • @shamshersingh9680
    @shamshersingh9680 8 месяцев назад

    Hi Josh, thanks a ton for making such a simple video on such a complex topic. Can you please explain what do you mean when you say "

    • @statquest
      @statquest  8 месяцев назад

      Your comment is missing the quote that you have from the video. Could you retype it in?

    • @shamshersingh9680
      @shamshersingh9680 8 месяцев назад

      @@statquest Yeah. Can you please explain - Note :- If we were training the Decoder-only transformer, then we would use the fact that we made a mistake to modify weights and biases. In contrast when we are just using the model to generate the responses, then it doesn't really matter what words come out right now.

  • @OliviaB-xu1vc
    @OliviaB-xu1vc 9 месяцев назад

    Thank you so much for another great video! I did have a question -- I'm confused about why you can train word embeddings with only linear activation functions because I thought that linear activation functions wouldn't allow you to learn non-linear patterns in the data, so why wouldn't you just not use an activation function at all in that case or use only one?

    • @statquest
      @statquest  9 месяцев назад

      For word embeddings specifically, we want to learn linear relationships among the words. This is illustrated in my video on word embeddings: ruclips.net/video/viZrOnJclY0/видео.html And, technically, when coding a linear activation function, you just omit the activation function.

  • @NJCLM
    @NJCLM Год назад +1

    Awsome as always from you !! now we only need en real tutorial with python to creat a mini transformer model. hops it is on the making as my wish list

  • @jacksonrudd3886
    @jacksonrudd3886 Год назад

    Thank you for the incredible content. Josh, quick question for you. I didn't see you mention vertically stacking the decoders in a way where the output of one decoder is the input for the next. From the 'Illustrated Transformer' page (I can't link b.c. youtube won't let me) it seems to be a core aspect of transformers. Thanks again.

    • @statquest
      @statquest  Год назад +1

      Personally, I wouldn't call that a core aspect. Unlike the ability to layer attention units, feeding the output of one decoder into the input of another in a stack, did not influence how the decoder-transformer (or even an encoder-decoder transformer) was designed. In contrast, the ability to layer attention had a big influence on how the transformer was designed.

    • @jacksonrudd3886
      @jacksonrudd3886 Год назад

      That makes sense. I just took another look at the Attention is All You Need paper, and it corroborates your explanation. Thank you.
      Request: a video on the practicalities of creating and training a production LLM. The data volume, the number of parameters and how the production architecture differs from the simplified educational model provided in this video. I think this would allow the audience to better understand what simplifications were (rightly) made for the purpose of explication.
      Also thank you so much for what you do. You are creating some of the best educational content on the internet. I am so jealous of this upcoming generation for having teachers like you :)

    • @statquest
      @statquest  Год назад

      @@jacksonrudd3886 That's right - in the Attention is all you need paper, they just mention the stacking (N=6) in passing and don't spend any time on it. And I'm planning on making the exact video that you want me to make. It may take some time, but it's in the works.

  • @kartikchaturvedi7868
    @kartikchaturvedi7868 Год назад +1

    Superrrb Awesome Fantastic video

  • @xspydazx
    @xspydazx Год назад +5

    After painstaking research on this topic, I have realized that all the information is not in the transformer itself. The transformer is just the neural network (i.e., the processor or function). The information is actually in the embedding model. The sequences are all stored there.
    When training the transformer, the word embedding model needs to be fully trained or trained with the same data. This allows the learned embeddings to fit the transformer model. Here, overfitting is beneficial as the model will be a closed model after training. The transformer can be retrained (tuned) to your specific task. The main task should be text generation corpus/tuned for question and answer.
    The learned embeddings model can actually generate data as well as the transformer neural network, making it a rich model. I also noticed that to get an effective word embeddings model, the optimization or "fine-tuning" should involve classified and labeled data. This allows clusters of similar terms to appear, as well as emotionally aware embeddings.
    The transformer is essentially performing an "anything in, anything out" operation, forcing the input and output to converge despite any logical connection between them. Given an input, it produces the desired outcome. As many similar patterns are entered, it will fit this data using the masking strategy. Transformers need to be trained as masked language models to be effective, highlighting the drawbacks of LSTM and RNN models which cannot produce the same results.
    The more distanced the output is from the input, the more layers and heads you need to deploy.

    • @iProFIFA
      @iProFIFA Год назад +1

      ... wut?

    • @xspydazx
      @xspydazx Год назад +2

      @@iProFIFA I mean the most important area of focus should be the embeddings model as this is the part which stores the data after training ... The transformer is just the neural network function. ..
      Also.... Chat gpt is primarily a "chat bot" so all inputs are fed to its Intent detection module , IE classify the user intention ... To send the query to the correct model for a response ...
      Right now the transformer is seen to be able to fit anything to anything model .... As long as you give an input and target to the model and enough samples the "function (transformer)" can fit the data to the model ... Hence the first model to train is the text generation model to give it many possibilitys to generate some form of text given a seed .... Then tune the model to your specific task , IE question and answer or the New "instruct" style model ...
      IE : for a true code generation model . The first corpus should be text books , tutorials , forum posts , mass source repos .... This will give it a massive base to generate some form of code given a seed ... Then to pass in the instruct code models , IE build a binary tree , and provide the specified code , ... It can be ANY code language .... Because the model is a transformer , later we can add another fine tune , for specific code translation ... IE csharp examples with Thier equivalent python and rust and javascript etc ... .. now this model can be retrained until it "overfits it's domain model" .... By adding general language corpus and basic questions answer modelling "after" you can now ask question and pursues project objectives ... Because this was originally trained with code model it's preferred output will be code ....
      The sealed language model outputted .. this is also the issue as all the data is in the embedding model you train it with ... So ... .
      This embedding model is the most important , as neural networks can fit any numerical data ..
      Which is the best model for word embeddings ... Fasttext , glove , skipgram ? Are there others ? What's the best optimiser for these models ? Are they interchangeable ? ..
      Finally , the transformers successes of late are due to the deployment of layers and heads .. this increase give the perception of adding dimensionality(randomness( tweakable settings (all weights and biases) but this is due to attempting to use a single model to fit all tasks ... If you have models for code gen. And others for picture gen , and others for chat gen, then others for business and local domain knowledge . Then it's better to have an intent model In front of all of these dedicated models . And direct the query to the appropriate models and take a softmax of the output to choose the correct output ! ... Again optimising the intent detector with the input and expected output and correct classification of the requested task ....
      Hopefully I explained it a bit better this time ! Lol .

    • @xspydazx
      @xspydazx Год назад +1

      Weights an biases don't take up space (they are just a few numbers in a table) it's the embed model ..

    • @aquasnippy
      @aquasnippy 7 месяцев назад +1

      @@xspydazx yo, your way of writing is really confusing and it seems like you went on a tangent so it’s hard to follow. Also you shouldn’t put spaces before commas and periods.

    • @free_thinker4958
      @free_thinker4958 2 месяца назад +1

      ​@@xspydazxare you talking about mixture of experts model in your last comment bro??

  • @rbryll2002
    @rbryll2002 4 месяца назад

    Hi Josh,
    I have a nagging question: if I understand your explanation correctly, in order to predict the next token, we first compute Keys, Queries and Values for the prompt tokens (or more generally - the prompt and the current set of completion tokens), THEN we use them to compute Masked Self-Attention and Residual Connections, which finally are passed through the fully-connected layer to predict (generate) the next token. If that is true, it would seem that in order to generate the completion, all we need to do is (conceptually) "place" the prompt at the output, compute ONLY Keys and Values for the prompt, then use these Keys and Values when computing Masked Self-Attention and Residual Connections for the completion tokens ONLY. There doesn't seem to be any need for computing Masked Self-Attention and Residual Connections for the PROMPT tokens when generating the completion tokens. In other words, ONLY the prompt Keys and Values are sufficient to provide the full context to compute the Masked Self-Attention and Residual Connections for the completion tokens.
    However, in your explanation you did go through computing Masked Self-Attention and Residual Connections for the prompt and (seemingly) re-generating the prompt tokens before moving on to generating the completion tokens. This part was unclear and appeared unnecessary to me.
    When asked, ChatGPT insists that "In decoder-only transformer models like GPT-3 or GPT-4, the prompt tokens are indeed fully processed through all the layers, INCLUDING the masked self-attention mechanisms and residual connections" and that "Keys and Values are derived from the hidden states AFTER incorporating the masked self-attention and residual connections". This would suggest that the Keys and Values are somehow computed AFTER (based on, using) Masked Self-Attention and Residual Connection and not vice versa as explained in your lecture. I understand that you might have simplified the design and/or reordered the computations for brevity/simplicity of explanation, but I would appreciate a clarification if the Masked Self-Attention and Residual Connections indeed need to be computed for the PROMPT tokens in addition to their Keys and Values in order to generate the completion tokens. Thanks so much!

    • @statquest
      @statquest  4 месяца назад +1

      Using the Queries/Keys/Values from the prompt to regenerate the prompt speeds up training.

    • @rbryll2002
      @rbryll2002 4 месяца назад

      @@statquest Thanks for your response. This makes sense for training, but in my question I was focusing on the situation during inference (I failed to state it clearly, sorry!)

    • @statquest
      @statquest  4 месяца назад +1

      @@rbryll2002 Sure, if you wanted to optimize the process, you could skip generating tokens until you get to the response.

    • @rbryll2002
      @rbryll2002 4 месяца назад

      ​@@statquest Does it mean that computing the Masked Self-Attention and Residual Connections for the PROMPT tokens is unnecessary during inference, since only their Keys and Values appear to be needed to compute the Masked Self-Attention and Residual Connections for the COMPLETION tokens? That is my (mis)understanding based on your video, but ChatGPT disagrees, stating the masked Self-Attention and Residual Connections for the PROMPT tokens are also needed when generating the COMPLETION tokens.

    • @statquest
      @statquest  4 месяца назад +1

      @@rbryll2002 I believe that it is done, and that is how it is described in the original manuscript. However, it is possible that you could skip that step. If you would like, you can play with the code to see what happens. I explain the code here: ruclips.net/video/C9QSpl5nmrY/видео.html and and you can get it to play around with here: github.com/StatQuest/decoder_transformer_from_scratch

  • @AbuDurum
    @AbuDurum Год назад

    Hey Josh. I just want to ask what software you use to make the diagrams?

    • @statquest
      @statquest  Год назад

      I use keynote and show some of my tricks here: ruclips.net/video/crLXJG-EAhk/видео.html

  • @yep9674
    @yep9674 6 месяцев назад

    I didn't really understand where the fully connected layer came from and how it is connected to the input values. It seems independent of the previous layers and somehow outputs the input words

    • @statquest
      @statquest  6 месяцев назад +1

      The illustration at 26:53 may make things easier to grasp. The residual connections are used as inputs to the fully connected layer.

  • @SaiPragnaanMarala
    @SaiPragnaanMarala 2 месяца назад

    Hey ,if we are feeding the predicted output as next input after doing the embedding,positional encoding and masked attention with previous values ,why did you take "awesome" as the next input even when the model predicted it as "what" .i didn't get you here.

    • @statquest
      @statquest  2 месяца назад

      What time point, minutes and seconds, are you asking about?

    • @SaiPragnaanMarala
      @SaiPragnaanMarala 2 месяца назад

      25:43 to 26:17 , the word "is" predicted next word as "what" but we still went on taking statquest as next word , why??

    • @statquest
      @statquest  2 месяца назад

      @@SaiPragnaanMarala Because we are still processing the input prompt. During this stage, it doesn't matter what tokens the transformer generates because they are all discarded since we already know what the prompt is. However, once we start generating a response to the prompt, then we can't discard any of the tokens that we generate and have to use them (unless we are training the model).

  • @aryamansinha2932
    @aryamansinha2932 10 месяцев назад

    hello..first off thank you for this great content
    I had a question/s
    could you give an example of how the embedding neural network is trained? i.e. what is the input and output in the embedding neural network during training? The neural networks I have worked with statements that go along the lines of "given a set of pixels determine whether the picture is a cat or not".. I do not know what the equivalent is with embedding neural networks
    and follow up question..can the embedding neural network be the same for an encoder-decoder model and a decoder-decoder model?

    • @statquest
      @statquest  10 месяцев назад +1

      1) We don't train the embedding layer separately from the rest of the transformer. So the inputs are what you see here as well as the ideal outputs that we use for training.
      2) Once trained, yes.

  • @지훈-l9j
    @지훈-l9j Год назад

    20:56 I think the value of the word "is" is miswritten it should be 1.1 , 0.9 not 2.9,1.3 it should not be same with the value of word 'what' Thank you for your videos btw ur explanation is awesome.

    • @statquest
      @statquest  Год назад

      That is correct. Sorry for the typo! :)

  • @laurentlusinchi519
    @laurentlusinchi519 10 месяцев назад

    The embedding values for "what" and "Statquest" are identical before the positional encoding. Is that not a typo ?

    • @statquest
      @statquest  10 месяцев назад

      That is correct. In order to illustrate how a decoder-only transformer worked, I had to make the model as simple as possible, and, as a result, some of the nuance in the values for the weights was lost.

  • @Modern_Nandi
    @Modern_Nandi Год назад +1

    Brilliant

  • @by301892
    @by301892 8 месяцев назад

    I feel it’s a bit misleading that it seems the tokens of the input sequence is fed in one by one, and that when you put in the first token, it predicts the second token but just ignores it, where in reality it feeds the entire sequence to predict the next target token, and on next iteration, you append the input sequence with the target token as input, and predicts the second target token, and so on. Right?

    • @statquest
      @statquest  8 месяцев назад

      At 26:28 I state that each token in the prompt is processed simultaneously.

    • @by301892
      @by301892 8 месяцев назад +1

      @@statquest gotcha. Thanks for the clarification, sensei.

  • @Primes357
    @Primes357 11 месяцев назад

    I didn't understand just one part: how are the weights to calculate Q, K and V for each word in the sentence calculated? Is it also an optimization process? If so, how is the loss function calculated?

    • @statquest
      @statquest  11 месяцев назад +1

      At 5:08 I say that all of the Weights in the entire transformer are determined using backpropagation. Specifically, we use cross entropy as the loss function. For more details about cross entropy, see: ruclips.net/video/6ArSys5qHAU/видео.html and ruclips.net/video/xBEh66V9gZo/видео.html

  • @JanKowalski-dm5vr
    @JanKowalski-dm5vr 10 месяцев назад

    Great video. Do I understand correctly DNN which is responsible for word embedding, it not only converts the token to its representation as a numeric vector, but already predicts as the next word should be returned ?

    • @statquest
      @statquest  10 месяцев назад

      In a transformer the embedding layer alone does not predict the next word because it wasn't specifically trained to do that the way a stand alone word embedding layer (like word2vec) would.

    • @JanKowalski-dm5vr
      @JanKowalski-dm5vr 10 месяцев назад

      @@statquest But if we train the whole model at the same time, then backpropagation does not change the weights of the network responsible for word embedding in such a way that they learn to predict the next word? Or don't we train this first network while learning ?

    • @statquest
      @statquest  10 месяцев назад +1

      @@JanKowalski-dm5vr It might. But the whole model, word embeddings and attention and everything, is trained to predict the next word, or translate, or whatever it's trained to do. So it's hard to say exactly what the word embedding layer will learn.

  • @shinoo5004
    @shinoo5004 Год назад

    Hi josh. Would you mind making a video for retention network?

  • @raminziaei6411
    @raminziaei6411 Год назад

    Hi Josh! I'm a little bit confused about the whole idea of generating the input first, compare it to the actual input and use to modify weights and biases in the training phase. I cannot find anywhere on the internet that it is mentioned. All I see is that the masked self attention is used on the input sequence to make contextualized version of each word and then, they are used to generate the target tokens. Nowhere can I find that generating the input sequence and compare it to the actual input is part of the process. Can you please clarify?

    • @statquest
      @statquest  Год назад

      What time point, minutes and seconds, are you asking about?

    • @raminziaei6411
      @raminziaei6411 Год назад

      @@statquest The section "generating the next word in the prompt" in this video. mins 23-27

    • @statquest
      @statquest  Год назад

      @@raminziaei6411 The idea of comparing the predicted input sequence to the known input sequence comes from the original manuscript that describes decoder only transformers, GENERATING WIKIPEDIA BY SUMMARIZING LONG SEQUENCES. They say: "Since the model is forced to predict the next token in the input as well as [the output] error signals are propagated from both input and output time-steps during training."

    • @raminziaei6411
      @raminziaei6411 Год назад

      @@statquest Thanks Josh. A related question would be "Does this only hold true if we are considering causal decoder transformers where we have masked self-attention for both input and output sequences? For prefix decoder transformers, where the input has bidirectional self-attention (full self-attention) and the output has masked self-attention, it should not hold true. Is that correct? I mean if the input has bidirectional self-attention, there is no point in predicting the next token in the input, since it has already seen the whole input sequence.

    • @statquest
      @statquest  Год назад

      @@raminziaei6411 I think "Encoder-Only Transformers", like BERT, use full self-attention on the input, even though they still can predict the input. However, I don't know for sure.

  • @mathumble6684
    @mathumble6684 Месяц назад

    It is a bit inaccurate here, it has both relation with pizza and oven, but due to its sampling, once it sampled taste after it, it will keep generating a sentence about pizza
    it can also sample cooks and complete with "cooks fast and never overdo" afterwards. thats why a temperature is here.

  • @sreerajnr689
    @sreerajnr689 8 месяцев назад

    In an encoder-decoder transformer encoder was trained in English and decoder was trained in Spanish which made it possible to do translations. But here, only English is used for both encoding and decoding which makes it impossible to convert the English encoding to Spanish output. So here, would we used both language datasets combined to train the model to enable it to do translations as well?

    • @statquest
      @statquest  8 месяцев назад +1

      Usually the tokens are just fragments of words, instead of entire words. This gives the decoder-only transformer more flexibility in terms of the vocabulary, since it can form new works it was never even trained on by combining the tokens in new ways. In this way, you can train a decoder-only transformer to translate english to spanish.

  • @BooleanDisorder
    @BooleanDisorder 11 месяцев назад

    Dude, can you make a video on state space models like Mamba? It's super interesting!