In Reinforcement Learning from Human Feedback (RLHF), a reward model is trained on pairwise human preference data to assign scalar scores to model responses. Before using the reward model in the RL loop, it is critical to evaluate how well it ranks responses on held-out preference pairs.
Implement a function reward_model_validation that takes arrays of reward scores assigned to chosen (preferred) and rejected responses, along with a list of margin thresholds, and returns a dictionary of validation metrics.
The function should compute the following metrics:
accuracy: the fraction of preference pairs where the chosen response received a strictly higher reward score than the rejected response.mean_margin: the average difference between chosen and rejected scores across all pairs.concordance: similar to accuracy, but ties (where chosen and rejected scores are equal) count as half-correct rather than incorrect.margin_accuracy: a dictionary mapping each given threshold to the fraction of pairs where the reward margin (chosen minus rejected) is greater than or equal to that threshold.All returned float values should be rounded to 4 decimal places.
Args: chosen_scores: 1D numpy array of shape (n,) with reward scores for chosen responses rejected_scores: 1D numpy array of shape (n,) with reward scores for rejected responses margin_thresholds: list of float thresholds for margin-based accuracy
Returns: A dictionary with keys 'accuracy', 'mean_margin', 'concordance', and 'margin_accuracy'.