AbsoluteMarginLoss¶
- class ampligraph.latent_features.AbsoluteMarginLoss(loss_params={}, verbose=False)¶
Absolute margin, max-margin loss.
Introduced in [HOSM17].
\[\mathcal{L}(\Theta) = \sum_{t^+ \in \mathcal{G}}\sum_{t^- \in \mathcal{C}} max(0, [\gamma - f_{model}(t^-;\Theta)]) - f_{model}(t^+;\Theta)\]where \(\gamma\) is the margin, \(\mathcal{G}\) is the set of positives, \(\mathcal{C}\) is the set of corruptions, \(f_{model}(t;\Theta)\) is the model-specific scoring function.
Example
>>> import ampligraph.latent_features.loss_functions as lfs >>> loss = lfs.AbsoluteMarginLoss({'margin': 1, 'reduction': 'mean'}) >>> isinstance(loss, lfs.AbsoluteMarginLoss) True
>>> loss = lfs.get('absolute_margin') >>> isinstance(loss, lfs.AbsoluteMarginLoss) True
Attributes
external_paramsnameMethods
__init__([loss_params, verbose])Initialize the loss.
- __init__(loss_params={}, verbose=False)¶
Initialize the loss.
- Parameters:
loss_params (dict) –
Dictionary of loss-specific hyperparams:
”margin”: (float) - Margin to be used in pairwise loss computation (default: 1).
”reduction”: (str) - Specifies whether to “sum” or take “mean” of loss per sample w.r.t. corruption (default: “sum”).
Example:
loss_params={'margin': 1}.