Last active
June 20, 2020 14:37
-
-
Save Mehdi-Amine/26119e3727ef1e46fe295e6a53aee5e2 to your computer and use it in GitHub Desktop.
Defining the structure of the confined but happy neural network
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
import torch.nn as nn | |
import torch.nn.functional as F | |
class Network(nn.Module): | |
def __init__(self, input_size, lin1_size, lin2_size): | |
super().__init__() # initializes Network from the parent class Module. | |
# linear layers. | |
self.lin1 = nn.Linear(input_size, lin1_size) # Creates random weights and biases. | |
self.lin2 = nn.Linear(lin1_size, lin2_size) # Use lin1.weight & lin1.bias to inspect. | |
def forward(self, x): | |
x = self.lin1(x) # affine function: x = x @ weights + bias. | |
x = F.relu(x) # ReLU activation. | |
x = self.lin2(x) # 2nd affine function | |
return x | |
# Creating a Network object | |
net = Network(input_size=3, lin1_size=7, lin2_size=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment