DeltaPointwiseLoss

class DeltaPointwiseLoss(margin: float | None = 0.0, margin_activation: str | Module | None = 'softplus', reduction: Literal['mean', 'sum'] = 'mean')[source]

Bases: PointwiseLoss

A generic class for delta-pointwise losses.

Pointwise Loss

Activation

Margin

Formulation

Implementation

Pointwise Hinge

ReLU

\(\lambda \neq 0\)

\(g(s, l) = \max(0, \lambda -\hat{l}*s)\)

pykeen.losses.PointwiseHingeLoss

Soft Pointwise Hinge

softplus

\(\lambda \neq 0\)

\(g(s, l) = \log(1+\exp(\lambda -\hat{l}*s))\)

pykeen.losses.SoftPointwiseHingeLoss

Pointwise Logistic (softplus)

softplus

\(\lambda = 0\)

\(g(s, l) = \log(1+\exp(-\hat{l}*s))\)

pykeen.losses.SoftplusLoss

Initialize the loss.

Parameters:
  • margin (float | None) – the margin, cf. PointwiseLoss.__init__()

  • margin_activation (Hint[nn.Module]) – the margin activation, or a hint thereof, cf. margin_activation_resolver.

  • reduction (Literal['mean', 'sum']) – the reduction, cf. PointwiseLoss.__init__()

Attributes Summary

hpo_default

The default strategy for optimizing the loss's hyper-parameters

Methods Summary

forward(x, target[, weight])

Calculate the point-wise loss.

Attributes Documentation

hpo_default: ClassVar[Mapping[str, Any]] = {'margin': {'high': 3, 'low': 0, 'type': <class 'float'>}, 'margin_activation': {'choices': {'hard', 'relu', 'soft', 'softplus'}, 'type': 'categorical'}}

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

Methods Documentation

forward(x: Tensor, target: Tensor, weight: Tensor | None = None) Tensor[source]

Calculate the point-wise loss.

Parameters:
  • x (Tensor) – The predictions.

  • target (Tensor) – The target values (between 0 and 1).

  • weight (Tensor | None) – The sample weights.

Returns:

The scalar loss value.

Return type:

Tensor