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

问题描述 投票:5回答:1

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

此外,我很清楚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

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

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

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

如果一个人使用二进制交叉熵到一个热矢量。预期零标签的概率也将受到惩罚。

machine-learning classification multilabel-classification one-hot-encoding cross-entropy
1个回答
3
投票

有关类似问题,请参阅my answer。简而言之,二元交叉熵公式对于单热矢量没有意义。可以将softmax交叉熵应用于两个或更多类,或者根据任务使用label中的(独立)概率向量。

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

你计算的是4个独立特征的二元交叉熵:

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

© www.soinside.com 2019 - 2024. All rights reserved.