class BCEWithLogitsLoss(size_average=None, reduce=None, reduction='mean')[source]

Bases: pykeen.losses.PointwiseLoss

A module for the binary cross entropy loss.

For label function \(l:\mathcal{E} \times \mathcal{R} \times \mathcal{E} \rightarrow \{0,1\}\) and interaction function \(f:\mathcal{E} \times \mathcal{R} \times \mathcal{E} \rightarrow \mathbb{R}\), the binary cross entropy loss is defined as:

\[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))))\]

where represents the logistic sigmoid function

\[\sigma(x) = \frac{1}{1 + \exp(-x)}\]

Thus, the problem is framed as a binary classification problem of triples, where the interaction functions’ outputs are regarded as logits.


This loss is not well-suited for translational distance models because these models produce a negative distance as score and cannot produce positive model outputs.

Initializes internal Module state, shared by both nn.Module and ScriptModule.

Attributes Summary


Methods Summary

forward(scores, labels)

Defines the computation performed at every call.

Attributes Documentation

synonyms: ClassVar[Optional[Set[str]]] = {'Negative Log Likelihood Loss'}

Methods Documentation

forward(scores, labels)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.


Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Return type