Pytorch NLLLOSS的理解

Understanding of Pytorch NLLLOSS

PyTorch的负对数似然损失,nn.NLLLoss定义为:

因此,如果以单批次的标准重量计算损失,则损失的公式始终为:

-1 * (prediction of model for correct class)

示例:

正确 Class = 0

模型预测正确 class = 0.5

损失 = -1 * 0.5

那么,如果计算损失时没有涉及对数函数,为什么称为“负对数似然损失”呢?

确实没有 log 被用来计算 nn.NLLLoss 的结果,所以这可能有点令人困惑。但是,我相信之所以这样称呼它是因为它 期望 接收对数概率:

The input given through a forward call is expected to contain log-probabilities of each class. - docs

最后,将它包含在名称中没有多大意义,因为您可能还想将此函数应用于非对数概率...