class Model(torch.nn.Module):
def init(self):
“”"
In the constructor we instantiate two nn.Linear module
“”"
super(Model, self).init()
self.linear = torch.nn.Linear(1, 1) # One in and one out
def forward(self, x):
“”"
In the forward function we accept a Variable of input data and we must return
a Variable of output data. We can use Modules defined in the constructor as
well as arbitrary operators on Variables.
“”"
y_pred = self.linear(x)
return y_pred
So my question is,
- self.linear = torch.nn.Linear(1, 1)
^ How can this attribute take in a function? - y_pred = self.linear(x)
return y_pred
^ How can we call an attribute? I thought functions/methods were only called using (). Isn’t self.linear an attribute?
I am sorry if this sounds silly but the above two are really bothering me.