Lesson 18.4 · 4 of 5 · 4 min read · Reviewed 24 Nov 2026
Pairwise comparison and position bias
By the end, you can
- Use pairwise comparison to choose between versions.
- Control for position bias.
Why pairwise
“Is this answer a 7 or an 8?” is hard to answer consistently. “Is A or B better for this customer?” is easier, for people and for models. Pairwise comparison is useful when choosing between two prompts or models.
The setup
for each case:
run version A and version B
judge(input, first=A, second=B) -> winner
judge(input, first=B, second=A) -> winner
count as a win only if both orders agree; otherwise a tie
Biases to control
| Bias | Control |
|---|---|
| Position: favours first (or second) | Swap order, require agreement |
| Length: favours longer | Tell the judge length isn’t a merit; check win rate against length difference |
| Self-preference: favours its own style | Use a different grader model, or calibrate (18.3) |
| Label leakage: “new version” | Hide which is which; call them Response 1 and 2 |
Reporting
Report wins, losses and ties, with a rough confidence range. “B wins 58%, loses 30%, ties 12% over 200 cases” says much more than “B is better”.
Use it alongside criteria
Pairwise tells you which is preferred, not why, and not whether either is good enough. Keep your must-pass criteria checks too.
Key points
- Pairwise grading asks 'which of these two answers is better?', which is often easier and more consistent than absolute scores.
- Model judges often favour the answer shown first (position bias), or the longer one.
- Run each pair twice with the order swapped, and count a win only when both orders agree.
Run a swapped-order pairwise tally
Count pairwise wins only when a judge agrees with itself in both orders, so position bias becomes ties.
You will have: A tally of wins, losses and ties for version B against version A over six cases.
Steps
- Read the simulated judge: it prefers the first answer unless the other is clearly better.
- For each case, judge (A, B) and then (B, A).
- Count a win only when both orders pick the same version; otherwise count a tie.
- Compare with the naive tally that uses only one order.
Done when
- The naive tally (A always first) shows A winning most cases.
- The swapped tally prints B wins 2, A wins 1, ties 3.
Open in the Playground No API key needed.
Starter code (Python)
# Quality scores are hidden from the judge in real life; here they drive a biased toy judge.
CASES = [("c1", 6, 9), ("c2", 7, 7), ("c3", 8, 5), ("c4", 5, 6), ("c5", 4, 8), ("c6", 7, 8)]
def judge(first, second):
"""Returns 'first' or 'second'. Biased: the first answer wins unless the second is 2+ points better."""
return "second" if second - first >= 2 else "first"
naive = {"A": 0, "B": 0}
for cid, a, b in CASES:
naive["A" if judge(a, b) == "first" else "B"] += 1
print("naive (A always first):", naive)
tally = {"B wins": 0, "A wins": 0, "ties": 0}
for cid, a, b in CASES:
# TODO: winner_1 from judge(a, b), winner_2 from judge(b, a), mapped to "A" or "B"
# TODO: count a win only if both agree, else a tie
pass
print(f"B wins {tally['B wins']}, A wins {tally['A wins']}, ties {tally['ties']}")
Show a solution
CASES = [("c1", 6, 9), ("c2", 7, 7), ("c3", 8, 5), ("c4", 5, 6), ("c5", 4, 8), ("c6", 7, 8)]
def judge(first, second):
"""Returns 'first' or 'second'. Biased: the first answer wins unless the second is 2+ points better."""
return "second" if second - first >= 2 else "first"
naive = {"A": 0, "B": 0}
for cid, a, b in CASES:
naive["A" if judge(a, b) == "first" else "B"] += 1
print("naive (A always first):", naive)
tally = {"B wins": 0, "A wins": 0, "ties": 0}
for cid, a, b in CASES:
w1 = "A" if judge(a, b) == "first" else "B"
w2 = "B" if judge(b, a) == "first" else "A"
if w1 == w2:
tally[f"{w1} wins"] += 1
else:
tally["ties"] += 1
print(cid, "A first:", w1, "| B first:", w2, "->", w1 if w1 == w2 else "tie")
print(f"B wins {tally['B wins']}, A wins {tally['A wins']}, ties {tally['ties']}")