具体来说,我正在做一个建模项目,我看到别人的代码看起来像
def forward(self, x):
x = self.fc1(x)
x = self.activation1(x)
x = self.fc2(x)
x = self.activation2(x)
x = self.fc3(x)
x = self.activation3(x)
# use log softmax + NLLLoss in training; softmax to make predictions
if self.training:
x = self.log_softmax(x)
else:
x = self.softmax(x)
return x
对于上下文,这是使用 PyTorch,它涉及分类问题。标准是 NLLLoss。log_softmax 用于训练但softmax用于实际预测的原因是什么?