MarginRankingLoss

class MarginRankingLoss(margin=1.0, margin_activation='relu', reduction='mean')[source]

Bases: pykeen.losses.PairwiseLoss

A module for the margin ranking loss.

Initialize the margin loss instance.

Parameters
  • margin (float) – The margin by which positive and negative scores should be apart.

  • margin_activation (Union[str, Callable[[FloatTensor], FloatTensor]]) – A margin activation. Defaults to 'relu', i.e. \(h(\Delta) = max(0, \Delta + \lambda)\), which is the default “margin loss”. Using 'softplus' leads to a “soft-margin” formulation as discussed in https://arxiv.org/abs/1703.07737.

  • reduction (str) – The name of the reduction operation to aggregate the individual loss values from a batch to a scalar loss value. From {‘mean’, ‘sum’}.

Attributes Summary

hpo_default

The default strategy for optimizing the model’s hyper-parameters

synonyms

Methods Summary

forward(pos_scores, neg_scores)

Defines the computation performed at every call.

Attributes Documentation

hpo_default: ClassVar[Mapping[str, Any]] = {'margin': {'high': 3, 'low': 0, 'q': 1, 'type': <class 'int'>}}

The default strategy for optimizing the model’s hyper-parameters

synonyms: ClassVar[Optional[Set[str]]] = {'Pairwise Hinge Loss'}

Methods Documentation

forward(pos_scores, neg_scores)[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