Mirage Academy ยท RLHF

RLHF course: how human preferences shape language models

You build or tune language models and want to know how human preferences change them. This course follows the pipeline in order: human comparisons, a reward model, policy optimization with PPO, DPO as the direct route, newer group-relative methods, and the ways the whole thing fails.

Open the RLHF courseCompare it with the fine-tuning course

The course

Eight chapters follow the preference pipeline from comparisons to an evaluated model

This Masters level course in English is meant for engineers and product people who build AI features. Watch the intro, then see which chapter covers which stage.

Still from the intro video for the course Reinforcement Learning from Human Feedback
Intro video, 1 min 9 s. Transcript below.
Read the transcript

You build or tune language models, and you want to know how human preferences actually change them. This course takes you from instruction tuning to preference learning, one stage at a time. The course follows the pipeline in order. First you collect human comparisons between two answers. Next you train a reward model on those comparisons. Then you optimise the policy against it with PPO. Finally you evaluate the result and watch for reward hacking. You then compare two routes. PPO trains the policy against a separate reward model. DPO learns directly from preference pairs instead. Chapter six adds newer group-relative methods. In the capstone you run a small preference experiment end to end, from comparisons to an evaluated model. If you want to understand how preferences shape models, start with chapter one.

Open the course: Reinforcement Learning from Human Feedback

Which chapter covers which stage

  1. Start
    • Chapter 1From instruction tuning to preference learning
  2. Collect
    • Chapter 2Collecting human preferences
  3. Reward model
    • Chapter 3Reward models
  4. Optimize
    • Chapter 4Policy optimisation with PPO
    • Chapter 5Direct Preference Optimisation
    • Chapter 6Newer methods and group-relative approaches
  5. Check
    • Chapter 7Reward hacking and evaluation
  6. Build
    • Chapter 8Capstone: a small preference experiment end to end
The intro video of the course, and the eight chapters sorted into the stages of the pipeline.

Chapters 1 and 2

People compare two answers, and the comparison becomes the training signal

Chapter 1 sets out the three stages of classic RLHF and why instruction tuning is not the end. Chapter 2 is about collecting the comparisons, and about how far you can trust them.

An example comparison, invented for this page

PROMPTExplain what a mortgage is to a new customer.

  • Answer APREFERREDA mortgage is a loan you use to buy a home, and the home secures the loan.4 votes
  • Answer BA mortgage is a contractual instrument of secured credit extended under a collateral agreement.1 votes

Annotator agreement, the share who chose the majority answer: 80%

  1. 01

    Pairs versus rankings

    Ask for a choice between two answers, or for a full ranking, and see what each costs.

  2. 02

    Guidelines and agreement

    Write the instructions the labelers follow, and measure how often they agree.

  3. 03

    Labeler biases

    Learn which habits of the people choosing can tilt the comparisons.

  4. 04

    Aggregating noisy labels

    Combine several imperfect judgments into one label.

  5. 05

    Quality control

    Catch labelers and batches that drift before they reach training.

One comparison: a prompt, two answers, and a row of dots for the annotators who chose each one.

Chapter 3

A reward model turns those comparisons into a score for each answer

Chapter 1 introduces preferences as a Bradley-Terry probability, and chapter 3 builds the reward model on it. The model learns scores such that the answer people prefer scores higher.

Example scores, invented for this page

  • Answer Ascore 2
  • Answer Bscore 0.5

Gap between the scores: 1.5

Chance that each answer is preferredAnswer AAnswer B

The rule: the probability that answer A is preferred over answer B is 1 divided by (1 plus e to the power of minus the score gap). It depends on the gap only, and equal scores give 50 percent.

  1. 01

    Reward model architecture

    How a language model becomes a model that outputs a score.

  2. 02

    Training with pairs

    Fit the scores to the comparisons you collected.

  3. 03

    Confidence and calibration

    Check whether a high score means what it should.

  4. 04

    Overoptimization

    See what happens when a policy chases the score too hard.

  5. 05

    Outcome and process rewards

    Reward the final answer, or reward each step.

Two answers with example scores as bars, and below them one bar split into the chance that each is preferred.

Chapter 4

PPO updates the policy, and the clip decides when to stop pushing

PPO scores each token with a clipped objective. Pick a better or a worse token and a ratio, and see when the clip takes over and the gradient goes to zero.

Does the clip stop the push?

The ratios and the two advantages are examples. The clip range is 0.8 to 1.2.

The token was
Ratio of new to old probability

Dotted line: the score by ratio. Faint line: ratio times advantage. Vertical dotted lines: the clip edges at 0.8 and 1.2.

Ratio times advantage
1.40
Clipped ratio times advantage
1.20
Score (the smaller)
1.20
Gradient
Zero

Ratio 1.4, token Better than expected: score 1.20, gradient Zero.

The rule: score = min(ratio x advantage, clip(ratio, 0.8, 1.2) x advantage). The ratio is the new policy's probability of the token divided by the old policy's, and the advantage says whether the token was better or worse than expected. The clipped term is the smaller one only when the ratio has moved past the edge in the direction the advantage likes, and there the gradient is zero.

  1. 01

    RL words for text

    Policy, action and reward, read as language-model terms.

  2. 02

    Advantage

    Whether a token did better or worse than expected.

  3. 03

    The clipped objective

    The rule on this page, with the reasons behind it.

  4. 04

    Four models in memory

    What a PPO run has to hold at once.

  5. 05

    Stability and stop rules

    Know when to halt a run that has gone off course.

An interactive clipped objective: pick a better or worse token and a ratio, and read the two terms, the score and whether the gradient flows.

Chapter 5

DPO learns directly from preference pairs, without a separate reward model

