# Multilabelrankingloss

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

- Skill: `qhjqhj00/multilabelrankingloss` (Agent Skill)
- Install (CLI): `npx skillmds add qhjqhj00/multilabelrankingloss`
- Raw SKILL.md: https://api.skillmd.com/api/skills/qhjqhj00/multilabelrankingloss/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: qhjqhj00 (https://skillmd.com/u/qhjqhj00)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/qhjqhj00/multilabelrankingloss

---


# multilabelrankingloss

> Metric `MultilabelRankingLoss` from `torchmetrics` (torchmetrics.classification.MultilabelRankingLoss)

## When to invoke this skill

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

## Reference signature

```python
from torchmetrics.classification import MultilabelRankingLoss

# MultilabelRankingLoss(num_labels: int, ignore_index: Optional[int] = None, validate_args: bool = True, **kwargs: Any) -> None
```

## Library docstring

```
Compute the label ranking loss for multilabel data [1].

The score is corresponds to the average number of label pairs that are incorrectly ordered given some predictions
weighted by the size of the label set and the number of labels not in the label set. The best score is 0.

As input to ``forward`` and ``update`` the metric accepts the following input:

- ``preds`` (:class:`~torch.Tensor`): A float tensor of shape ``(N, C, ...)``. Preds should be a tensor
  containing probabilities or logits for each observation. If preds has values outside [0,1] range we consider
  the input to be logits and will auto apply sigmoid per element.
- ``target`` (:class:`~torch.Tensor`): An int tensor of shape ``(N, C, ...)``. Target should be a tensor
  containing ground truth labels, and therefore only contain {0,1} values (except if `ignore_index` is specified).

.. tip::
   Additional dimension ``...`` will be flattened into the batch dimension.

As output to ``forward`` and ``compute`` the metric returns the following output:

- ``mlrl`` (:class:`~torch.Tensor`): A tensor containing the multilabel ranking loss.

Args:
    preds: Tensor with predictions
    target: Tensor with true labels
    num_labels: Integer specifying the number of labels
    ignore_index:
        Specifies a target value that is ignored and does not contribute to the metric calculation
    validate_args: bool indicating if input arguments and tensors should be validated for correctness.
        Set to ``False`` for faster computations.

Example:
    >>> from torch import rand, randint
    >>> from torchmetrics.classification import MultilabelRankingLoss
    >>> preds = rand(10, 5)
    >>> target = randint(2, (10, 5))
    >>> mlrl = MultilabelRankingLoss(num_labels=5)
    >>> mlrl(preds, target)
    tensor(0.4167)
```

## Quick recipe

```python
import torchmetrics.classification as _m
score = _m.MultilabelRankingLoss(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)`.

