In Direct Preference Optimization (DPO), the implicit reward for a response is defined as the log-probability ratio between the trained policy model and a frozen reference model, scaled by a temperature parameter beta.
Given the sum of log-probabilities (over response tokens) of a chosen response and a rejected response under both a policy model and a reference model, compute the implicit rewards for both responses.
The implicit reward is defined as:
Write a function dpo_rewards(policy_chosen_logps, policy_rejected_logps, ref_chosen_logps, ref_rejected_logps, beta) that takes four floats (or numpy arrays of equal shape) of summed log-probabilities and a float beta, and returns a tuple (chosen_reward, rejected_reward) as Python floats (or lists if inputs are arrays), rounded to 4 decimal places only in tests (do not round in your solution).
If inputs are numpy arrays, return numpy arrays converted via .tolist(). If inputs are scalars, return scalar floats.