PairwiseLoss

class ampligraph.latent_features.PairwiseLoss(loss_params={}, verbose=False)

Pairwise, max-margin loss.

Introduced in [BUGD+13].

\[\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.PairwiseLoss({'margin': 0.005, 'reduction': 'sum'})
>>> isinstance(loss, lfs.PairwiseLoss)
True
>>> loss = lfs.get('pairwise')
>>> isinstance(loss, lfs.PairwiseLoss)
True

Attributes

external_params

name

Methods

__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 the “mean” of loss per sample w.r.t. corruptions (default: “sum”).

Example: loss_params={‘margin’: 1}.