PairwiseLoss

class PairwiseLoss(reduction: Literal['mean', 'sum'] = 'mean')[source]

Bases: Loss

Pairwise loss functions compare the scores of a positive triple and a negative triple.

Initialize the loss.

Parameters:

reduction (Literal['mean', 'sum']) – the reduction, cf. pykeen.nn.modules._Loss

Methods Summary

forward(pos_scores, neg_scores[, ...])

Calculate the point-wise loss.

Methods Documentation

abstractmethod forward(pos_scores: Tensor, neg_scores: Tensor, pos_weights: Tensor | None = None, neg_weights: Tensor | None = None) Tensor[source]

Calculate the point-wise loss.

Note

The positive and negative scores need to be broadcastable.

Note

If given, the positve/negative weight needs to be broadcastable to the respective scores.

Parameters:
  • pos_scores (Tensor) – The positive scores.

  • neg_scores (Tensor) – The negative scores.

  • pos_weights (Tensor | None) – The sample weights for positives.

  • neg_weights (Tensor | None) – The sample weights for negatives.

Returns:

The scalar loss value.

Return type:

Tensor