PIXELBANKv9.1.0
Menu

Evaluate a reward model's pairwise ranking accuracy.

Given N preference pairs with true labels and predicted reward scores, compute:

  1. The fraction of pairs where the model correctly ranks chosen > rejected
  2. The average margin (r_chosen - r_rejected) for correct predictions
  3. The average margin for incorrect predictions

Input:

  • Line 1: N
  • Next N lines: r_chosen r_rejected (predicted rewards for the chosen and rejected responses)

A prediction is correct if r_chosen > r_rejected.

Output:

  • Line 1: Accuracy (fraction correct), rounded to 4 decimal places
  • Line 2: Average margin for correct predictions, rounded to 4 decimal places (or 0.0000 if none)
  • Line 3: Average margin for incorrect predictions, rounded to 4 decimal places (or 0.0000 if none)

Example:

Input:
4
2.0 1.0
1.5 2.5
3.0 0.0
0.5 0.5
Output:
0.5000
2.0000
-0.7500
Reasoning:
  • The input contains 4 pairs of predicted rewards, which are evaluated to determine the correctness of each pair:
    • Pair 1: 2.0>1.02.0 > 1.0, correct
    • Pair 2: 1.5<2.51.5 < 2.5, incorrect
    • Pair 3: 3.0>0.03.0 > 0.0, correct
    • Pair 4: 0.5=0.50.5 = 0.5, incorrect (since rchosen≯rrejectedr_{chosen} \ngtr r_{rejected})
  • The accuracy is calculated as the fraction of correct pairs: 24=0.5\frac{2}{4} = 0.5
  • The average margin for correct predictions is calculated: (2.0−1.0)+(3.0−0.0)2=1.0+3.02=4.02=2.0\frac{(2.0-1.0) + (3.0-0.0)}{2} = \frac{1.0 + 3.0}{2} = \frac{4.0}{2} = 2.0
  • The average margin for incorrect predictions is calculated: (1.5−2.5)+(0.5−0.5)2=−1.0+0.02=−1.02=−0.5\frac{(1.5-2.5) + (0.5-0.5)}{2} = \frac{-1.0 + 0.0}{2} = \frac{-1.0}{2} = -0.5, but since there are two incorrect pairs and one has a margin of 0, the actual calculation is −1.01=−1.0\frac{-1.0}{1} = -1.0 for the non-zero margin, and then considering the equal rewards pair, it results in −1.0+02=−0.5\frac{-1.0 + 0}{2} = -0.5, however the provided output suggests considering only the non-zero margin pair and another incorrect pair with a margin, hence −1.01=−1.0\frac{-1.0}{1} = -1.0 is not the correct calculation and (1.5−2.5)1=−1.0\frac{(1.5-2.5)}{1} = -1.0 and the other incorrect pair has 0.5−0.5=00.5-0.5=0, but the output −0.75-0.75 implies −1.0+(−0.5)2=−1.52=−0.75\frac{-1.0+(-0.5)}{2} = \frac{-1.5}{2} = -0.75 which matches the given output when considering both incorrect pairs have non-zero margins or one of them has a margin of −0.5-0.5 which is not the case, so the provided calculation in this step might be incorrect and the

Constraints:

  • 1 <= N <= 100
  • If r_chosen == r_rejected, count as incorrect
  • Round to 4 decimal places
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Pairwise Ranking Accuracy - Medium | PixelBank