BCEWithLogitsLoss
- class BCEWithLogitsLoss(reduction: str = 'mean')[来源]
基础类:
PointwiseLoss二元交叉熵损失。
对于标签函数 \(l:\mathcal{E} \times \mathcal{R} \times \mathcal{E} \rightarrow \{0,1\}\) 和交互函数 \(f:\mathcal{E} \times \mathcal{R} \times \mathcal{E} \rightarrow \mathbb{R}\),二元交叉熵损失定义为:
\[L(h, r, t) = -(l(h,r,t) \cdot \log(\sigma(f(h,r,t))) + (1 - l(h,r,t)) \cdot \log(1 - \sigma(f(h,r,t))))\]其中表示逻辑S型函数
\[\sigma(x) = \frac{1}{1 + \exp(-x)}\]注意
softplus激活函数 \(h_{\text{softplus}}(x) = -\log(\sigma(x))\).
因此,问题被框定为三元组的二元分类问题,其中交互函数的输出被视为logits。
警告
这种损失不太适合用于平移距离模型,因为这些模型会产生负距离作为分数,并且无法产生正的模型输出。
注意
相关的
torch模块是torch.nn.BCEWithLogitsLoss,但由于 PyKEEN 的损失函数中实现了扩展功能,因此不能互换使用。初始化损失。
- Parameters:
reduction (str) – 减少方式,参见
pykeen.nn.modules._Loss
属性摘要
这个损失的近义词
方法总结
forward(scores, labels)定义每次调用时执行的计算。
属性文档
方法文档