# Inspect: a pairwise ranking scorer

At the end of this page your [Inspect](https://inspect.aisi.org.uk/) eval will score each output by where it ranks among the sample's reference answers, judged two at a time against a rubric, with a range of places for every text. The score is the share of references the output ranks above: 1.0 when it ranks first, 0.0 when it ranks last.

Inspect scores one sample at a time ([custom scorers](https://inspect.aisi.org.uk/custom-scorers.html)), so the scorer ranks what that sample holds: the model's output and the texts in its `target`. Give each sample one or more reference answers, for example an earlier model's answer and a written one.

## Run the example

You need [uv](https://docs.astral.sh/uv/) and Python 3.10 or later. The scorer ships in the `supposing` package as an extra. In an empty folder, save `pairwise_task.py` below, then:

```sh
uv venv && uv pip install 'supposing[inspect]'
.venv/bin/inspect eval pairwise_task.py --model mockllm/model
```

Both models here are fakes, so nothing is spent: Inspect's `mockllm/model` gives every question the same fixed answer, and Supposing's `mock` judge prefers the text with the higher hidden `[[q=...]]` score (a text without one gets a fixed score from its hash). The run printed:

```text
pairwise_answers (2 samples): mockllm/model
total time:                  0:00:01
mockllm/model                77 tokens [I: 11, O: 66]
pairwise_rank
mean           0.833
stderr         0.167
```

Each sample's explanation, in the log viewer (`inspect view`), holds the ranking:

```text
reference 1 ranks first, but the best could be any of the first 3. (16 judge calls)
1. reference 1 (could be 1-2)
2. output (could be 1-3)
3. reference 2 (could be 1-3)
4. reference 3 (could be 3-4)
```

Here the output ranked second of four, so it scored 2 of 3, 0.67. "Could be 1-3" is its range of places at 90% confidence: after 16 calls the judge cannot yet tell it apart from the best reference. The score's metadata has `rank`, `rank_lo`, `rank_hi`, `judge_calls` and `cost_usd`, for filtering samples whose place is still uncertain.

`pairwise_task.py`:

```python
from inspect_ai import Task, task
from inspect_ai.dataset import Sample
from inspect_ai.solver import generate

from supposing.inspect import pairwise_rank

RUBRIC = "Which answer explains the idea more clearly and correctly to a new programmer?"


@task
def pairwise_answers():
    return Task(
        dataset=[
            Sample(input="What does a hash map do?",
                   target=["It stores values under keys and finds them fast. [[q=0.8]]",
                           "It is a kind of list. [[q=0.2]]"]),
            Sample(input="Why write tests?",
                   target=["So you learn quickly when a change breaks something. [[q=0.9]]",
                           "Because the manager asks for them. [[q=0.1]]",
                           "To make the code longer. [[q=0.05]]"]),
        ],
        solver=generate(),
        scorer=pairwise_rank(RUBRIC, judge="mock"),
    )
```

The same file is in the engine's repository at `examples/inspect/`. In your own task, `from supposing.inspect import pairwise_rank` is all you need.

## Score an existing log by name

Installing the extra registers the scorer with Inspect as `supposing/pairwise_rank`, so you can score a log you already have, without changing its task:

```sh
inspect score logs/my-eval.eval --scorer supposing/pairwise_rank -S rubric="Which answer is clearer and more correct?" -S judge=mock
```

The log's samples need reference answers in their `target`. Each `-S` sets one argument of the scorer, below.

## Use a real judge

There are two ways to choose the judge:

- `judge=` takes a Supposing judge: `"quick"`, `"balanced"`, `"thorough"`, an OpenRouter model id such as `"anthropic/claude-haiku-5.5"` (these need `OPENROUTER_API_KEY`), or `"claude_cli"` for local use ([Choosing a judge](choosing-a-judge.md)).
- `model_role="grader"` uses the Inspect model bound to that role, the same role Inspect's own [model-graded scorers](https://inspect.aisi.org.uk/model-graded.html) use: `inspect eval pairwise_task.py --model <model> --model-role grader=<judge model>`. The judge's calls then use Inspect's model configuration and keys.

Other keyword arguments set the ranking:

| Argument | What it does |
|---|---|
| `rounds` | Opponents per text. Default 8: about 4 judge calls per text, and 8 for 2 or 3 texts. More rounds narrow the ranges |
| `both_orders` | `True` judges every pair in both orders, and adds the order check. Doubles the calls |
| `max_calls` | A hard cap on judge calls per sample, for any judge |
| `max_cost_usd` | A hard cap on recorded spend per sample: no call starts that could pass it. Judges that report no price, such as `claude_cli`, cannot be capped this way |
| `seed` | Pairing and the ranges are deterministic for a given seed. Default 0 |

A sample with an output and three references makes 16 judge calls by default, so 100 such samples make about 1,600. [What a run costs](../concepts/cost.md) turns calls into money.

The explanation also carries the judge checks. A judge that always picked the first text it read scored the output 0.0 in our test and the explanation said: "Treat with care: the judge strongly favoured whichever text it read first (first-shown text wins 100%)". [Judge checks](../concepts/judge-checks.md) says what each check means.

## Why pairs

On four public datasets, comparing items in pairs agreed with human ratings or real outcomes more often than the same model scoring each item alone: 86% against 67% on ELLIPSE essays, 73% against 57% on PERSUADE essays, 77% against 71% on Upworthy headlines and 82% against 76% on UKPConvArg arguments. Pairs made more judge calls than scoring alone in each test. The method and the limits are in [Pairwise comparison or scoring each item](../concepts/pairwise-vs-scoring.md).
