在神经网络的输出层,典型的是使用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).

其他回答

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

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

与标准归一化相比,Softmax有一个很好的属性。

它对分布均匀的神经网络的低刺激(想象一个模糊的图像)和高刺激(例如。大数字,想想清晰的图像),概率接近0和1。

而标准归一化并不关心,只要比例相同。

看看当soft max有10倍大的输入时会发生什么,即你的神经网络得到一个清晰的图像,许多神经元被激活

>>> softmax([1,2])              # blurry image of a ferret
[0.26894142,      0.73105858])  #     it is a cat perhaps !?
>>> softmax([10,20])            # crisp image of a cat
[0.0000453978687, 0.999954602]) #     it is definitely a CAT !

然后与标准归一化进行比较

>>> std_norm([1,2])                      # blurry image of a ferret
[0.3333333333333333, 0.6666666666666666] #     it is a cat perhaps !?
>>> std_norm([10,20])                    # crisp image of a cat
[0.3333333333333333, 0.6666666666666666] #     it is a cat perhaps !?

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

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

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

虽然它确实有些随意,但softmax具有理想的属性,例如:

易微(df/dx = f*(1-f)) 当用作分类任务的输出层时,输入的分数可以解释为log-odds

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

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

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

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

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