Coding a ChatGPT Like Transformer From Scratch in PyTorch

In this StatQuest we walk through the code required to code your own ChatGPT like Transformer in PyTorch and we do it one step at a time, with every little detail clearly explained.
NOTE: This StatQuest assumes that you are already familiar with the concepts behind...
Decoder-Only Transformers: • Decoder-Only Transform...
The Essential Matrix Algebra for Neural Networks: • Essential Matrix Algeb...
The Matrix Math Behind Transformers: • The matrix math behind...
You can get the code here: github.com/StatQuest/decoder_...
The full Neural Networks playlist, from the basics to AI, is here: • The Essential Main Ide...
Learn more about GiveInternet.org: giveinternet.org/StatQuest NOTE: Donations up to $30 will be matched by an Angel Investor - so a $30 donation would give $60 to the organization. DOUBLE BAM!!!
If you'd like to support StatQuest, please consider...
Patreon: / statquest
...or...
KZread Membership: / @statquest
...buying my book, a study guide, a t-shirt or hoodie, or a song from the StatQuest store...
statquest.org/statquest-store/
...or just donating to StatQuest!
paypal: www.paypal.me/statquest
venmo: @JoshStarmer
Lastly, if you want to keep up with me as I research and create new StatQuests, follow me on twitter:
/ joshuastarmer
0:00 Awesome song and introduction
1:12 Loading the modules
2:04 Creating the training dataset
6:17 Coding Position Encoding
14:09 Coding Attention
21:04 Coding a Decoder-Only Transformer
26:39 Running the model (untrained)
29:18 Training and using the model
#StatQuest #PyTorch #chatgpt

Пікірлер: 70

  • @statquest
    @statquest10 күн бұрын

    - You can get the code here: github.com/StatQuest/decoder_transformer_from_scratch - Learn more about GiveInternet.org: giveinternet.org/StatQuest NOTE: Donations up to $30 will be matched by an Angel Investor - so a $30 donation would give $60 to the organization. DOUBLE BAM!!! - The full Neural Networks playlist, from the basics to AI, is here: kzread.info/dash/bejne/daWDyMttYa_MdNo.html - Support StatQuest by buying my book The StatQuest Illustrated Guide to Machine Learning or a Study Guide or Merch!!! statquest.org/statquest-store/

  • @thebirdhasbeencharged
    @thebirdhasbeenchargedКүн бұрын

    Can't imagine the work that goes into this, writing the code, making diagrams, recording, editing and voice over, you're the goat big J.

  • @statquest

    @statquest

    Күн бұрын

    Thanks!

  • @n.h.son1902
    @n.h.son1902Күн бұрын

    You said this was going to come out at the end of May. And I’ve been waiting for this for 2 months. Finally, it’s out 😂

  • @statquest

    @statquest

    Күн бұрын

    I guess better later than never?

  • @TalkOfWang
    @TalkOfWangКүн бұрын

    It is party time! Thanks for uploading!

  • @statquest

    @statquest

    Күн бұрын

    You bet!

  • @bayoudata
    @bayoudataКүн бұрын

    Cool, learn a lot from all of your videos Josh! 🤯

  • @statquest

    @statquest

    Күн бұрын

    Thanks!

  • @muhammadikram375
    @muhammadikram375Күн бұрын

    sir you deserved millions of views on your KZread ❤❤🎉

  • @statquest

    @statquest

    Күн бұрын

    Thanks!

  • @techproductowner
    @techproductownerКүн бұрын

    You will be rememberd for next 1000 years in the history of Statistics and Data Science , You should be named as "Father of Applied Statics & Machine Learning " , Pls thumbs up if you are with me

  • @statquest

    @statquest

    Күн бұрын

    BAM! :)

  • @jahanzebnaeem2525
    @jahanzebnaeem25255 сағат бұрын

    HUGE RESPECT for all the work you put into your videos

  • @jawadmansoor6064
    @jawadmansoor6064Күн бұрын

    Finally greatly watied video arrived. Thank you.

  • @statquest

    @statquest

    Күн бұрын

    Bam! :)

  • @ShadArfMohammed
    @ShadArfMohammedКүн бұрын

    as always, wonderful content. Thanks :)

  • @statquest

    @statquest

    Күн бұрын

    Thanks again!

  • @glaudiston
    @glaudistonКүн бұрын

    Today we learned that statquest is awesome. triple BAM!

  • @statquest

    @statquest

    Күн бұрын

    Thanks!

  • @205-cssaurabhmaulekhi9
    @205-cssaurabhmaulekhi9Күн бұрын

    Thank you I was in need of this 😊

  • @statquest

    @statquest

    Күн бұрын

    Glad it was helpful!

  • @neonipun
    @neonipunКүн бұрын

    I'm gonna enjoy this one!

  • @statquest

    @statquest

    Күн бұрын

    bam! :)

  • @gvascons
    @gvasconsКүн бұрын

    Great and very didactic as usual, Josh!! Definitely going to wrap my head around this for a while and try a few tweaks! Do you plan on eventually also discussing other non-NLP topics like GANs and Diffusion Models?

  • @statquest

    @statquest

    Күн бұрын

    One day I hope to.

  • @sharjeel_mazhar
    @sharjeel_mazharКүн бұрын

    Thank you! You're the best!!!

  • @statquest

    @statquest

    Күн бұрын

    You're welcome!

  • @jorgesanabria6484
    @jorgesanabria6484Күн бұрын

    This will be awesome. I am trying to learn the math behind transformers and PyTorch so hopefully this helps give me some intuition

  • @statquest

    @statquest

    Күн бұрын

    I've got a video all about the math behind transformers here: kzread.info/dash/bejne/faScz7GDnq-nlKw.html

  • @mikinyaa
    @mikinyaa8 күн бұрын

    🎉🎉🎉thank you😊

  • @statquest

    @statquest

    8 күн бұрын

    bam! :)

  • @Mạnhfefe
    @MạnhfefeКүн бұрын

    thank you sm fr bro

  • @statquest

    @statquest

    14 сағат бұрын

    Any time!

  • @gstiebler
    @gstiebler21 сағат бұрын

    Thanks!

  • @statquest

    @statquest

    13 сағат бұрын

    TRIPLE BAM!!! Thank you for supporting StatQuest!

  • @Faisal-cl9iu
    @Faisal-cl9iuКүн бұрын

    Thanks a lot for for this free wonderful content. ❤😊

  • @statquest

    @statquest

    Күн бұрын

    Thank you!

  • @zeroonetwothree1298
    @zeroonetwothree1298Күн бұрын

    Legend.

  • @statquest

    @statquest

    Күн бұрын

    :)

  • @gustavojuantorena
    @gustavojuantorenaКүн бұрын

    🎉🎉🎉

  • @statquest

    @statquest

    Күн бұрын

    Triple 🎉!

  • @TheFunofMusic
    @TheFunofMusicКүн бұрын

    Triple Bam!!!

  • @statquest

    @statquest

    Күн бұрын

    :)

  • @suika6459
    @suika6459Күн бұрын

    amazinggg

  • @statquest

    @statquest

    14 сағат бұрын

    Thanks!

  • @nossonweissman
    @nossonweissmanКүн бұрын

    BAM!!

  • @statquest

    @statquest

    Күн бұрын

    Thanks Nosson!

  • @zendr0
    @zendr0Күн бұрын

    Bam!

  • @statquest

    @statquest

    Күн бұрын

    :)

  • @user-gh9fm2dn3t
    @user-gh9fm2dn3tКүн бұрын

    Baaaam!❤

  • @statquest

    @statquest

    Күн бұрын

    :)

  • @isaacsalzman
    @isaacsalzmanКүн бұрын

    Ya misspelled ChatGPT - Generative Pre-trained Transformer

  • @statquest

    @statquest

    Күн бұрын

    Corrected! :)

  • @user-pj3td8sq6q
    @user-pj3td8sq6qКүн бұрын

    GTP :)

  • @statquest

    @statquest

    Күн бұрын

    Corrected! ;)

  • @acasualviewer5861
    @acasualviewer586122 сағат бұрын

    I'm confused as to why the values would come from the ENCODER when computing the cross attention between the Encoder and Decoder. Shouldn't the values come from the decoder itself? So if I trained a model to translate from English to German, then wanted to switch out the German for Spanish, I'd expect the new decoder to know what to do with the output of the Encoder. But if the values are coming from the Encoder, then this wouldn't work.

  • @statquest

    @statquest

    13 сағат бұрын

    The idea is that the query in the decoder is used to determine how a potential word in the output is related to the words in the input. This done by using a query from the decoder and keys for all of the input words in the encoder. Then, once we have established how much (what percentages) a potential word in the output is related to all of the input word, we then have to determine what that percentage is of. It is of the values. And thus, the values have to come from the encoder. For more details, see: kzread.info/dash/bejne/rKyF27aEaNTbqbw.html

  • @keeperofthelight9681
    @keeperofthelight9681Күн бұрын

    Sir can you include how to make the chatbot to hold a conversation with

  • @statquest

    @statquest

    Күн бұрын

    I'll keep that in mind.

  • @yosimadsu2189
    @yosimadsu2189Күн бұрын

    🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻 Please please please show us how to train QVK Weights in detail 🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻 You showed us just a simple call to function. But we are curious how it did the math, what to train, and how it can changes values of the weights. ABC

  • @statquest

    @statquest

    14 сағат бұрын

    Every single weight and bias in a neural network is trained with backpropagation. To learn more about how this process works, see: kzread.info/dash/bejne/e4Jmus97mKyypJc.html kzread.info/dash/bejne/m62ilNydca_PmZs.html and kzread.info/dash/bejne/eX-O0bGBiKrJfNI.html

  • @yosimadsu2189

    @yosimadsu2189

    11 сағат бұрын

    @@statquest Since both QVK Weights are splitted and the calculations are passing non neural network, imho the back propagation process is quite tricky. In the other hand, the fit function did not tell the order of calculations on each nodes.

  • @ckq
    @ckqКүн бұрын

    GTP

  • @statquest

    @statquest

    Күн бұрын

    Corrected! :)

  • @mousquetaire86
    @mousquetaire86Күн бұрын

    Wish you could be Prime Minister of the United Kingdom!

  • @statquest

    @statquest

    Күн бұрын

    Ha! :)

  • @naromsky
    @naromskyКүн бұрын

    From scratch in pytorch, huh.

  • @statquest

    @statquest

    Күн бұрын

    I decided to skip doing it in assembly. ;)