MarginRankingLoss¶
-
class
MarginRankingLoss
(margin=1.0, margin_activation='relu', reduction='mean')[source]¶ Bases:
pykeen.losses.PairwiseLoss
A module for the margin ranking loss.
See also
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
The default strategy for optimizing the model’s hyper-parameters
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
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