Bring the mental model from Maximum Likelihood; this page will reuse it instead of restarting from zero.
RLHF: Reward Modeling + KL-Regularized Policy Optimization
RLHF trains a reward model from pairwise preferences, then reweights a reference policy toward high learned reward while a KL penalty limits distribution shift.
01
Intuition
Build the mental picture first so the rest of the page has something to attach to.
Canonical sources: Christiano et al., "Deep Reinforcement Learning from Human Preferences", and Ouyang et al., "Training language models to follow instructions with human feedback".
A pretrained or supervised-finetuned language model gives a distribution over completions. In InstructGPT-style RLHF, the reference policy is often the supervised-finetuned model trained from demonstrations. RLHF asks:
When humans prefer one completion over another, how should that preference move probability mass?
The mechanism has two stages.
First, train a reward model from comparisons. It does not learn an absolute moral score; it learns differences that make preferred completions more likely under a pairwise preference model.
Second, optimize a policy against that learned reward while penalizing movement away from a reference model. In the finite-action picture:
RLHF multiplies the reference probability of each completion by an exponential reward bonus, then renormalizes.
High reward pulls probability upward. The KL penalty controls how far the new policy may drift. If the reward model is a proxy with exploitable errors, optimizing too aggressively can move probability mass toward outputs that score well under the proxy but are worse under the real target.
Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.
02
Math
Translate the story into symbols, assumptions, and a derivation you can inspect.
The two moving pieces are the preference-trained reward gap and the KL-shaped policy update:
The rest of this section unpacks those two witnesses.
Preference data and reward-model likelihood
Let a preference datum be (x,yw,yℓ), where yw is preferred to yℓ for prompt x. Define the reward gap
A reward model rϕ(x,y)∈R predicts
The negative log-likelihood is
where
Only reward differences inside the same prompt are observed. Therefore rϕ(x,y)+c(x) gives the same pairwise probabilities as rϕ(x,y).
Reward scale also needs a convention. With a fixed logistic noise model, reward gaps are measured in that model's log-odds units. With perfectly separable hard preferences, an unregularized reward model can drive gaps toward infinity. Practical systems therefore normalize, regularize, or otherwise choose a usable reward scale before policy optimization.
KL-regularized policy optimization
For a fixed prompt x, reference policy πref, and candidate policy π, define expected reward
and the KL term
The RLHF objective is
Equivalently, if
then
Assume πref(y∣x)>0 on the candidate support. Optimize Jx over the finite distribution π(⋅∣x) subject to ∑yπ(y∣x)=1. The Lagrange stationarity condition is
Solving for π(y∣x) and normalizing gives
Here
Larger β keeps the policy closer to the reference. Smaller β lets learned reward dominate.
Rearranging gives the bridge to DPO:
The final term depends only on the prompt, so it cancels in preference differences.
PPO is the optimizer, not the definition
In language-model RLHF, the candidate space is enormous. InstructGPT-style RLHF uses PPO to optimize the learned reward with a KL penalty to the supervised-finetuned or reference model. The clean finite-action formula above is the exact optimum of a finite-action regularized objective. PPO is a stochastic optimizer for the language-model version; it is not this closed-form update, and a parametric policy with per-token KL details need not trace the toy optimum exactly.
Reward hacking
If rϕ(x,y) differs from the real target u(x,y), then low β can concentrate the policy on outputs with high proxy reward and low true utility. KL regularization reduces this pressure but does not make the proxy correct.
Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.
03
Code
Keep the implementation aligned with the notation so the algorithm is legible.
This witness keeps the pieces visible: pairwise reward-model fitting, reward-shift invariance, and the KL-regularized policy that reweights a reference distribution.
import numpy as np
def sigmoid(z):
return 1.0 / (1.0 + np.exp(-z))
def softmax(logits):
logits = logits - logits.max()
e = np.exp(logits)
return e / e.sum()
# One prompt, four candidate completions.
# Shape: rewards, pi_ref, pi_star are all (K,).
pairs = np.array([
[0, 1],
[0, 2],
[2, 1],
[3, 1],
[0, 3],
])
K = 4
r = np.zeros(K)
lr = 0.3
l2 = 0.05
for _ in range(800):
grad = l2 * r
for winner, loser in pairs:
margin = r[winner] - r[loser]
p = sigmoid(margin)
g = p - 1.0
grad[winner] += g
grad[loser] -= g
r -= lr * grad / len(pairs)
r -= r.mean() # choose one representative of the shift-equivalence class
pi_ref = np.array([0.35, 0.30, 0.20, 0.15])
beta = 0.7
def kl_regularized_policy(reward):
logits = np.log(pi_ref) + reward / beta
return softmax(logits)
pi_star = kl_regularized_policy(r)
pi_shifted = kl_regularized_policy(r + 10.0)
kl = np.sum(pi_star * (np.log(pi_star) - np.log(pi_ref)))
print("learned reward representative:", np.round(r, 3))
print("reference policy: ", np.round(pi_ref, 3))
print("KL-regularized policy: ", np.round(pi_star, 3))
print("KL(pi* || pi_ref): ", round(float(kl), 4))
assert np.allclose(pi_star, pi_shifted)
Adding a constant to every reward changes neither pairwise preference probabilities nor the KL-regularized policy. The policy depends on reward differences and on how strongly β anchors it to the reference.
Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.
04
Interactive Demo
Use direct manipulation to connect the explanation to a moving system.
Live Concept Demo
Explore RLHF: Reward Modeling + KL-Regularized Policy Optimization
The stage is code-native and interactive. Use it to test the explanation against the mechanism.
Manipulate one control and predict the visible change.
Choose what to inspect in RLHF: Reward Modeling + KL-Regularized Policy Optimization. This shared fallback is an observation guide, not evidence of learning.
Use the demo as a probability-shaping machine. Change β, toggle a proxy reward gap, and add a reward shift. Watch the reference policy get reweighted, and notice that shifting every reward leaves the policy unchanged.
Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.
Concept: RLHF: Reward Modeling + KL-Regularized Policy Optimization
What is the smallest example that makes RLHF: Reward Modeling + KL-Regularized Policy Optimization click without losing the math?
Object contextAlignment
concept:alignment/rlhfRLHF: Reward Modeling + KL-Regularized Policy Optimization
What is the smallest example that makes RLHF: Reward Modeling + KL-Regularized Policy Optimization click without losing the math?
Start with the prediction checkpoint, then compare the reveal to the mental model.
Take this moveStudy modes
Keep the object fixed; change the lens.Route back through the notebook
Carry the same object through intuition, math, code, and demo.
RLHF trains a reward model from pairwise preferences, then reweights a reference policy toward high learned reward while a KL penalty limits distribution shift.
The next edge should feel earned: use the demo prediction here before following Direct Preference Optimization.
After The First Pass
Turn the concept into an inspected object.
The lower panels are one second act: keep the object fixed, inspect it visually, check source boundaries, practice transfer, then attach the research question.Mechanism Storyboard
See the idea move before the page explains it
RLHF trains a reward model from pairwise preferences, then reweights a reference policy toward high learned reward while a KL penalty limits distribution shift.

