Retrievalmrr

Compute the RetrievalMRR metric — provided by torchmetrics. Use when the user has predictions and ground-truth and needs to compute RetrievalMRR, or asks how to score with RetrievalMRR.

qhjqhj00 b23bc0e 1.4 KB Updated 3 repo stars

File contents

retrievalmrr

Metric RetrievalMRR from torchmetrics (torchmetrics.RetrievalMRR)

When to invoke this skill

The user has predictions + ground truth and asks to evaluate with RetrievalMRR, or mentions torchmetrics.RetrievalMRR directly, or wants the standard torchmetrics implementation.

Reference signature

from torchmetrics import RetrievalMRR

# _RetrievalMRR(empty_target_action: str = 'neg', ignore_index: Optional[int] = None, **kwargs: Any) -> None

Library docstring

Wrapper for deprecated import.

>>> from torch import tensor
>>> indexes = tensor([0, 0, 0, 1, 1, 1, 1])
>>> preds = tensor([0.2, 0.3, 0.5, 0.1, 0.3, 0.5, 0.2])
>>> target = tensor([False, False, True, False, True, False, True])
>>> mrr = _RetrievalMRR()
>>> mrr(preds, target, indexes=indexes)
tensor(0.7500)

Quick recipe

import torchmetrics as _m
score = _m.RetrievalMRR(y_true, y_pred)

Don'ts

  • Don't reimplement when the library version handles edge cases (NaN, ties, empty inputs) better than a hand-rolled formula.
  • Always check the library version's argument order — sklearn is (y_true, y_pred) while torchmetrics is (preds, target).

qhjqhj00/research-skills-pool/tree/main/skill-factory/output/retrievalmrr commit b23bc0ec3f

Frequently asked questions

npx skillmds add qhjqhj00/retrievalmrr