Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intro to pytorch #3

Open
enryH opened this issue May 24, 2022 · 0 comments
Open

intro to pytorch #3

enryH opened this issue May 24, 2022 · 0 comments

Comments

@enryH
Copy link
Collaborator

enryH commented May 24, 2022

Regarding two questions regarding the exercises. Please see the two comments:

  • initialise weights to zero: check out this code -> zero_() method call on paramters (the underscore tell you that is changing the state as far as I know)

  • if you make your custom module, it has the attributes you give it (and some methods it inherits). So a nn.Linear instance has attributes weight and bias, not your custom class bases on nn.Module

    class LinearRegression(nn.Module):
    
     def __init__(self):
         """Everything stateful which you need to use your model goes here."""
         super().__init__()  # needs to be here for API reasons -> call nn.Module.__init__
         self.linear_reg = nn.Linear(1, 1)
    
     def forward(self, x):  # now with input
         return self.linear_reg(x)
    
    
     lin_reg = LinearRegression()
     lin_reg.linear_reg.weight # access weight of underlying nn.Linear instance 
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant