An output layer converts a model’s internal representation into the prediction consumed by the next stage. In a scalar reward model, a small linear head maps the final hidden representation of a sequence to one numerical score. Pairwise preference learning then compares the chosen and rejected scores; the loss depends on their difference, not their absolute offset. section 5.1 section 5.9
A typical scalar output pipeline proceeds as follows:
- Run tokenized input through the base language model and request hidden states. section 5.2
- Select one sequence representation, commonly the last non-padding or EOS token, using the attention mask. section 5.2
- Apply a linear layer from the model hidden size to one output unit, producing one scalar per sequence. section 5.2
- Compare scalar outputs for chosen and rejected completions with a sigmoid or log-sigmoid preference loss. section 5.1 section 5.2
The same architectural idea supports different prediction granularities. A standard preference reward model emits one logit for an entire sequence, whereas an outcome reward model applies a scalar head at every token and predicts correctness probabilities for completion tokens. Prompt tokens are masked during training and scoring. section 5.4 section 5.9
Minimal scalar head
Given a base language model with hidden size h, define a head as a linear map from h features to one value. Run chosen and rejected inputs separately, obtain rewards_chosen and rewards_rejected, and optimize -logsigmoid(rewards_chosen - rewards_rejected). section 5.2
import torch.nn as nn rewards_chosen = model(**inputs_chosen) 1 rewards_rejected = model(**inputs_rejected) 2 loss = -nn.functional.logsigmoid(rewards_chosen - rewards_rejected).mean()
The listing connects the scalar output layer directly to pairwise reward-model training. section 5.2





