Having an issue with Tensor sizes from model while doing Udemy course #853
Answered
by
LuluW8071
david-bickford
asked this question in
Q&A
-
Beta Was this translation helpful? Give feedback.
Answered by
LuluW8071
Mar 8, 2024
Replies: 1 comment 1 reply
-
class LinearRegressionModel(nn.Module):
def __init__(self):
super().__init__()
self.weights = nn.Parameter(torch.randn(1, requires_grad=True))
self.bias = nn.Parameter(torch.randn(1, requires_grad=True))
#forward method to define the computation in the model
def forward(self, x:torch.Tensor) -> torch.Tensor:
return self.weights * X + self.bias return self.weights * X + self.bias The original Correct way:class LinearRegressionModel(nn.Module):
def __init__(self):
super().__init__()
self.weights = nn.Parameter(torch.randn(1, requires_grad=True))
self.bias = nn.Parameter(torch.randn(1, requires_grad=True))
#forward method to define the computation in the model
def forward(self, x:torch.Tensor) -> torch.Tensor:
return self.weights * x + self.bias |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
david-bickford
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The original
X
value is being returned from originalX
data where it should have beenx
for forwarding the input data at a time as you have wrotedef forward(self, x:torch.Tensor)
in the modelCorrect way: