To fine-tune GPT-2 from human preferences, Ziegler et al. (2019) show a labeler an input and four samples from the language model, and ask which one is best. The reward model is trained so that a softmax over its four scores puts high probability on the sample the human picked:
where is the index the labeler chose. Implement the loss and the model's agreement with the labelers.
choice_probs(rewards)
rewards: array of shape (batch, k), the reward model's scores for each comparison's k samples.four_way_loss(rewards, choices)
choices: integer array of shape (batch,) with the labeler's pick in each row.(loss, accuracy) of Python floats rounded to 4 decimals:
loss: the mean over the batch of of the probability assigned to the chosen sample;accuracy: the fraction of rows where the highest-scored sample (the first one on ties) is the chosen one.k = 2 the same loss is the familiar pairwise one.