Created
June 8, 2019 18:21
-
-
Save vaibhavkumar049/d941092e41237486d5b8d089c45f9729 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FirstNetwork(nn.Module): | |
def __init__(self): | |
super().__init__() | |
torch.manual_seed(0) | |
self.weights1 = nn.Parameter(torch.randn(2, 2) / math.sqrt(2)) | |
self.bias1 = nn.Parameter(torch.zeros(2)) | |
self.weights2 = nn.Parameter(torch.randn(2, 4) / math.sqrt(2)) | |
self.bias2 = nn.Parameter(torch.zeros(4)) | |
def forward(self, X): | |
a1 = torch.matmul(X, self.weights1) + self.bias1 | |
h1 = a1.sigmoid() | |
a2 = torch.matmul(h1, self.weights2) + self.bias2 | |
h2 = a2.exp()/a2.exp().sum(-1).unsqueeze(-1) | |
return h2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment