我正在做一个需要Softmax Regression用Pytorch. 作业说:
Implement Softmax Regression as an nn.Module and pipe its output with its output with torch.nn.Softmax.
由于我是 pytorch 的新手,我不知道该怎么做。到目前为止,我已经尝试过:
class SoftmaxRegression(nn.Module): # 继承自 nn.Module!
def __init__(self, num_labels, num_features):
super(SoftmaxRegression, self).__init__()
self.linear = torch.nn.Linear(num_labels, num_features)
def forward(self, x):
# should return the probabilities for the classes, e.g.
# tensor([[ 0.1757, 0.3948, 0.4295],
# [ 0.0777, 0.3502, 0.5721],
# ...
# not sure what to do here
有人知道我该怎么做吗?我不确定该forward方法中应该写什么。我感谢任何帮助!