在神经网络的输出层,典型的是使用softmax函数来近似一个概率分布:

因为指数的缘故,计算起来很费钱。为什么不简单地执行Z变换,使所有输出都是正的,然后通过将所有输出除以所有输出的和来归一化?


当前回答

假设我们改变softmax函数,使输出激活由

where c is a positive constant. Note that c=1 corresponds to the standard softmax function. But if we use a different value of c we get a different function, which is nonetheless qualitatively rather similar to the softmax. In particular, show that the output activations form a probability distribution, just as for the usual softmax. Suppose we allow c to become large, i.e., c→∞. What is the limiting value for the output activations a^L_j? After solving this problem it should be clear to you why we think of the c=1 function as a "softened" version of the maximum function. This is the origin of the term "softmax". You can follow the details from this source (equation 83).

其他回答

我们正在研究一个多类分类问题。也就是说,预测变量y可以取k个类别中的一个,其中k > 2。在概率论中,这通常用多项分布来模拟。多项分布是指数族分布的一个成员。我们可以利用指数族分布的性质重构概率P(k=?|x),它与softmax公式一致。

如果你相信这个问题可以用另一个分布来建模,而不是多项式分布,那么你就可以得到一个不同于softmax的结论。

有关进一步的信息和正式的推导,请参阅CS229课堂讲稿(9.3 Softmax回归)。

此外,通常对softmax执行的一个有用的技巧是:softmax(x) = softmax(x+c), softmax在输入中的偏移量不变。

假设我们改变softmax函数,使输出激活由

where c is a positive constant. Note that c=1 corresponds to the standard softmax function. But if we use a different value of c we get a different function, which is nonetheless qualitatively rather similar to the softmax. In particular, show that the output activations form a probability distribution, just as for the usual softmax. Suppose we allow c to become large, i.e., c→∞. What is the limiting value for the output activations a^L_j? After solving this problem it should be clear to you why we think of the c=1 function as a "softened" version of the maximum function. This is the origin of the term "softmax". You can follow the details from this source (equation 83).

我发现这里的解释非常好:CS231n:用于视觉识别的卷积神经网络。

从表面上看,softmax算法似乎是一个简单的非线性(我们用指数传播数据)归一化。然而,事情远不止如此。

具体来说,有几个不同的视图(与上面的链接相同):

信息论——从信息论的角度来看,softmax函数可以被看作是试图最小化预测和事实之间的交叉熵。 概率视图-从这个角度来看,我们实际上是在看对数概率,因此当我们执行幂运算时,我们最终得到原始概率。在这种情况下,softmax方程找到MLE(最大似然估计)

总之,即使softmax方程看起来是任意的,但它不是。这实际上是规范化分类的一种相当有原则的方式,以最小化预测和事实之间的交叉熵/负可能性。

我认为其中一个原因可能是处理负数并除以0,因为exp(x)总是正的并且大于0。

例如,对于a =[-2, -1, 1,2],和将是0,我们可以使用softmax来避免除0。

q_i的值是无界的分数,有时被解释为对数概率。根据这种解释,为了恢复原始概率值,必须对它们求幂。

统计算法经常使用对数似然损失函数的一个原因是它们在数值上更稳定:概率的乘积可以表示为一个非常小的浮点数。使用对数似然损失函数,概率的乘积变成一个和。

另一个原因是,当假设从多元高斯分布中提取随机变量的估计量时,对数似然性自然发生。例如,请参阅最大似然(ML)估计器及其与最小二乘连接的方式。