AttributeError: 'super' object has no attribute '_LinearRegressionModel__init' #1088
Unanswered
MaryamSaremiKermanshahi
asked this question in
Q&A
Replies: 1 comment 1 reply
-
@MaryamSaremiKermanshahi I think you didnt put double underscore on right side of Here's the corrected version: # Create a linear regression model class
class LinearRegressionModel(nn.Module): # nn.Module contains building blocks(subclass) of neural networks
def __init__(self):
super().__init__()
self.weights = nn.Parameter(torch.randn(1,
requires_grad = True, # set parameter to be updated via gradient descent -> True
dtype = torch.float))
self.bias = nn.Parameter(torch.randn(1,
requires_grad = True, # set parameter to be updated via gradient descent -> True
dtype = torch.float))
# Forward method to define the computation in model
def forward(self, x:torch.Tensor) -> torch.Tensor: # 'x' is input data
return self.weights * x + self.bias # Linear regression formula |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey, I am trying 01_pytorch_workflow on my colab,
when I want to check my LinearRegressionModel, with rhis code:
from torch import nn
#Creating linear regression model
class LinearRegressionModel(nn.Module): #almost everything in PyTorch inherits from nn.Module
def init(self):
super().__init()
#Create a random seed
torch.manual_seed(42)
#Create an instance of the model (this is a subclass of nn.Module)
model_0 = LinearRegressionModel()
model_0
I face to this error:
AttributeError: 'super' object has no attribute '_LinearRegressionModel__init'
"Would you please help me, get rid of the error"
Beta Was this translation helpful? Give feedback.
All reactions