CrossEntropyLoss
- class CrossEntropyLoss(size_average=None, reduce=None, reduction='mean')[source]
Bases:
pykeen.losses.SetwiseLoss
A module for 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.Initializes internal Module state, shared by both nn.Module and ScriptModule.
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, labels, label_smoothing=None, num_entities=None)[source]
Process scores from LCWA training loop.
- Parameters
- Return type
FloatTensor
- Returns
A scalar loss value.
- process_slcwa_scores(positive_scores, negative_scores, label_smoothing=None, batch_filter=None, num_entities=None)[source]
Process scores from sLCWA training loop.
- Parameters
positive_scores (
FloatTensor
) – shape: (batch_size, 1) The scores for positive triples.negative_scores (
FloatTensor
) – 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 (
Optional
[float
]) – An optional label smoothing parameter.batch_filter (
Optional
[BoolTensor
]) – 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 (
Optional
[int
]) – The number of entities. Only required if label smoothing is enabled.
- Return type
FloatTensor
- Returns
A scalar loss term.