Start with the picture, metaphor, or geometric mechanism.
Before reading further, choose the kind of change RLHF: Reward Modeling + KL-Regularized Policy Optimization should make visible.
Visual Inquiry
Make the image answer a mathematical question
RLHF trains a reward model from pairwise preferences, then reweights a reference policy toward high learned reward while a KL penalty limits distribution shift.
Which visible object should carry the first intuition?
Pick the cue that should make RLHF: Reward Modeling + KL-Regularized Policy Optimization easier to reason about before the page gives the answer.
Source Grounding
Canonical references for the mechanism on this page.
What is the smallest example that makes RLHF: Reward Modeling + KL-Regularized Policy Optimization click without losing the math?
concept:alignment/rlhfsources: christiano-2017-human-preferences, ouyang-2022-instructgpt
Open the closest source note before trusting the local explanation.
2 selected-object sources shown first; 2 references total.
Audit the claim boundary, then ask from the same selected object.
Grounds preference-labeled reward models as a way to train behavior from comparative human feedback.
Christiano trains a reward predictor from trajectory-segment comparisons and optimizes a policy on predicted reward. Ouyang describes demonstrations -> SFT, rankings -> reward model, and...
Reviews only preference-modeling and KL-regularized optimization mechanics. It does not certify reward as true human objective, PPO exact attainment of the finite-action optimum, PPO-ptx/...
Grounds the modern instruction-following RLHF pipeline: demonstrations, preference rankings, reward model, and PPO.
Christiano trains a reward predictor from trajectory-segment comparisons and optimizes a policy on predicted reward. Ouyang describes demonstrations -> SFT, rankings -> reward model, and...
Reviews only preference-modeling and KL-regularized optimization mechanics. It does not certify reward as true human objective, PPO exact attainment of the finite-action optimum, PPO-ptx/...
Claim Review
RLHF trains a reward model from pairwise preferences, then reweights a reference policy toward high learned reward while a KL penalty limits distribution shift.
What is the smallest example that makes RLHF: Reward Modeling + KL-Regularized Policy Optimization click without losing the math?
concept:alignment/rlhfsources: christiano-2017-human-preferences, ouyang-2022-instructgpt
Treat every claim as provisional until source support and a local witness agree.
1 structured claim check on this concept.
Run the prediction or practice transfer before asking for a grounded review.
Publisher-side editorial review is not independent replication. Claims without it still need exact source-support review. 2 references and 3 local witnesses are available for inspection.
Christiano trains a reward predictor from trajectory-segment comparisons and optimizes a policy on predicted reward. Ouyang describes demonstrations -> SFT, rankings -> reward model, and PPO against RM rewar...
Reviews only preference-modeling and KL-regularized optimization mechanics. It does not certify reward as true human objective, PPO exact attainment of the finite-action optimum, PPO-ptx/pretraining-gradient...
Christiano supports learning a reward predictor from pairwise trajectory preferences and optimizing a policy on predicted reward. Ouyang supports InstructGPT demonstrations -> SFT, rankings -> RM, and PPO against RM with per-token KL to SFT. Local math/code/demo are toy witnesses for sigmoid preferences, KL probability shaping, shift invariance, and proxy-gap caveats.
Reviewer: codex+oracle; reviewed 2026-05-07Practice notebook
Use the idea, then test it somewhere new
RLHF trains a reward model from pairwise preferences, then reweights a reference policy toward high learned reward while a KL penalty limits distribution shift.
What is the smallest example that makes RLHF: Reward Modeling + KL-Regularized Policy Optimization click without losing the math?
concept:alignment/rlhfsources: christiano-2017-human-preferences, ouyang-2022-instructgpt
Use one state from RLHF: Reward Modeling + KL-Regularized Policy Optimization to explain what changes, why it changes, and which assumption the explanation needs.
No learner move yet; no learning state is inferred.
Write first, use only the help you need, then try a new case without it.
Use one state from RLHF: Reward Modeling + KL-Regularized Policy Optimization to explain what changes, why it changes, and which assumption the explanation needs.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Reveal when your model needs a nudge.
Write an attempt before asking the companion.
0 of 3 progressive hints opened.
This draft and any AI response do not establish mastery; a later unassisted case can.
- ObjectConceptRLHF: Reward Modeling + KL-Regularized Policy Optimization
- PredictBefore revealRLHF: Reward Modeling + KL-Regularized Policy Optimization prediction
- WitnessCompare codeRLHF: Reward Modeling + KL-Regularized Policy Optimization code witne...
- RoomAsk groundedChecking local snapshot
Research Room
Attach the question to an exact object
Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.Open the draft below to save one note and next action in this browser.
RLHF: Reward Modeling + KL-Regularized Policy Optimization
What is the smallest example that makes RLHF: Reward Modeling + KL-Regularized Policy Optimization click without losing the math?
These are fixed, deterministic perspectives derived from the selected object. They do not represent people, community contributions, or independent review.
Source ids christiano-2017-human-preferences, ouyang-2022-instructgpt must support the exact object, not just the surrounding topic.
Treat this as a mechanism object: connect the definition to one equation, code witness, or demo before broadening the discussion.
Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo.
The learner can state the mechanism in their own words
Local action draftNo local draft saved yetExpand only when ready to capture one local next action
This draft stays locally in this browser for concept:alignment/rlhf.
- Source ids to inspect: christiano-2017-human-preferences, ouyang-2022-instructgpt
- Definition, prerequisite, and contrast concept links
- The equation or code witness that makes the concept operational
- One demo state that shows the invariant instead of a slogan
- The learner can state the mechanism in their own words
- The learner can name the prerequisite that would repair confusion
- The learner can predict how the mechanism changes under one perturbation
I am working in Continuous Function's research reading room. Object: concept - RLHF: Reward Modeling + KL-Regularized Policy Optimization Object key: concept:alignment/rlhf Context: Alignment Anchor id: concept/concept-notebook/alignment/rlhf Open question: What is the smallest example that makes RLHF: Reward Modeling + KL-Regularized Policy Optimization click without losing the math? Evidence to inspect: - Source ids to inspect: christiano-2017-human-preferences, ouyang-2022-instructgpt - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan Deterministic role lenses for this object: - Boundary: fixed perspectives, not people, community contributions, or independent review - Source-checking summary: Treat this as a mechanism object: connect the definition to one equation, code witness, or demo before broadening the discussion. - Proposed experiment: Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo. - Teach/transfer move: Turn the mechanism into one sentence that predicts a neighboring concept. - Assumptions: - Source ids christiano-2017-human-preferences, ouyang-2022-instructgpt must support the exact object, not just the surrounding topic. - The stable content-object key lets local drafts, prompts, and route memory attach without changing the source page. - The concept explanation is local atlas prose until checked against its math, code, and source support. - Prerequisite gaps should become a repair route, not a reason to leave the object vague. - Role-lens requests: - Learner: ask for "Ask what would make "RLHF: Reward Modeling + KL-Regularized Policy Optimization" feel predictable rather than familiar." | assumption: Source ids christiano-2017-human-preferences, ouyang-2022-instructgpt must support the exact object, not just the surrounding topic. | next action: The learner can state the mechanism in their own words - Researcher: ask for "Source ids to inspect: christiano-2017-human-preferences, ouyang-2022-instructgpt" | assumption: The stable content-object key lets local drafts, prompts, and route memory attach without changing the source page. | next action: The learner can name the prerequisite that would repair confusion - Experimenter: ask for "Choose one variable or condition to perturb before asking for an explanation." | assumption: The concept explanation is local atlas prose until checked against its math, code, and source support. | next action: The learner can predict how the mechanism changes under one perturbation - Professor: ask for "Find the smallest transferable rule a learner could reuse without the AI." | assumption: Prerequisite gaps should become a repair route, not a reason to leave the object vague. | next action: Teach or transfer: Turn the mechanism into one sentence that predicts a neighboring concept. What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action. Current deterministic role lens for this object: - Role lens: Learner - Evidence request: Ask what would make "RLHF: Reward Modeling + KL-Regularized Policy Optimization" feel predictable rather than familiar. - Assumption to keep visible: Source ids christiano-2017-human-preferences, ouyang-2022-instructgpt must support the exact object, not just the surrounding topic. - Proposed experiment: Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo. - Next action: The learner can state the mechanism in their own words
concept/concept-notebook/alignment/rlhf
concept:alignment/rlhf