ContrastiveLocalLoss

class lightning_ir.loss.embedding.ContrastiveLocalLoss(temperature: float = 1.0)[source]

Bases: EmbeddingLossFunction

Loss function that computes a contrastive loss between a query and multiple document embeddings, such that only one document embedding has a a high similarity to the query embedding, while all other document embeddings have a low similarity. Originally proposed in: Multi-View Document Representation Learning for Open-Domain Dense Retrieval

__init__(temperature: float = 1.0) None[source]

Methods

__init__([temperature])

compute_loss(output)

Compute the loss based on the embeddings in the output.

compute_loss(output: BiEncoderOutput) torch.Tensor[source]

Compute the loss based on the embeddings in the output.

Parameters:

output (BiEncoderOutput) – The output from the model containing query and document embeddings.

Returns:

The computed loss.

Return type:

torch.Tensor

process_scores(output: LightningIROutput) torch.Tensor

Process the scores from the output.

Parameters:

output (LightningIROutput) – The output from the model.

Returns:

The scores tensor.

Return type:

torch.Tensor

process_targets(scores: torch.Tensor, batch: TrainBatch) torch.Tensor

Process the targets from the batch.

Parameters:
  • scores (torch.Tensor) – The scores tensor.

  • batch (TrainBatch) – The training batch.

Returns:

The processed targets tensor.

Return type:

torch.Tensor