如果你正在研究多类分类和简单的神经网络,你可以采用多种方式,作为初学者尝试在PyTorch中创建一个类作为nn.Module的子类来开始
class Network(nn.Module):
def init(self):
super().init()
# Inputs to hidden layer linear transformation
self.hidden = nn.Linear(784, 256)
# Output layer, 10 units - one for each digit
self.output = nn.Linear(256, 10)
# Define sigmoid activation and softmax output
self.sigmoid = nn.Sigmoid()
self.softmax = nn.Softmax(dim=1)
def forward(self, x):
# Pass the input tensor through each of our operations
x = self.hidden(x)
x = self.sigmoid(x)
x = self.output(x)
x = self.softmax(x)
return x
model = Network()
</code>