softmax 和 crossEntropyloss

原文标题softmax and crossEntropyloss

我想知道softmax是否是多类(超过2个)分类神经网络中的必备品?我正在阅读一些堆栈溢出主题,我看到一些人说有必要在最后一层有 softmax,而另一些人说没有必要包含它,因为 crossEntropyloss 本身应用了 softmax,所以我不确定它是否真的有必要或不? (这里是讨论 pytorch 的链接 – 我需要在我的多类分类模型中应用 Softmax 函数吗? – 堆栈溢出!)据我所知,softmax 所做的只是将输出加权缩放到范围之间0 和 1,总和为 1。如果您能清除以下几点,我将不胜感激:

   1. is it a must to have a softmax in the last layer in case of mutli-class classification?
   2. if we have softmax in the last layer, would it affect the calculation of cross entropy loss?
   3. if we don’t include it in the last layer, how would it affect the whole accuracy calculation and classification in general? thanks for your answers in advance.

原文链接:https://stackoverflow.com//questions/71978721/softmax-and-crossentropyloss

回复

我来回复
  • khashayar ehteshami的头像
    khashayar ehteshami 评论

    与 PyTorchCrossEntropy 中一样,您可以看到 PyTorch 中的 CrossEntropy 函数本身具有 softmax 函数。因此对于多类分类,在使用 CrossEntropy 函数的情况下,最后一层不需要任何 softmax。

    当您在交叉熵之前完成了 Softmax 激活时,就像执行两次 sofmax 函数一样,这会导致值开始相互平衡。您可以查看此链接以获取有关此内容的更多信息。

    2年前 0条评论