Loss Functions

Loss functions implemented in PyKEEN and additionally imported from torch.

Name

Reference

bce

torch.nn.BCELoss

bceaftersigmoid

pykeen.losses.BCEAfterSigmoidLoss

crossentropy

pykeen.losses.CrossEntropyLoss

marginranking

torch.nn.MarginRankingLoss

mse

torch.nn.MSELoss

nssa

pykeen.losses.NSSALoss

softplus

pykeen.losses.SoftplusLoss

Note

This table can be re-generated with pykeen ls losses -f rst

class pykeen.losses.BCEAfterSigmoidLoss(reduction='mean')[source]

A loss function which uses the numerically unstable version of explicit Sigmoid + BCE.

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

forward(logits, labels, **kwargs)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

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

FloatTensor

class pykeen.losses.CrossEntropyLoss(reduction='mean')[source]

Evaluate cross entropy after softmax output.

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

forward(logits, labels, **kwargs)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

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

FloatTensor

pykeen.losses.Loss

alias of torch.nn.modules.loss._Loss

class pykeen.losses.NSSALoss(margin, adversarial_temperature, reduction='mean')[source]

An implementation of the self-adversarial negative sampling loss function proposed by [sun2019].

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

forward(pos_scores, neg_scores)[source]

Calculate the loss for the given scores.

Return type

FloatTensor

class pykeen.losses.SoftplusLoss(reduction='mean')[source]

A loss function for the softplus.

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

forward(logits, labels)[source]

Calculate the loss for the given scores and labels.

Return type

FloatTensor

pykeen.losses.get_loss_cls(query)[source]

Get the loss class.

Return type

Type[_Loss]