【发布时间】:2018-03-12 13:34:38
【问题描述】:
这两个函数之间的区别已经在这篇 pytorch 帖子中描述过:What is the difference between log_softmax and softmax?
是:exp(x_i) / exp(x).sum()
并且 log softmax 是:log(exp(x_i) / exp(x).sum()).
但是对于下面的 Pytorch 代码,为什么我得到不同的输出:
>>> it = autograd.Variable(torch.FloatTensor([0.6229,0.3771]))
>>> op = autograd.Variable(torch.LongTensor([0]))
>>> m = nn.Softmax()
>>> log = nn.LogSoftmax()
>>> m(it)
Variable containing:
`0.5611 0.4389`
[torch.FloatTensor of size 1x2]
>>>log(it)
Variable containing:
-0.5778 -0.8236
[torch.FloatTensor of size 1x2]
但是,值 log(0.5611) 是 -0.25095973129,而 log(0.4389) 是 -0.35763441915
为什么会有这样的差异?
【问题讨论】:
标签: machine-learning deep-learning pytorch softmax