首页 文章

二进制Crossentropy惩罚单热矢量的所有分量

提问于
浏览
4

我知道二元交叉熵与两类的分类交叉熵相同 .

此外,我很清楚softmax是什么 .
因此,我看到分类交叉熵只会惩罚应该为1的一个分量(概率) .

但是为什么,不能或不应该在单热矢量上使用二进制交叉熵?

Normal Case for 1-Label-Multiclass-Mutual-exclusivity-classification:
################
pred            = [0.1 0.3 0.2 0.4]
label (one hot) = [0   1   0   0]
costfunction: categorical crossentropy 
                            = sum(label * -log(pred)) //just consider the 1-label
                            = 0.523
Why not that?
################
pred            = [0.1 0.3 0.2 0.4]
label (one hot) = [0   1   0   0]
costfunction: binary crossentropy
                            = sum(- label * log(pred) - (1 - label) * log(1 - pred))
                            = 1*-log(0.3)-log(1-0.1)-log(1-0.2)-log(1-0.4)
                            = 0.887

我看到在二进制交叉熵中 zero 是一个目标类,并且对应于以下一个热门编码:

target class zero 0 -> [1 0]
target class one  1 -> [0 1]

总结:为什么我们只计算/总结预测类的负对数似然 . 为什么我们不惩罚其他SHOULD-BE-ZERO- / NOT-THAT-CLASS课程呢?

在一种情况下,使用二进制交叉熵到单热矢量 . 预期零标签的概率也将受到惩罚 .

1 回答

  • 2

    有关类似问题,请参阅my answer . 简而言之,二元交叉熵公式不可能对两个或更多类应用softmax交叉熵,或者根据任务使用 label 中的(独立)概率向量 .

    但是为什么,不能或不应该在单热矢量上使用二进制交叉熵?

    你计算的是 4 independent features 的二进制交叉熵:

    pred   = [0.1 0.3 0.2 0.4]
    label  = [0   1   0   0]
    

    模型推断预测第一个特征以10%概率开启,第二个特征以30%概率开启,依此类推 . 目标标签以这种方式解释:所有功能都关闭,第二个除外 . 注意, [1, 1, 1, 1] 也是完全有效的标签,即它不是单热矢量,并且 pred=[0.5, 0.8, 0.7, 0.1] 是有效预测,即总和不必等于1 .

    换句话说,您的计算是有效的,但是对于完全不同的问题:多标签非排他性二进制分类 .

    另见difference between softmax and sigmoid cross-entropy loss functions in tensorflow .

相关问题