Skip to content
Discussion options

You must be logged in to vote

@matanat — your expected behavior is correct (MRR should be 0 when no relevant docs are retrieved), but the issue in your example is that all predictions have the same score (0.0), which creates an ambiguous ranking.

When all scores are equal, the ranking is arbitrary. TorchMetrics assigns rank 1 to the first element, and since target[0] = 1, it sees the first item as "correctly retrieved at rank 1" → MRR = 1.0.

Fix: use meaningful scores. MRR requires a ranked list:

import torch
from torchmetrics.retrieval import RetrievalMRR

mrr = RetrievalMRR()

# Case 1: relevant item ranked first → MRR = 1.0
preds = torch.tensor([0.9, 0.3, 0.1])
target = torch.tensor([1, 0, 0])
indexes = torch.tensor([

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Borda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants