NSSALoss
- class NSSALoss(margin: float = 9.0, adversarial_temperature: float = 1.0, reduction: str = 'mean')[source]
Bases:
AdversarialLoss
The self-adversarial negative sampling loss function proposed by [sun2019].
Initialize the NSSA loss.
- Parameters:
margin (float) – The loss’s margin (also written as gamma in the reference paper)
adversarial_temperature (float) –
The negative sampling temperature (also written as alpha in the reference paper)
Note
The adversarial temperature is the inverse of the softmax temperature used when computing the weights! Its name is only kept for consistency with the nomenclature of [sun2019].
reduction (str) – The name of the reduction operation to aggregate the individual loss values from a batch to a scalar loss value. From {‘mean’, ‘sum’}.
Note
The default hyperparameters are based on the experiments for FB15k-237 in [sun2019].
Attributes Summary
The default strategy for optimizing the loss's hyper-parameters
synonyms of this loss
Methods Summary
negative_loss_term_unreduced
(neg_scores[, ...])Calculate the loss for the negative scores without reduction.
positive_loss_term
(pos_scores[, ...])Calculate the loss for the positive scores.
Attributes Documentation
- hpo_default: ClassVar[Mapping[str, Any]] = {'adversarial_temperature': {'high': 1.0, 'low': 0.5, 'type': <class 'float'>}, 'margin': {'high': 30, 'low': 3, 'q': 3, 'type': <class 'int'>}}
The default strategy for optimizing the loss’s hyper-parameters
- synonyms: ClassVar[set[str] | None] = {'Negative Sampling Self-Adversarial Loss', 'Self-Adversarial Negative Sampling Loss'}
synonyms of this loss
Methods Documentation
- negative_loss_term_unreduced(neg_scores: Tensor, label_smoothing: float | None = None, num_entities: int | None = None) Tensor [source]
Calculate the loss for the negative scores without reduction.