Building makemore Part 3: Activations & Gradients, BatchNorm

  Рет қаралды 257,065

Andrej Karpathy

Andrej Karpathy

Күн бұрын

We dive into some of the internals of MLPs with multiple layers and scrutinize the statistics of the forward pass activations, backward pass gradients, and some of the pitfalls when they are improperly scaled. We also look at the typical diagnostic tools and visualizations you'd want to use to understand the health of your deep network. We learn why training deep neural nets can be fragile and introduce the first modern innovation that made doing so much easier: Batch Normalization. Residual connections and the Adam optimizer remain notable todos for later video.
Links:
- makemore on github: github.com/karpathy/makemore
- jupyter notebook I built in this video: github.com/karpathy/nn-zero-t...
- collab notebook: colab.research.google.com/dri...
- my website: karpathy.ai
- my twitter: / karpathy
- Discord channel: / discord
Useful links:
- "Kaiming init" paper: arxiv.org/abs/1502.01852
- BatchNorm paper: arxiv.org/abs/1502.03167
- Bengio et al. 2003 MLP language model paper (pdf): www.jmlr.org/papers/volume3/b...
- Good paper illustrating some of the problems with batchnorm in practice: arxiv.org/abs/2105.07576
Exercises:
- E01: I did not get around to seeing what happens when you initialize all weights and biases to zero. Try this and train the neural net. You might think either that 1) the network trains just fine or 2) the network doesn't train at all, but actually it is 3) the network trains but only partially, and achieves a pretty bad final performance. Inspect the gradients and activations to figure out what is happening and why the network is only partially training, and what part is being trained exactly.
- E02: BatchNorm, unlike other normalization layers like LayerNorm/GroupNorm etc. has the big advantage that after training, the batchnorm gamma/beta can be "folded into" the weights of the preceeding Linear layers, effectively erasing the need to forward it at test time. Set up a small 3-layer MLP with batchnorms, train the network, then "fold" the batchnorm gamma/beta into the preceeding Linear layer's W,b by creating a new W2, b2 and erasing the batch norm. Verify that this gives the same forward pass during inference. i.e. we see that the batchnorm is there just for stabilizing the training, and can be thrown out after training is done! pretty cool.
Chapters:
00:00:00 intro
00:01:22 starter code
00:04:19 fixing the initial loss
00:12:59 fixing the saturated tanh
00:27:53 calculating the init scale: “Kaiming init”
00:40:40 batch normalization
01:03:07 batch normalization: summary
01:04:50 real example: resnet50 walkthrough
01:14:10 summary of the lecture
01:18:35 just kidding: part2: PyTorch-ifying the code
01:26:51 viz #1: forward pass activations statistics
01:30:54 viz #2: backward pass gradient statistics
01:32:07 the fully linear case of no non-linearities
01:36:15 viz #3: parameter activation and gradient statistics
01:39:55 viz #4: update:data ratio over time
01:46:04 bringing back batchnorm, looking at the visualizations
01:51:34 summary of the lecture for real this time

Пікірлер: 316
@mileseverett
@mileseverett Жыл бұрын
Andrej, as a third year PhD student this video series has given me so much more understanding of the systems I take for granted. You're doing incredible work here!
@leopetrini
@leopetrini Жыл бұрын
1:30:10 The 5/3 gain in the tanh comes for the average value of tanh^2(x) where x is distributed as a Gaussian, i.e. integrate (tanh x)^2*exp(-x^2/2)/sqrt(2*pi) from -inf to inf ~= 0.39 The square root of this value is how much the tanh squeezes the variance of the incoming variable: 0.39 ** .5 ~= 0.63 ~= 3/5 (hence 5/3 is just an approximation of the exact gain). We then multiply by the gain to keep the output variance 1.
@peace-wink
@peace-wink Жыл бұрын
Thank you : )
@MonkeyKong21
@MonkeyKong21 Жыл бұрын
i hope they're using the actual value and just writing 5/3 in the docs as slang
@Abhishekkumar-qj6hb
@Abhishekkumar-qj6hb Жыл бұрын
Hi leopetrini could you check my comment above n answer if possible
@Zoronoa01
@Zoronoa01 9 ай бұрын
Thank you for the insight!
@lennixplayzpokemon1239
@lennixplayzpokemon1239 9 ай бұрын
@leopetrini Can you explain how you calculated the integral?
@Erosis
@Erosis Жыл бұрын
This has to be the best hands-on coding tutorial for these small yet super-important deep learning fundamentals online. Absolutely great job!
@nkhuang1390
@nkhuang1390 Жыл бұрын
Every time another Andrej Karpathy video drops, its like Christmas for me. This video series has helped me to develop genuine Intuition about how neural networks work. I hope you continue to put these out, its making a massive impact on making these "black box" technologies accessible to the anyone and everyone!
@parent5x
@parent5x Жыл бұрын
Andrej you have a wonderful gift for educating others. I’m a self learner of NNs and it’s a painful process but you seriously help ease that suffering… much appreciated! Ty
@Umar-Ateeq
@Umar-Ateeq 3 ай бұрын
Great, I am also going through this same painful process. Can you suggest something that can help ease this pain?
@hetanshpatel8521
@hetanshpatel8521 2 ай бұрын
If you want to learn the theory. Try Soheil feizi . He is professor at UMD. Amazing teacher. And the course content is just top notch.
@thodorispaparrigopoulos8542
@thodorispaparrigopoulos8542 5 ай бұрын
I cannot fathom that this video only has 4k likes... He is literally explaining stuff that no one else goes through, because they simply don't know them, but they are crucial!
@adamskrodzki6152
@adamskrodzki6152 4 ай бұрын
thanks for reminding to gie a like ;)
@khuongtranhoang9197
@khuongtranhoang9197 Жыл бұрын
Turns out this should be the way to teach machine learning: a combination of theory reference and actual coding. Thank you Andrej!
@american-professor
@american-professor 5 ай бұрын
Exactly. My DL course back in 2015 had a ton of obscure math and no coding. I had no idea how to train NNs after that course. I'm rediscovering and learning a ton of stuff from this video alone, way more than from my course.
@hungrydeal6154
@hungrydeal6154 Жыл бұрын
To put BatchNorm into perspective, I am going through Geoffrey Hinton's 2012 lecture notes on bag of tricks for mini-batch descent, it was when AlexNet was first published. Hinton was saying there was no one best way for learning method/gradient descent with mini-batches. Well, here it is BatchNorm. Hinton: "Just think of how much better neural nets will work, once we've got this sorted out". We are living in that future :)
@amgad_hasan
@amgad_hasan Жыл бұрын
What did he mean by "Hinton was saying there was no one best way for learning method/gradient descent with mini-batches"? Did he mean initializing them?
@chanep1
@chanep1 11 ай бұрын
I like that not even the smallest detail is pulled out of thin air, everything is completely explained
@ragibshahriyear3682
@ragibshahriyear3682 Ай бұрын
Thank you Mr. Karpathy. I am in love with your teaching. Given how accomplished and experienced you are, you are still teaching with such grace. I dream about sitting in one of your classes and learning from you, and I hope to meet you one day. May you be blessed with good health. Lots of love and respect.
@swarajnanda5990
@swarajnanda5990 Жыл бұрын
My mind is totally blown at the detail I am getting. Feel like this is an ivy league level course, with the content so meticulously covered.
@siddharth-gandhi
@siddharth-gandhi Жыл бұрын
It's so nice to have you back on KZfaq! Thanks for teaching me Rubik's Cube back in the day and thanks for teaching us deep learning now!
@philipwoods6720
@philipwoods6720 Жыл бұрын
These videos have been incredible. Thank you so much for taking the time to make them, and I look forward to all the future ones!!!
@yonastesh7830
@yonastesh7830 Жыл бұрын
Andrej, thank you so much for your tutorials here. You've no idea how much your videos helped me. Please keep doing more videos.
@eitanporat9892
@eitanporat9892 Жыл бұрын
Thank you for delving deep into the nitty-gritty details. I appreciate the exercises!
@MLwithAmir
@MLwithAmir Жыл бұрын
These videos are so useful, Andrej thank you so much. The parts when you wrap up the lecture, and then change your mind to add more content are my fav. 😄
@hlinc2
@hlinc2 Жыл бұрын
This series is definitely the clearest presentation of ML concepts I have seen, but the teaching generalizes so well. I’ll be using this step-by-step intuition-building approach for all complicated things from now on. Nice that the approach also gives a confidence that I can understand stuff with enough time. Truly appreciate your doing this.
@project-hq
@project-hq Жыл бұрын
This whole series is absolutely amazing. Thank you very much Andrej! Being able to code along with you, improving a system as my own knowledge improves is fantastic
@rafaelsouza4575
@rafaelsouza4575 Жыл бұрын
oh man, this is top-notch content! Not sure if there are other available contents on these topics with so much clearness about its inner gears with reproducible examples. Thank you so much! You're a DL hero.
@mrmiyagi26
@mrmiyagi26 Жыл бұрын
Thank you for the deep dive into batch normalization and diagnostic approaches! Really useful to see it explained from the paper with the code.
@CuriousAnonDev
@CuriousAnonDev Жыл бұрын
I really enjoy learning and listening to people like Andrej who love what they do and aren't doing it just for money. Shared the channel with my friends ☺️ Keep up the great work Andrej!
@tsunamidestructor
@tsunamidestructor Жыл бұрын
Thank you so much for this, Andrej! Your series single-handedly revitalized my love for deep learning! Please keep this series going :)
@eustin
@eustin Жыл бұрын
it's done the same for me. i'm excitedly going through each video. it feels good to be back!
@1knmd
@1knmd Жыл бұрын
The quality of these lectures is out of the charts. This channel is a gold mine!. Andrej, thank you, thank you very much for these lectures.
@1997benjaminvh
@1997benjaminvh Жыл бұрын
This is awsome!! Thank you so much for taking the time to do this Andrej. Please keep this going, I am learning so much from you.
@vpamula1
@vpamula1 2 ай бұрын
A lot of material packed in this video; I envision understanding the mechanics of these networks to take many years, even with some prior experience.
@8eck
@8eck Жыл бұрын
Thank you Andrej, i have finally found time to go through your lectures. I have learn and understood a lot more than before, thank you.
@lkothari
@lkothari Жыл бұрын
You're a great teacher Andrej. This has been by far the most interesting ML course/training I have come across. Keep up the good work!
@ptrckqnln
@ptrckqnln Жыл бұрын
This is filling in a lot of gaps for me, thank you! I especially appreciate your insights about reading a network's behavior during training; they gave me a few epiphanies.
@IchibanKanobee
@IchibanKanobee 6 ай бұрын
These video series are exceptional. The clarity and practicality of the tutorials are unmatched by any other course. Thank you for the invaluable help for all practitioners of deep learning!
@kimiochang
@kimiochang Жыл бұрын
I completed this one today, and I just want to show Andrej my gratitude. Looking forward to the next one. Thank you very much, Andrej. Thank you!
@enchanted_swiftie
@enchanted_swiftie Жыл бұрын
So many small things, scrutinzers and how easily he has pointed them out one by one, step by step, problem to solution is just amazing. Love your work Andrej. You are amazing.
@minhajulhoque2113
@minhajulhoque2113 Жыл бұрын
The batch normalization explanation was amazing! Thank you for your hard work and concise and clear explanations.
@cktse_jp
@cktse_jp 7 ай бұрын
Your choice of visualizations as diagnostic tool is super insightful. Thanks so much for sharing your experience.
@vitorzucher435
@vitorzucher435 5 ай бұрын
You have some much depth in your knowledge, Yet, you manage to explain complex concepts with such and incredible didactics. This is someone who truly understands his field. Andrej, thank you so much and even more for the humility in how you do it so. You explain how libraries and languages like python and pytorch work and dive into the WHYs on why things are happening. This is absolute priceless.
@divelix2666
@divelix2666 Жыл бұрын
Can't even explain how impactful this video for my understanding of nns... Thank you so much!
@fhools
@fhools Жыл бұрын
These are some of the best lectures i've ever seen. I love the explaination in the first part about tanh saturation. Really trying to get the viewer to develop intuition.
@scottsun345
@scottsun345 Жыл бұрын
Thank you, Andrej, amazing content! As a beginner in deep learning and even in programing, I find most materials out there are either pure theories or pure API applications, and they rarely come this deep and detailed. Your videos cover not just the knowledge of this field, but also so many empirical insights that came from working on actual projects. Just fantastic! Please make more of these lessons!
@theusualcouple
@theusualcouple 4 ай бұрын
Thank you @Andrej for bringing this series. You are a great teacher, the way you have simplified such seemingly complex topics is valuable to all the students like me. 🙏
@ernietam6202
@ernietam6202 11 ай бұрын
Really enjoy your classes. I learnt a lot of tips for training and feel comfortable now. Will continue finishing this series.
@greatwall2003
@greatwall2003 2 ай бұрын
Great material on the intricacies of how neural networks work. Until now, I hadn't paid attention to the distribution of values entering the activation layers, and as it turns out, this is an extremely important issue. Thanks!
@juleswombat5309
@juleswombat5309 Жыл бұрын
These lectures are an awesome gift to us mortals. Such a clear explanation on the principles of neural networks. I only need to be able to afford access to massive TPU cloud compute and huge corpus, but at least I can now gain insight and understand the principles of these technologies.
@gonzaloalbornoz7279
@gonzaloalbornoz7279 Жыл бұрын
You explain very simple things that I know and always give me a new perspective on it!. Your way of transmitting knowledge is incredible.
@parent5x
@parent5x Жыл бұрын
Exactly!
@american-professor
@american-professor 5 ай бұрын
You are such a gold mine of knowledge, it's insane. I wish you were my DL professor during my PhD.
@AlexTang99
@AlexTang99 Ай бұрын
This is the most amazing video on neural network mathematics knowledge I've ever seen; thank you very much, Andrej!
@AbhishekSingh-ee2bo
@AbhishekSingh-ee2bo Жыл бұрын
Thank you.. I am a self learner and your series has been a milestone for me.
@moalimus
@moalimus Жыл бұрын
Thanks very much for this, please keep them coming, you are changing lives.
@the-hanhpham8950
@the-hanhpham8950 Жыл бұрын
Thank you so much for the time and effort put into the videos of this series. Appreciate it very much.
@styssine
@styssine 4 ай бұрын
This is a great lecture, especially the second half building intuition about diagnostics. Amazing stuff.
@AboutOliver
@AboutOliver 6 ай бұрын
You're an incredible teacher. You really have a gift. Thanks for these lectures!!!!
@rmajdodin
@rmajdodin Жыл бұрын
1:33:30 The reason the gradients of the higer layers have a bigger deviation (in the absence of tanh layer), is that you can write the whole NN as a sum of products, and it is easy to see that each weight of Layer 0 appears in 1 term, of layer 1 in 30 terms, of layer 2 in 3000 terms and so on. Therefore a small change of a weight in higer layers changes the output more.
@Lauren-qj6ti
@Lauren-qj6ti 6 ай бұрын
What an inspiration. Like others have alluded in the comments, I find Andrej's teaching so remarkably therapeutic.
@houbenbub
@houbenbub Жыл бұрын
following your lectures is a delight! Thanks for taking the time to make them :)
@vil9386
@vil9386 3 ай бұрын
I don't think any other book or blog or videos cover what Andrej has covered. Awesome insights. THANK YOU Andrej.
@sanjaybhatikar
@sanjaybhatikar 5 ай бұрын
I keep coming back to these videos again and again. Andrej is legend!
@dang242
@dang242 11 ай бұрын
Thank you for explaining everything in such detail. It makes everything much more understandable
@dengzhonghan5125
@dengzhonghan5125 11 ай бұрын
Your lecture is so amazing. Please keep updating, thanks for sharing and educating.
@lucianovidal8721
@lucianovidal8721 5 ай бұрын
The amount of useful information in this video is impressive. Thanks for such good content.
@PureArtMV
@PureArtMV 6 ай бұрын
What a gem. Thanks for the lectures, Andrej
@afbf6522
@afbf6522 Жыл бұрын
Amazing explanation about the nitty gritty details of Deep Learning, the "dark arts" of the trade.
@mPajuhaan
@mPajuhaan Жыл бұрын
Very interesting how you've described the concept of pre-tuning NN.
@peterhojnos6705
@peterhojnos6705 Жыл бұрын
Zdravím, díky, že si sa dal na tvorbu videí pre širšiu verejnosť!
@adamskrodzki6152
@adamskrodzki6152 4 ай бұрын
Amazing, knowledge that is hell hard to find in other videos and also, you have AMAZING skill in clearly explaining complex stuff.
@user-og6xo6iw9h
@user-og6xo6iw9h Жыл бұрын
love the short snippets about how to implement these tools in production.
@jeanchristophe15
@jeanchristophe15 3 ай бұрын
Thank you so much for your clear and thoughtful explanation Andrej!
@yazanmaarouf48
@yazanmaarouf48 5 ай бұрын
I have shot myself in the foot multiple times before these videos. Training big models are much more difficult than I initially anticipated. Time wasted sadly. But I have more confidence in myself thanks to these video. Thanks Andrej
@punto-y-coma7890
@punto-y-coma7890 3 ай бұрын
Awesome explanation Andrej! Than you very much for sharing your knowledge.
@ukaszlipniak2365
@ukaszlipniak2365 Жыл бұрын
I'm learning a lot. Thanks for these lectures!
@alexandermedina4950
@alexandermedina4950 Жыл бұрын
Amazing video tutorial, thank you professor Andrej.
@ShouryanNikam
@ShouryanNikam 6 ай бұрын
Thanks for making this! It's such an honor to be learning from you!
@sarai3538
@sarai3538 Жыл бұрын
Thanks for the great explanation of activation,gradient as well as histogram.
@8eck
@8eck Жыл бұрын
Wow, didn't knew that there is such content and from Karpathy himself. Thank you!
@kemalware4912
@kemalware4912 Жыл бұрын
My life is much better now because of your videos.
@JuliusSmith
@JuliusSmith 5 ай бұрын
Thanks for the fantastic download! You have changed my learning_rate in this area from 0.1 to something >1!
@tildarusso
@tildarusso Жыл бұрын
Nice to be lectured again after watching the Stanford CS231 multiple times!
@robertcowher
@robertcowher 2 ай бұрын
If you decide to make more content, a video series like this with a focus on self-driving or RL for robotics would be awesome. Not that you don't have enough going on, but that's my wish-list item :) Thanks for putting an incredibly in-depth resource out here free on the internet.
@ramboli4118
@ramboli4118 Жыл бұрын
I finally understand when Statistics come into play in machine learning. It's when you introduce the randomized weights(matrices)!
@riponsaha8320
@riponsaha8320 Жыл бұрын
This tutorial is so engaging and insightful.
@GregorUrbanekmenticorpAG
@GregorUrbanekmenticorpAG Жыл бұрын
Andrej thanks very much for your wonderful, educational videos. they are here to stay. A suggestion: wouldn't it be nice to prop up the resolution and contrast of the screen capture to make it more easy on the spectators eyes?
@hole62
@hole62 Жыл бұрын
As a former HTML nerd, I am forever indebted to the amount of precise calculations and their limits, as is expressed in this video…
@aureliencobb199
@aureliencobb199 Жыл бұрын
Thank you for the lectures. I really appreciate the effort.
@sauloviedo2677
@sauloviedo2677 Жыл бұрын
Finallyyy!!! I was nervious waiting for the new video! Thank you Andrej!!!
@ianfukushima1316
@ianfukushima1316 Жыл бұрын
Thank you! You made me happy with these lectures :)
@venkateshmunagala205
@venkateshmunagala205 Жыл бұрын
Thanks Andrej :) . It gave me a better understanding on the concept
@ayogheswaran9270
@ayogheswaran9270 Жыл бұрын
Thanks a lot Andrej!! Thank you for all your efforts❤.
@TheMato1112
@TheMato1112 Жыл бұрын
Dakujem ti Andrej, je to vazne na inej urovni :)
@mikehoops
@mikehoops Жыл бұрын
Thank you Andrej, fantastic tutorial
@billykotsos4642
@billykotsos4642 Жыл бұрын
Dives straight in and kills the presentation…. Another banger…. Can make old papers fun to go through….
@karolduracz4008
@karolduracz4008 Жыл бұрын
This is very helpful and interesting. Thank you.
@EmileAI
@EmileAI Жыл бұрын
You are an Angel sir The land of AI is blessed and the harvest is plenty. New AI warriors will rise from this Thanks
@eduardtsuranov712
@eduardtsuranov712 Жыл бұрын
incredibly cool videos, huge thanks, all the best!
@casvanmarcel
@casvanmarcel Жыл бұрын
I love these videos! Thanks for making them!
@josephngari1659
@josephngari1659 Жыл бұрын
I absolutely LOVE this series!!!!
@smithwill9952
@smithwill9952 Жыл бұрын
Better than study in University. Keep going A.K. Share your video for sure.
@aayushsmarten
@aayushsmarten Жыл бұрын
Andrej's transformation between 15:14 and 15:16 was pretty quick 😉
@thegimel
@thegimel Жыл бұрын
Your videos are absolutely wonderful, hitting the key points in a simple and concise manner. Thank you! P.S. What should be the initialization of weights if there are say 2 or more consecutive Linear layers, and only then a ReLU activation layer?
@aliyahantonio148
@aliyahantonio148 Жыл бұрын
Thank you so much bro. Sending virtual hugs. Worked like a charm ;-)
@buoyrina9669
@buoyrina9669 Жыл бұрын
Thanks. Looking forward to next videos
@user-eb8ih5mm3w
@user-eb8ih5mm3w 8 ай бұрын
very beautiful Thank you Andrej.
@chonmon
@chonmon Жыл бұрын
lol although I don't really understand what's going on here, but I'm just liking and commenting to support Andrej! Keep it up Andrej!
@escaraskaskosky9
@escaraskaskosky9 Жыл бұрын
Thanks so much for this videos; they re amazing
Building makemore Part 4: Becoming a Backprop Ninja
1:55:24
Andrej Karpathy
Рет қаралды 179 М.
Building makemore Part 2: MLP
1:15:40
Andrej Karpathy
Рет қаралды 288 М.
Increíble final 😱
00:37
Juan De Dios Pantoja 2
Рет қаралды 70 МЛН
🍟Best French Fries Homemade #cooking #shorts
00:42
BANKII
Рет қаралды 61 МЛН
СНЕЖКИ ЛЕТОМ?? #shorts
00:30
Паша Осадчий
Рет қаралды 6 МЛН
La revancha 😱
00:55
Juan De Dios Pantoja 2
Рет қаралды 49 МЛН
Building makemore Part 5: Building a WaveNet
56:22
Andrej Karpathy
Рет қаралды 162 М.
Let's build GPT: from scratch, in code, spelled out.
1:56:20
Andrej Karpathy
Рет қаралды 4,4 МЛН
But what is a convolution?
23:01
3Blue1Brown
Рет қаралды 2,5 МЛН
Let's reproduce GPT-2 (124M)
4:01:26
Andrej Karpathy
Рет қаралды 221 М.
The spelled-out intro to language modeling: building makemore
1:57:45
Andrej Karpathy
Рет қаралды 617 М.
JAX in 100 Seconds
3:24
Fireship
Рет қаралды 393 М.
The most important skill in statistics
13:35
Very Normal
Рет қаралды 302 М.
PyTorch at Tesla - Andrej Karpathy, Tesla
11:11
PyTorch
Рет қаралды 511 М.
State of GPT | BRK216HFS
42:40
Microsoft Developer
Рет қаралды 651 М.
keren sih #iphone #apple
0:16
kadangaruan
Рет қаралды 1,6 МЛН
APPLE совершила РЕВОЛЮЦИЮ!
0:39
ÉЖИ АКСЁНОВ
Рет қаралды 897 М.
ПОКУПКА ТЕЛЕФОНА С АВИТО?🤭
1:00
Корнеич
Рет қаралды 1,7 МЛН