ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing
ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing

All Courses

RLHF: Reinforcement Learning from Human Feedback
Chapter 1: Foundations of RLHF for Language Model Alignment
The AI Alignment Problem in LLMs
Limitations of Supervised Fine-Tuning
Reinforcement Learning Principles Refresher
Introduction to the RLHF Process
Setting Up the Development Environment
Chapter 2: Supervised Fine-Tuning (SFT) Phase
Role of SFT in the RLHF Pipeline
Curating High-Quality SFT Datasets
SFT Implementation Details
Evaluating SFT Model Performance
Hands-on Practical: SFT Execution
Chapter 3: Reward Modeling from Human Preferences
Concept of Learning from Preferences
Human Preference Data Collection
Preference Dataset Formats and Structures
Reward Model Architectures
Training Objectives for Reward Models
Calibration of Reward Models
Potential Issues in Reward Modeling
Hands-on Practical: Training a Reward Model
Chapter 4: RL Fine-Tuning with Proximal Policy Optimization (PPO)
PPO Algorithm for RLHF Context
Policy and Value Network Implementation
The Role of the KL Divergence Penalty
Calculating Advantages and Returns
PPO Hyperparameter Tuning for LLMs
Common PPO Implementation Libraries (TRL)
Troubleshooting PPO Training Instability
Practice: Implementing the PPO Update Step
Chapter 5: Integrating the Full RLHF Pipeline
Workflow Orchestration
Model Loading and Initialization
Generating Responses with the Policy Model
Scoring Responses with the Reward Model
Synchronizing Models During Training
Code Structure for an End-to-End RLHF System
Hands-on Practical: Running a Simplified RLHF Loop
Chapter 6: Advanced RLHF Techniques and Alternatives
Direct Preference Optimization (DPO)
Reinforcement Learning from AI Feedback (RLAIF)
Improving Sample Efficiency in RLHF
Addressing Reward Hacking Explicitly
Multi-Objective Reward Models
Contextual and Conditional RLHF
Practice: Comparing PPO and DPO Concepts
Chapter 7: Evaluation, Analysis, and Deployment
Metrics for Evaluating Aligned Models
Human Evaluation Protocols
Automated Evaluation Suites
Analyzing Policy Shift During RL Tuning
Red Teaming and Safety Testing
Computational Costs and Scalability
Deployment Considerations for RLHF Models
Hands-on Practical: Analyzing RLHF Run Logs

Calibration of Reward Models

Reward models (RM) are trained with an objective, typically based on the Bradley-Terry framework, to effectively learn relative preferences between pairs of responses. However, the raw output scores RM(prompt,response)RM(\text{prompt}, \text{response})RM(prompt,response) from such models do not automatically possess a meaningful scale. The difference between two scores, RM(prompt,response1)−RM(prompt,response2)RM(\text{prompt}, \text{response}_1) - RM(\text{prompt}, \text{response}_2)RM(prompt,response1​)−RM(prompt,response2​), determines the predicted probability P(response1≻response2)P(\text{response}_1 \succ \text{response}_2)P(response1​≻response2​) via the sigmoid function. Yet, does a score difference of 2 represent twice as "strong" a preference as a difference of 1? Not necessarily.

Calibration addresses this issue. A well-calibrated reward model produces scores where the predicted probabilities accurately reflect the true probabilities observed in the human preference data. If the model predicts σ(RM1−RM2)=0.8\sigma(RM_1 - RM_2) = 0.8σ(RM1​−RM2​)=0.8, we expect that for pairs with approximately this score difference, humans indeed preferred response 1 around 80% of the time. Without calibration, the RM might be systematically overconfident (e.g., predicting 0.9 probability when the actual preference rate is only 70%) or underconfident.

Assessing Reward Model Calibration

A standard technique for evaluating calibration is using a reliability diagram (also known as a calibration plot).

  1. Binning: Divide the range of predicted preference probabilities (e.g., [0, 1]) or raw score differences into several bins (e.g., 10 bins).
  2. Calculating Averages: For all preference pairs (yw,yl)(y_w, y_l)(yw​,yl​) falling into a specific bin based on their predicted probability σ(RM(yw)−RM(yl))\sigma(RM(y_w) - RM(y_l))σ(RM(yw​)−RM(yl​)):
    • Calculate the average predicted probability within that bin.
    • Calculate the actual fraction of pairs where ywy_wyw​ was indeed preferred (this should always be 1 by definition if using (yw,yl)(y_w, y_l)(yw​,yl​) pairs, but it's useful if assessing on raw score differences or a separate test set where the outcome isn't fixed by the pair order). A better approach is to compute the average accuracy within the bin: the proportion of pairs correctly classified according to the preference label. For a bin centered around probability ppp, the expected accuracy is ppp.
  3. Plotting: Plot the average observed accuracy (or fraction of positives) against the average predicted probability for each bin.