You then compare the two routes. PPO trains the policy against a separate reward model, and DPO learns from the pairs directly.

Both start from human comparisons.

  • PPO route
    1. 01The policy writes an answer.
    2. 02A separate reward model scores it.
    3. 03PPO updates the policy, with the clip as its limit.
    Holds four models in memory
  • DPO route
    1. 01Start from a preference pair.
    2. 02Compare the chosen and the rejected answer, relative to a reference.
    3. 03Update the policy, with beta setting how closely it stays near the reference.
    Learns from the pairs directly
  1. 01

    The DPO loss

    The loss that turns a preference pair into an update.

  2. 02

    The implicit reward

    Why DPO needs no separate reward model.

  3. 03

    What beta does

    The knob that sets how far the policy may move.

  4. 04

    A known failure

    A way DPO goes wrong, and how to spot it.

  5. 05

    DPO or RL

    Choose between the two routes for your case.

Two routes from the same comparisons: PPO with a separate reward model on the left, DPO straight from the pairs on the right.

DPO in a fine-tuning workflow: the fine-tuning course โ†’

Chapter 6

Group-relative methods score each sample against its own group

Chapter 6 covers feedback from AI, group-relative advantage, verifiable rewards and other preference losses. The picture shows the group-relative idea on six samples.

Example rewards, invented for this page. Average reward of the group: 0.5

  1. Sample 1reward 0.2
    -0.3
  2. Sample 2reward 0.9
    +0.4
  3. Sample 3reward 0.4
    -0.1
  4. Sample 4reward 0.7
    +0.2
  5. Sample 5reward 0.5
    0.0
  6. Sample 6reward 0.3
    -0.2

Under each bar: the reward, then the advantage.

In its plain form: a sample's advantage is its reward minus the average reward of its group. A sample above the average gets a positive advantage and one below it a negative one, and the advantages of a group add up to zero.

  1. 01

    AI feedback

    Use a model instead of a person to judge the answers.

  2. 02

    Group-relative advantage

    Compare each sample with the others drawn for the same prompt.

  3. 03

    Verifiable rewards

    Use a reward that a program can check.

  4. 04

    Other preference losses

    Variants of the pair-based loss, and when they apply.

  5. 05

    Choosing

    Pick a method for the data and the budget you have.

Six samples for one prompt: each bar rises above the average line or falls below it by the sample's advantage.

Chapter 7

Reward hacking: the reward keeps rising while the human check turns down

A policy can learn to please the reward model without getting better for people. The chapter shows how to check the proxy against a human check and how to pick the checkpoint.

A drawn shape for illustration, not measured data

Proxy reward from the reward modelHuman checkDotted line: the best checkpoint by the human check

optimization steps, left to right

  1. 01

    Reward hacking

    How a policy finds the gaps in a reward model.

  2. 02

    Proxy versus human check

    Compare the score you optimize with what people say.

  3. 03

    Win rate with ties

    Count the comparisons that end level.

  4. 04

    Is the win rate real

    Ask whether a difference is more than noise.

  5. 05

    Pick a checkpoint

    Choose the run state to keep, and say why.

The proxy reward climbs for the whole run, the human check peaks and then falls, and a dotted line marks the peak.

Chapter 8

The capstone: a small preference experiment end to end

You ask a question, prepare the data, build a toy reward model, test best-of-N and drift, and write the report.

Example rewards, invented for this page

  1. 0.31Sample 1
  2. 0.52Sample 2
  3. 0.44Sample 3
  4. 0.78Sample 4
  5. 0.60Sample 5
  6. 0.39Sample 6
  7. 0.70Sample 7
  8. 0.48Sample 8

Best of eight picks sample 4Average reward: 0.53

  1. The capstone lessons
  2. 01The question
  3. 02The data
  4. 03A toy reward model
  5. 04Best-of-N and drift
  6. 05The report
Eight samples for one prompt as bars, the highest picked in cyan, and under them the five lessons of the capstone chapter.

How you learn

What the coach does and what the certificate is

Lessons come with an Academy AI coach that you talk to by voice.

The AI coach
According to the app it asks follow-up questions and tests your understanding. Notes you save are where the next session picks up.
The certificate
You get a certificate or a confirmation of participation, depending on how you went through the course. The PDF has a verification code that anyone can check on a public page.
The limit
A certificate is not a state-recognized qualification. According to the page about certificates, it is Mirage's own statement of what you achieved in a course.
Three facts: what the coach does, what the certificate is, and where it stops.

How certificates work โ†’

Questions about the RLHF course

  • Who is the RLHF course for?

    Engineers and technical product people who work on AI features and want to understand how preference training changes a model. The level is Masters.

  • What is RLHF?

    Reinforcement learning from human feedback. People compare answers, a reward model learns from the comparisons, and the language model is then optimized against that reward. Chapters 1 to 4 follow these stages.

  • What is the difference between PPO and DPO?

    PPO trains the policy against a separate reward model. DPO learns directly from preference pairs instead. Chapters 4 and 5 teach both, and chapter 5 ends on how to choose between them.

  • What is a reward model?

    A model that gives an answer a score so that the answer people prefer scores higher. Chapter 3 covers its architecture, training on pairs, calibration and overoptimization.

  • What is reward hacking?

    A policy that scores well with the reward model without getting better for people. Chapter 7 covers how to spot it and how to pick a checkpoint.

  • What is the experiment at the end?

    The capstone: a small preference experiment end to end. You ask the question, prepare the data, build a toy reward model, test best-of-N and drift, and write the report.

  • Is the course in English?

    Yes. Everything here is in English, and no German version exists.

  • Do I get a certificate?

    You finish with a certificate or a confirmation of participation, depending on your path. It carries no state recognition.