PyTorch Tutorial 06 - Training Pipeline: Model, Loss, and Optimizer

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 ธ.ค. 2024

ความคิดเห็น • 122

  • @amanpratapsingh1243
    @amanpratapsingh1243 4 ปีที่แล้ว +66

    You are so under- rated, this video needs to reach everyone out there who are struggling with the basics,
    as videos like this is super rare to find online. Keep up the good work :-)

    • @patloeber
      @patloeber  4 ปีที่แล้ว +1

      thank you so much! I'm happy that it is helpful :)

  • @zackinator1439
    @zackinator1439 ปีที่แล้ว +3

    I love finally finding a series that explains the absolute bare basics. So tired of tutorials that are like "Ok, so start by importing torch, then use the prebuilt DataLoader class to load a built-in dataset, then run it through a built-in model and print the result. Congrats, you did AI"

  • @jeffinkachappilly9708
    @jeffinkachappilly9708 2 ปีที่แล้ว +1

    Thank you ,so much. Surviving university because of guys like you.
    Much appreciated!!

  • @SureshKumar-tm1xy
    @SureshKumar-tm1xy 4 ปีที่แล้ว +8

    After watching one video, I subscribed to your channel and planing to finish PyTorch tutorial in 2 days. It is very helpful in understanding all the basics. Highly appreciate your efforts in making this course, keep up the good work:-)

    • @patloeber
      @patloeber  4 ปีที่แล้ว +1

      Thank you! I'm happy that it's helpful :)

    • @salmony22
      @salmony22 3 ปีที่แล้ว +1

      I did the same

  • @callforpapers_
    @callforpapers_ 4 ปีที่แล้ว +1

    Dude, this is fucking better than any tutorials I've ever seen

    • @patloeber
      @patloeber  4 ปีที่แล้ว

      Hehe thank you so much :)

  • @michelolzam
    @michelolzam 5 ปีที่แล้ว +3

    Thanks for this awesome series on Pytorch. I would definetely love to see more!

    • @patloeber
      @patloeber  5 ปีที่แล้ว

      Thank you very much!

  • @venkatesanr9455
    @venkatesanr9455 4 ปีที่แล้ว +1

    This is the good tutorial ever I have seen for PyTorch

  • @iEdp526_01
    @iEdp526_01 3 ปีที่แล้ว +4

    Holy crap, thank you for making this series. I've been struggling with this stuff for months now and was finding it nearly impossible to make headway towards really grasping it. The basics seemed impossible to get a firm hold of and apply. These videos and how you broke everything down to the most basic levels made it so much clearer. It feels like I've made more real headway in the last couple hours than in the month before that.

    • @patloeber
      @patloeber  3 ปีที่แล้ว +1

      Really happy to hear that :)

  • @harris99716
    @harris99716 10 หลายเดือนก่อน

    7:56 here, output_size = n_features is just because n_features is 1. I think you should simply write output_size = 1 to avoid confusing. For regression problem, in general, output_size is 1.

  • @haoteli2122
    @haoteli2122 4 ปีที่แล้ว +2

    I liked every single one of your video I watched so far. Thanks so much for the tutorial!

    • @patloeber
      @patloeber  4 ปีที่แล้ว

      Thank you for the feedback! I’m happy you like it :)

  • @praveenchalampalem4038
    @praveenchalampalem4038 2 ปีที่แล้ว

    Really Awesome Series of Videos with no words to express my Gratitude Patrick.!!!!!!!!

  • @ronstubed
    @ronstubed 3 ปีที่แล้ว +1

    Just what I needed and have been looking for.

    • @patloeber
      @patloeber  3 ปีที่แล้ว

      glad to hear that

  • @romp39
    @romp39 4 ปีที่แล้ว +3

    Great stuff, helped me break through some of the basics!

    • @patloeber
      @patloeber  4 ปีที่แล้ว

      glad to hear that :)

  • @DFan-uc3qz
    @DFan-uc3qz 3 ปีที่แล้ว

    Thanks very much for this tutorial! It really helps me a lot. Even though I am doing deep learning, I never went through the basics systematically step by step, and your videos make me understand things better. Keep up your amazing work!

    • @patloeber
      @patloeber  3 ปีที่แล้ว

      Great to hear! That's why I did this series :)

  • @sawradip
    @sawradip 4 ปีที่แล้ว

    Brother, you are doing wonderful work.
    Keep it up!!
    Take love!!

    • @patloeber
      @patloeber  4 ปีที่แล้ว

      Thanks! Glad you like it :)

  • @madhurabhalke2344
    @madhurabhalke2344 3 ปีที่แล้ว +1

    Damn.. This was the bestt video i had ever seen of pytorch.. Thank you so much for the amazing amazing amazing content!

  • @bhabeshmali3640
    @bhabeshmali3640 3 ปีที่แล้ว

    Wow, man!! You are awesome. Thanks for uploading this playlist. Much Love from India

    • @patloeber
      @patloeber  3 ปีที่แล้ว

      glad you like it :)

  • @СергейКириллов-ь9ю
    @СергейКириллов-ь9ю 3 ปีที่แล้ว

    You are really amazing in explaining! Solid examples of every step.

  • @bluebox6307
    @bluebox6307 4 ปีที่แล้ว +2

    I really love your series!
    Beside of that, I think I've spotted a minor mistake or rather "unpleasant" thing and just wanted to quickly mention it here for the sake of completeness.
    At 4:12, you've called "loss(Y, y_pred)". Technically it should be "loss(y_pred, Y)" as the usual notation of the loss functions of Pytorch is always "loss(y_prediction, y_target)".
    In this case, as mean squared error was used, it doesn't make any difference (because it is commutative with respect to Y and y_pred). But if you would've used another loss function, this leads to unexpected behavior or errors.

    • @patloeber
      @patloeber  3 ปีที่แล้ว

      yes, thanks for pointing this out :)

  • @hosseinnikraveshmatin110
    @hosseinnikraveshmatin110 5 ปีที่แล้ว +2

    I just wanted to thank you for your awesome codes, man I learned a lot here. please don't stop and keep going man

    • @patloeber
      @patloeber  5 ปีที่แล้ว

      Thank you very much! I am really happy that this is helpful :)

  • @salmony22
    @salmony22 3 ปีที่แล้ว

    Very interesting, awesome and step by step explanation. Thank you so much

  • @HoangNguyen-be4vy
    @HoangNguyen-be4vy 4 ปีที่แล้ว +2

    You deserve 1.000.000 subscribers

    • @patloeber
      @patloeber  4 ปีที่แล้ว

      Thank you 😊

    • @HoangNguyen-be4vy
      @HoangNguyen-be4vy 4 ปีที่แล้ว

      @@patloeber Sir, I copied your code from Github and managed to run on Jupyter, but the compiler showed up an invalid syntax from your print function
      File "", line 45
      print(f'Prediction before training: f(5) = {model(X_test).item():.3f}')
      ^
      SyntaxError: invalid syntax
      Can you fix it for me? Thanks

  • @sibasneakers6870
    @sibasneakers6870 3 ปีที่แล้ว

    Hey, Thank you so much. Your videos are helping me with my research.

    • @patloeber
      @patloeber  3 ปีที่แล้ว +1

      Happy to help!

  • @conlanrios
    @conlanrios 11 หลายเดือนก่อน

    Great vid, super clear!

  • @vishalwaghmare3130
    @vishalwaghmare3130 2 ปีที่แล้ว

    Your channel is very helpful my friend ❣️

  • @twinklepatel3907
    @twinklepatel3907 4 ปีที่แล้ว

    Thanks for the meticulous tutorial ✨ after plenty of try I find the all the fundamentas here🔥

    • @patloeber
      @patloeber  4 ปีที่แล้ว +1

      Thanks for watching :)

  • @hiranmaimohan3399
    @hiranmaimohan3399 3 ปีที่แล้ว

    Thank you so much! This playlist has helped me a lot!

    • @patloeber
      @patloeber  3 ปีที่แล้ว

      glad to hear this!

  • @arashsajjadi9141
    @arashsajjadi9141 2 ปีที่แล้ว

    Thank you very much for your excellent course. Just because I was unfamiliar with the syntax of classes but had taken a machine learning course at university, I needed to pause the videos and search for some concepts. (such as super() , __init__ and so on)

  • @dingusagar
    @dingusagar 2 ปีที่แล้ว +2

    was trying to play around with the params and inputs. initially x_train values were [1,2,3,4]. I tried to put a larger value in it. like x_train = [100,2,3,4]. After that the gradients started exploding and the loss became nan after few epochs. Any idea why this is happening.

  • @noneed_0914
    @noneed_0914 6 หลายเดือนก่อน +1

    why don't we use only w instead of w[0][0] in printing statement (timing 10:40)

    • @INGLERAJKAMALRAJENDRA
      @INGLERAJKAMALRAJENDRA 5 หลายเดือนก่อน

      We are implementing a linear regression model here, which has single parameter = w. The .item() can be only applied on tensors which have 1*1 dimensions - meaning - essentially - they are scalars. Hence, doing w.item() is also okay here. But, when we will have complex models - which won't have single parameter w or may have parameters like w1, w2, .. etc. captured by the tensor w (model.parameters() unpacked), then, in that case w.item() won't be possible. Hence, probably as a good practise, the tutor used w[0][0].item() instead of w.item()

  • @uditapatel778
    @uditapatel778 3 ปีที่แล้ว

    Thanks for this series. I am moving from tensorflow to pytorch and it's always good to start from scratch. I appreciate that you are starting from math to numpy to pytorch. If there was another step to move to pytorch lightning that would be great ! (I think I can figure that out myself for now). Thanks again ! :)

    • @patloeber
      @patloeber  3 ปีที่แล้ว

      Glad you like it!

  • @hector1502
    @hector1502 4 ปีที่แล้ว +2

    Thank you again for your excellent videos. To make this experiment more similar to the previous video, I think that the bias shouldn't be optimized: model = nn.Linear(input_size, 1, bias = False)

    • @patloeber
      @patloeber  4 ปีที่แล้ว

      You are correct! I see you are very familiar with PyTorch :)

    • @hector1502
      @hector1502 4 ปีที่แล้ว

      @@patloeber And to make it even more similar, we can initialize the (in this case, only) weight to zero with: "model.weight.data = torch.zeros(model.weight.shape)"

  • @monsterpets5899
    @monsterpets5899 ปีที่แล้ว

    thank you very much,very nice tutorial

  • @taaaaaaay
    @taaaaaaay 4 ปีที่แล้ว +2

    You teach better than my professor 😩

    • @patloeber
      @patloeber  4 ปีที่แล้ว

      Thanks! Glad you like my teaching style :)

    • @xtraeone5947
      @xtraeone5947 3 ปีที่แล้ว

      Which college r u from?

  • @dorzevi
    @dorzevi 3 ปีที่แล้ว

    this is so good!! thank you

  • @canernm
    @canernm 3 ปีที่แล้ว

    Hi, thanks for the videos.
    Quick question: at 8:00, we say that the output_size is equal to the input_size. This is generally the case or only in this particular example?
    Thanks in advance.

    • @patloeber
      @patloeber  3 ปีที่แล้ว +1

      only in this particular example

    • @canernm
      @canernm 3 ปีที่แล้ว

      @@patloeber great, thanks :) i saw most of the series btw and it rocks! Keep up the good work.

  • @Falconoo7383
    @Falconoo7383 ปีที่แล้ว

    Can we also apply this in the matrix similarly (the gradient)?

  • @popamaji
    @popamaji 3 ปีที่แล้ว

    hi I don't get it when you define model=nn.linear(inputsize,outputsize) which has 2 arguments but in epoch you give model 1 argument(in line: y=model(x) in 9:49)!!!!!
    lets put aside that x and inputsize,outputsize are not the same thing

  • @nicolasgabrielsantanaramos291
    @nicolasgabrielsantanaramos291 4 ปีที่แล้ว

    Thanks for this Class. It's helping me a lot.

    • @patloeber
      @patloeber  4 ปีที่แล้ว

      I'm glad it is helpful :)

  • @longfeihan2100
    @longfeihan2100 2 ปีที่แล้ว

    Very nice tutorial. Is there a mistake here saying "in the last tutorial, we implemented logistic regression from scratch?" but it is about linear regression?

  • @karimbaig8573
    @karimbaig8573 3 ปีที่แล้ว

    Could you please explain how this class extension is done: like why does the class LinearRegression, need to implement the forward method in the class? why does the lin(x) take only one parameter? I always get confused about extending classes and if you could explain/make a video for it. what would be a good resource to learn about extending classes and/or extending classes for custom layers?

  • @martinkolb3616
    @martinkolb3616 3 ปีที่แล้ว

    How do you tune hyperparameters like learning rate? Do you use a lr_finder? Or what's your pipeline for improving metrics?

    • @martinkolb3616
      @martinkolb3616 3 ปีที่แล้ว

      Mostly, how do you pick the starting learning rate? Afterwards, I think you tend to use a scheduler? (question should have been posted in the comments of the lr_scheduler video...sorry!)

  • @edmonda.9748
    @edmonda.9748 4 ปีที่แล้ว +1

    in manual optimization (e.g. in SGD) we need and use the gradient directly in the update formula. it seems there should be a direct relation between loss.backward() and optimizer.step(), (i.e. optimizer.step() should get an input from nn.backward() ) unless under the hood the optimizer uses the grad calculated by loss.backward()
    if somebody could explain what happens ...

    • @patloeber
      @patloeber  4 ปีที่แล้ว +3

      optimizer.step performs a parameter update based on the current gradient (stored in .grad attribute of a parameter) and the update rule. See here: discuss.pytorch.org/t/how-are-optimizer-step-and-loss-backward-related/7350

  • @harissajwani2583
    @harissajwani2583 4 ปีที่แล้ว +1

    Hi.. why do you use the super() method for the same class?

    • @patloeber
      @patloeber  4 ปีที่แล้ว +1

      This is the syntax to call the super method of the nn.Module base class: See here: stackoverflow.com/questions/576169/understanding-python-super-with-init-methods

  • @tayssirmoussa334
    @tayssirmoussa334 2 ปีที่แล้ว

    Thank you for this video,but i have a question about training model with pytorch,
    I'm working on prediction model with pytorch and i need that the process of preparing data abd training run in parallel ,is there any way of doing that?

  • @snackbob100
    @snackbob100 3 ปีที่แล้ว

    Does the super initialization just initiate the NN.module constructor (that we cant see), as well as the super LinearRegession class constructor?

    • @patloeber
      @patloeber  3 ปีที่แล้ว +1

      the NN.module with all its magic behind the scenes...

  • @brucegalleco8892
    @brucegalleco8892 3 ปีที่แล้ว

    How do I modify the code if the inputs are multiple linear instead of 1,2,3,4 I have like [1,1], [2,2,], [3,3], [4,4] and is there a way plot it out.

  • @vishnuvardhan6625
    @vishnuvardhan6625 9 หลายเดือนก่อน

    Helpful ❤

  • @popamaji
    @popamaji 4 ปีที่แล้ว +1

    pls explain or give sources or make a vid about what is optimizer and what are its benefits?

    • @patloeber
      @patloeber  4 ปีที่แล้ว

      optimizer will make your life easier ;) it solves the update calculations for you

  • @DanielWeikert
    @DanielWeikert 5 ปีที่แล้ว

    Thanks great work again! One question related to the topic you might have an idea on. When we only have one output like "good" or "bad" I have seen people using softmax with a Dense layer and 2 neurons at the end and people using sigmoid using a Dense layer with 1 output. What do you think is the better approach?

    • @patloeber
      @patloeber  5 ปีที่แล้ว

      Good question. I prefer one output for binary classifiers. It needs fewer parameters (less prone to overfitting and errors), and therefore fewer calculations, so slightly faster updates. On the other hand 2 layers can be more flexible...

  • @nscarlos25
    @nscarlos25 3 ปีที่แล้ว

    Great video!
    Do you consider making videos with reinforcement learning models with PyTorch? That would be great!

    • @patloeber
      @patloeber  3 ปีที่แล้ว +1

      thanks! I already have one with RL and the snake game

    • @nscarlos25
      @nscarlos25 3 ปีที่แล้ว

      @@patloeber great! Found it! Thanks!

  • @sairabano7968
    @sairabano7968 3 ปีที่แล้ว

    Can you please tell which IDE you are using, is it sublime text? because for me sublime editor is not working with PyTorch

  • @salafghaniedsa669
    @salafghaniedsa669 11 หลายเดือนก่อน

    thats awesome!

  • @daliborgrudenic9966
    @daliborgrudenic9966 ปีที่แล้ว

    Sooooo helpful :-)

  • @yashwatwani4574
    @yashwatwani4574 4 ปีที่แล้ว

    Great tutorial buddy!! Can u explain "model(X_test)" is coming as -0.449 . I want to know the process like what is happening "model = nn.Linear(input_size, output_size)"

    • @patloeber
      @patloeber  4 ปีที่แล้ว

      calling model(X) will calculate the forward pass and give us the predicted values. Usually we have to define the forward pass in our model class, but since we are only using one nn.Linear layer, the forward pass is already available

  • @LoveinPortofino1
    @LoveinPortofino1 4 ปีที่แล้ว

    Dear Python Engineer,
    When you hover over a method or a class, you get a really nice quick documentation for pytorch methods. Did you do any additional operation such as adding some external documentation to pycharm, or it is the default behavior of your pycharm program?
    Btw, great content. We look for more customized models!
    Best,
    Ibrahim

    • @patloeber
      @patloeber  4 ปีที่แล้ว +1

      Thanks! My editor is VS Code. I just have the Python extension installed, this comes with auto suggestions.

  • @Dan-uf2vh
    @Dan-uf2vh 4 ปีที่แล้ว

    can someone please explain why Adam is considered adaptive and how it operates in conjuncture with zero_grad? if it is adaptive, using zero_grad will only allow it to be adaptive within the batch that you supply it at every step; am I correct? it adapts within the batch or is something wrong with this interpretation and with using zero_grad before each step?

  • @trioduoxx
    @trioduoxx 4 ปีที่แล้ว

    Thank you

    • @patloeber
      @patloeber  4 ปีที่แล้ว

      glad you like it!

  • @my_opiniondemocracy6584
    @my_opiniondemocracy6584 2 ปีที่แล้ว

    how to write the python code in oop?
    I know the basics ...but I still dont know how to go about the flow..
    like you wrote..like writing an essay or a story

  • @piyushkumar-wg8cv
    @piyushkumar-wg8cv ปีที่แล้ว

    Aren't the number of samples and dimension of input different things?

  • @zhengguanwang4337
    @zhengguanwang4337 2 ปีที่แล้ว

    perfect!!!!!

  • @ijaj8143
    @ijaj8143 ปีที่แล้ว

    Why on earth this series has so less views.. not justified

  • @albertma1
    @albertma1 4 ปีที่แล้ว +1

    I actually love this video and the tutorial 7. I am a newbie in the ML/AI. This video helped me understand how to code from scratch to train a prior model. I'd love to see a video on how to modify this code to do reinforcement learning. I am working on a task in which I can train a prior model but now I need to apply reinforcement learning to this model. I know my reward function (score from 0 to 1) but I am not sure what exactly I should change to the code and especially how to modify the loss function. It is the nn.CrossEntropyLoss loss function. I know that my new loss function should be a function of both the original loss function and reward. (correct me if I am wrong). Is there anyone can give me some guidance? thanks

    • @patloeber
      @patloeber  4 ปีที่แล้ว

      Hi. Really glad you like it! hmm Reinforcement Learning can be complex. I am planning a tutorial for this, but it may take a few weeks...Maybe this tutorial is helpful for you in the meanwhile:
      pytorch.org/tutorials/intermediate/reinforcement_q_learning.html

  • @licurtis332
    @licurtis332 22 วันที่ผ่านมา

    When I copy the custom model and run, "TypeError: LinearRegression.__init__() takes 1 positional argument but 3 were given" occurs. I check the code line by line, I promise there's no typing mistakes. Is there anybody can help me out?

  • @ARCGISPROMASTERCLASS
    @ARCGISPROMASTERCLASS 2 ปีที่แล้ว

    Excellant

  • @pulkitverma8923
    @pulkitverma8923 4 ปีที่แล้ว

    I am still not clear about using super(), if we are in the same class then why are we using it?

    • @patloeber
      @patloeber  4 ปีที่แล้ว +1

      We need it to initialize the super class (nn.Module) correctly so we can use its functionality

    • @pulkitverma8923
      @pulkitverma8923 4 ปีที่แล้ว

      @@patloeber Thank you, I loved your tutorial. One of the best tutorials on pytorch I have ever seen.

    • @ВикторКуркучеков
      @ВикторКуркучеков 4 ปีที่แล้ว

      @@patloeber Maybe I am wrong, but is super(LinearRegression,self) the same to super()? Then why we are use arguments?

    • @patloeber
      @patloeber  4 ปีที่แล้ว

      @@pulkitverma8923 thanks :)

    • @patloeber
      @patloeber  4 ปีที่แล้ว

      @@ВикторКуркучеков Yes in Python 3 it's ok to just use super(). The arguments are just for backwards compatibility, and because PyTorch uses it like this in their documentation as well. But you can omit them.

  • @margin1570
    @margin1570 2 ปีที่แล้ว

    loss function should be loss(y_pred, Y)

  • @SANK4444
    @SANK4444 10 หลายเดือนก่อน

    optimizer.zero_grad()
    loss.backward()
    optimizer.step()
    I guess the order of those matters right??

  • @damianwysokinski3285
    @damianwysokinski3285 3 ปีที่แล้ว

    Looks like pytorch requires more tedious work compared to keras

    • @patloeber
      @patloeber  3 ปีที่แล้ว

      a little bit but it gives you more flexibility

    • @damianwysokinski3285
      @damianwysokinski3285 3 ปีที่แล้ว

      @@patloeber which one do you use more often in your production systems?

  • @高造擎
    @高造擎 2 ปีที่แล้ว

    I was executing the code, and I encountered this error:
    w -= learning_rate * w.grad (your code is right)
    w = w - learning_rate * w.grad (mine causes error)
    Can anybody explain this to me? Aren't these two lines the same?