Multi Layer Perceptron in Pytorch

PHOTO EMBED

Tue Jun 22 2021 13:30:37 GMT+0000 (Coordinated Universal Time)

Saved by @saran #python

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
content_copyCOPY