ApproxLossFunction
- class lightning_ir.loss.approximate.ApproxLossFunction(temperature: float = 1)[source]
Bases:
ListwiseLossFunctionBase class for approximate loss functions that compute ranks from scores.
- __init__(temperature: float = 1) None[source]
Initialize the ApproxLossFunction.
- Parameters:
temperature (float) – Temperature parameter for scaling the scores. Defaults to 1.
Methods
__init__([temperature])Initialize the ApproxLossFunction.
get_approx_ranks(scores, temperature)Compute approximate ranks from scores.
- abstract compute_loss(output: LightningIROutput, batch: TrainBatch) torch.Tensor
Compute the loss based on the scores and targets in the output and batch.
- 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
- static get_approx_ranks(scores: Tensor, temperature: float) Tensor[source]
Compute approximate ranks from scores.
- Parameters:
scores (torch.Tensor) – The input scores.
temperature (float) – Temperature parameter for scaling the scores.
- Returns:
The computed approximate ranks.
- 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