Score a reward model by pairwise preference accuracy
Before using a reward model in RLHF you check it on held-out preference pairs: how often does it score the human-chosen answer above the rejected one? Ties are common with coarse or quantized scores, so they are usually counted as half right.
Write pair_accuracy(r_chosen, r_rejected), two equal-length lists of reward scores. For each pair: chosen > rejected scores 1, a tie scores 0.5, otherwise 0. Return (accuracy, mean_margin) where accuracy is the mean pair score and mean_margin is the mean of r_chosen - r_rejected, both floats.
def pair_accuracy(r_chosen, r_rejected)Example
pair_accuracy([2.0, 1.0, 0.5], [1.0, 1.0, 0.9]) gives (0.5, 0.2).
Understand the idea
A reward model is checked on held-out preference pairs: for each pair a human picked one answer over the other, and we ask whether the model scores the chosen one higher. A tie means the model cannot tell them apart, so it earns half credit rather than zero. The mean margin shows how clearly the model separates the two. Worked example: chosen [3, 1, 2, 0], rejected [1, 1, 2.5, -2]. Pair scores: 3 > 1 gives 1, 1 = 1 gives 0.5, 2 < 2.5 gives 0, 0 > -2 gives 1. Accuracy = 2.5 / 4 = 0.625. Margins: [2, 0, -0.5, 2], mean = 3.5 / 4 = 0.875. Rule: score each pair 1 if chosen > rejected, 0.5 if equal, else 0; accuracy = mean score; mean_margin = mean of (chosen - rejected); both as floats. Counting ties as wrong punishes uncertainty as if it were a wrong preference. This is the first sanity check run on reward models before RLHF or best-of-n sampling.