class MLP(torch.nn.Module):
def __init__(self,D_in,H, D_out):
"""
In the constructor we instantiate two nn.Linear modules and assign them as member variables.
"""
super(MLPModel,self).__init__()
self.hidden1 = torch.nn.Linear(D_in,H)
self.hidden2 = torch.nn.Linear(H,D_out)
self.sig = torch.nn.Sigmoid()
def forward(self,x):
"""
In the forward function we accept a Tensor of input data and we must return
a Tensor of output data. We can use Modules defined in the constructor as
well as arbitrary operators on Tensors.
"""
out = self.sig(self.hidden1(x))
out = self.hidden2(out)
return out
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter