Labelers rank between 4 and 9 completions of a prompt and may mark some as tied. The reward model is trained on every comparison the ranking implies, with all comparisons of a prompt kept together, and before reinforcement learning its output is shifted by a bias so that the labelers' own demonstrations score 0 on average. Implement the bookkeeping, the loss with ties, and the bias.
A ranking is a best-first list of tie groups, each a list of completion indices: [[2], [0, 3], [1]] means 2 is best, 0 and 3 are tied, 1 is worst.
ranking_comparisons(ranking)
(better, worse) pairs for every two completions in different groups. Order: for each group , for each later group , for each i in group , for each j in group (both in the given order). Tied completions give no comparison.batch_comparison_counts(rankings)
"prompts", "forward_passes" (one reward-model pass per completion), "comparisons" (kept comparisons), "pooled_forward_passes" (two passes per comparison, when every comparison is its own example), "max_comparisons" ( over prompts, with that prompt's number of completions), and "dropped_ties" (max minus kept).ranking_loss(scores, rankings)
scores[p] lists the reward-model scores of prompt 's completions, by completion index. Per prompt, average over its kept comparisons; a prompt with no comparison is left out. Return the mean over the remaining prompts rounded to 4 decimals (0.0 if none). Stay finite for score gaps of .demonstration_bias(demo_scores) returns the bias (a float rounded to 6 decimals) such that demo_scores + b has mean 0.
normalize_rewards(scores, bias) returns scores + bias as a list of floats.