RankNet
- class lightning_ir.loss.pairwise.RankNet(temperature: float = 1)[source]
Bases:
PairwiseLossFunctionRankNet loss function for pairwise ranking tasks.
RankNet optimizes pairwise ranking by modeling the probability that a positive document should be ranked higher than a negative document using a logistic function. It computes the margin between the scores of positive and negative pairs and applies a binary cross-entropy loss to maximize the likelihood of correct pairwise orderings. This approach allows the model to learn from relative comparisons rather than absolute score values.
Originally proposed in: Learning to Rank using Gradient Descent
- __init__(temperature: float = 1) None[source]
Initialize the RankNet loss function. :param temperature: Temperature parameter for scaling the scores. :type temperature: float
Methods
__init__([temperature])Initialize the RankNet loss function.
compute_loss(output, batch)Compute the RankNet loss.
- compute_loss(output: LightningIROutput, batch: TrainBatch) torch.Tensor[source]
Compute the RankNet 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