CrossEntropyLoss
- class CrossEntropyLoss(reduction: str = 'mean')[source]
Bases:
SetwiseLoss
The cross entropy loss that evaluates the cross entropy after softmax output.
Note
The related
torch
module istorch.nn.CrossEntropyLoss
, but it can not be used interchangeably in PyKEEN because of the extended functionality implemented in PyKEEN’s loss functions.Initialize the loss.
- Parameters:
reduction (str) – the reduction, cf.
pykeen.nn.modules._Loss
Methods Summary
process_lcwa_scores
(predictions, labels[, ...])Process scores from LCWA training loop.
process_slcwa_scores
(positive_scores, ...[, ...])Process scores from sLCWA training loop.
Methods Documentation
- process_lcwa_scores(predictions: Tensor, labels: Tensor, label_smoothing: float | None = None, num_entities: int | None = None) Tensor [source]
Process scores from LCWA training loop.
- Parameters:
- Returns:
A scalar loss value.
- Return type:
- process_slcwa_scores(positive_scores: Tensor, negative_scores: Tensor, label_smoothing: float | None = None, batch_filter: Tensor | None = None, num_entities: int | None = None) Tensor [source]
Process scores from sLCWA training loop.
- Parameters:
positive_scores (Tensor) – shape: (batch_size, 1) The scores for positive triples.
negative_scores (Tensor) – shape: (batch_size, num_neg_per_pos) or (num_unfiltered_negatives,) The scores for the negative triples, either in dense 2D shape, or in case they are already filtered, in sparse shape. If they are given in sparse shape, batch_filter needs to be provided, too.
label_smoothing (float | None) – An optional label smoothing parameter.
batch_filter (Tensor | None) – shape: (batch_size, num_neg_per_pos) An optional filter of negative scores which were kept. Given if and only if negative_scores have been pre-filtered.
num_entities (int | None) – The number of entities. Only required if label smoothing is enabled.
- Returns:
A scalar loss term.
- Return type: