An outcome reward model (ORM) puts a scalar head on a language model that outputs a logit at every token of a completion. The probability estimates how likely the completion is to end with a correct answer. Training uses one binary label per completion (1 = correct). In code the label is copied onto every completion token and prompt (and padding) tokens get the label , which the loss ignores.
The RLHF book gives a per-token loss and a simpler sequence-level form:
with the sequence-level loss being the binary cross-entropy (BCE) between and . Implement both and the inference-time aggregation.
orm_token_labels(prompt_len, completion_len, outcome, pad_len=0)
-100 for the prompt, outcome for each completion token, -100 for the padding.orm_token_loss(logits, labels)
logits, labels: arrays of the same shape ((batch, seq_len) or 1-D). Return the mean BCE over all unmasked positions in the batch (label not -100), as a float rounded to 4 decimals. If no position is unmasked, return 0.0.orm_pooled_loss(logits, labels)
0.0 if there are none).aggregate_correctness(probs, method, m=None)
probs: 1-D per-token probabilities of the completion tokens. method is "mean", "min", "product" or "last" (mean of the last m tokens, or of all tokens if m exceeds the length); anything else raises ValueError. Return a float rounded to 4 decimals.