InfoNCE
- class lightning_ir.loss.listwise.InfoNCE[source]
Bases:
ListwiseLossFunctionInfoNCE loss for listwise ranking tasks.
Information Noise-Contrastive Estimation loss for listwise ranking adapts contrastive learning by treating the relevant item as the positive signal and all other items in the list as negative noise, maximizing the likelihood of the correct document relative to the entire candidate set via a softmax-normalized objective.
Originally proposed in: Representation Learning with Contrastive Predictive Coding
Methods
compute_loss(output, batch)Compute the InfoNCE loss.
- compute_loss(output: LightningIROutput, batch: TrainBatch) torch.Tensor[source]
Compute the InfoNCE loss.
- Parameters:
output (LightningIROutput) – The output from the model containing scores.
batch (TrainBatch) – The training batch containing targets.
- Returns:
The computed loss.
- Return type:
torch.Tensor