Perfect calibration corresponds to the y=xy=xy=x line. Deviations indicate miscalibration: points below the line indicate overconfidence (predicted probability > actual accuracy), while points above indicate underconfidence.

Example reliability diagram comparing an uncalibrated model (overconfident at higher probabilities) and a better-calibrated model.

Quantitatively, calibration can be measured using metrics like the Expected Calibration Error (ECE), which computes the weighted average difference between predicted probabilities and observed accuracies across bins.

Techniques for Improving Calibration

If assessment reveals poor calibration, several techniques can be applied:

  1. Temperature Scaling: This is a simple and often effective post-processing method. It involves rescaling the logits (the inputs to the final activation function, in our case, the raw RM scores or their difference) by a learned temperature parameter T>0T > 0T>0. The calibrated probability is calculated as: Pcalibrated(response1≻response2)=σ(RM(prompt,response1)−RM(prompt,response2)T)P_{calibrated}(\text{response}_1 \succ \text{response}_2) = \sigma\left( \frac{RM(\text{prompt}, \text{response}_1) - RM(\text{prompt}, \text{response}_2)}{T} \right)Pcalibrated​(response1​≻response2​)=σ(TRM(prompt,response1​)−RM(prompt,response2​)​) The temperature TTT is optimized on a hold-out validation set of preference pairs. The goal is typically to minimize the negative log-likelihood (NLL) or a calibration metric like ECE on this validation set.

    • If T>1T > 1T>1, it "cools" the logits, softening probabilities and reducing model confidence (correcting overconfidence).
    • If T<1T < 1T<1, it "heats" the logits, sharpening probabilities and increasing confidence (correcting underconfidence).
    • T=1T=1T=1 leaves the probabilities unchanged. Temperature scaling only adjusts the confidence of the predictions without changing the ranking (argmax) of the outputs, making it a safe adjustment.
  2. Label Smoothing: Applied during the initial RM training phase, label smoothing replaces hard targets (0 or 1) with slightly softened targets (e.g., 0.05 and 0.95). This discourages the model from producing extremely high-confidence predictions (pushing logits towards positive or negative infinity) and can implicitly improve calibration.

  3. Isotonic Regression: Another post-processing technique that fits a non-decreasing function to map the model's output probabilities to calibrated probabilities. It's more powerful than temperature scaling but requires more data and can sometimes be less stable.

  4. Data Quality and Diversity: Fundamentally, calibration issues can arise from noisy labels, insufficient data in certain regions of the score space, or a mismatch between the training data distribution and the data encountered later. Improving the quality and diversity of the human preference dataset is always beneficial.

Why Calibration Matters for RL Fine-Tuning

The subsequent RL phase (typically using PPO) relies heavily on the reward signal provided by the RM. The magnitude of the reward r=RM(prompt,response)r = RM(\text{prompt}, \text{response})r=RM(prompt,response) or the advantage calculated using it directly influences the scale of policy updates.

  • Overconfident RM: An overconfident RM might assign excessively high rewards for responses it slightly prefers, leading the RL policy to optimize too aggressively towards specific response types that might only be marginally better, potentially sacrificing diversity or exploring less. It can also cause instability if small changes in generated text lead to large swings in reward.
  • Underconfident RM: An underconfident RM might provide weak reward signals, making it difficult for the RL agent to distinguish meaningfully between good and slightly less good responses, slowing down learning or preventing the policy from reaching optimal alignment.

A well-calibrated RM provides a more reliable and interpretable reward signal. The magnitude of the reward difference between two potential responses better reflects the actual strength of human preference, leading to more stable and effective policy updates during the RL fine-tuning stage. While PPO often involves normalizing advantages, the relative scale of rewards derived from a calibrated model is still beneficial for learning behaviors aligned with human judgments. Therefore, assessing and improving RM calibration is an important step before proceeding to the RL optimization phase.

  • Predicting Good Probabilities with Supervised Learning, Alexandru Niculescu-Mizil, Rich Caruana, 2005 Proceedings of the 22nd International Conference on Machine Learning (ICML) DOI: 10.1145/1102351.1102432 - Classic paper outlining reliability diagrams, expected calibration error, and methods like isotonic regression for probability calibration in machine learning.
  • On Calibration of Modern Neural Networks, Chuan Guo, Geoff Pleiss, Yu Sun, Kilian Q. Weinberger, 2017 Proceedings of the 34th International Conference on Machine Learning (ICML) DOI: 10.48550/arXiv.1706.04599 - Examines calibration issues in deep neural networks and proposes temperature scaling as a simple yet effective post-processing method to improve calibration.

© 2026 ApX Machine Learning