Skip to content

Instantly share code, notes, and snippets.

@vaibhavkumar049
Created June 8, 2019 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaibhavkumar049/d941092e41237486d5b8d089c45f9729 to your computer and use it in GitHub Desktop.
Save vaibhavkumar049/d941092e41237486d5b8d089c45f9729 to your computer and use it in GitHub Desktop.
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