4.4.5Alignment, Prompting & RAG

Constitutional AI overview

2,152 words10 min readdifficulty · medium3 backlinks

WHAT is Constitutional AI (CAI)?

The problem it solves: standard RLHF (Reinforcement Learning from Human Feedback) needs humans to rank model outputs, including harmful ones. That is:

  • Expensive (many labels),
  • Psychologically harmful to labelers (reading toxic content),
  • Opaque (the "values" live only in the label distribution, not written anywhere).

CAI replaces most of that human labeling with the model judging itself against stated principles.


The two stages (this is the 80/20 core — learn this cold)

CAI has two phases. Say them out loud before reading on.

Stage 1 — Supervised Learning (SL) via self-critique

HOW (the loop):

  1. Prompt the model with a (possibly harmful) query → get an initial response.
  2. Ask the model: "Critique this response according to principle P." (P sampled from the constitution).
  3. Ask the model: "Now revise the response to remove that problem."
  4. Optionally repeat critique→revise a few times.
  5. Collect the final revised (prompt → good response) pairs.
  6. Fine-tune the base model on these pairs → we get the SL-CAI model.

This bakes the constitution's behavior directly into the weights.

Stage 2 — RL from AI Feedback (RLAIF)

HOW:

  1. Take the SL-CAI model; sample two responses to a prompt.
  2. Feed both to an AI "judge" model with a principle: "Which response better follows principle P?"
  3. The judge's choice becomes a preference pair.
  4. Train a preference (reward) model rθr_\theta on these AI-generated comparisons.
  5. Optimize the policy with RL (PPO) against rθr_\theta → final RL-CAI model.
Figure — Constitutional AI overview

WHY write it as a formula? Deriving the RLAIF objective from scratch

We never "just dump" the loss. Let's build it.

Step 1 — What does the judge give us? For a prompt xx and two responses y1,y2y_1,y_2, the judge picks a winner ywy_w and loser yly_l.

Why this step? We need a numeric target from a categorical choice, so we model "how often is ywy_w preferred" as a probability.

Step 2 — Model preference with a reward function. Assume each response has a hidden quality score rθ(x,y)r_\theta(x,y). The probability the judge prefers ywy_w over yly_l follows the Bradley–Terry model:

P(ywylx)=erθ(x,yw)erθ(x,yw)+erθ(x,yl)=σ ⁣(rθ(x,yw)rθ(x,yl))P(y_w \succ y_l \mid x) = \frac{e^{r_\theta(x,y_w)}}{e^{r_\theta(x,y_w)}+e^{r_\theta(x,y_l)}} = \sigma\!\big(r_\theta(x,y_w)-r_\theta(x,y_l)\big)

Why this step? Higher score ⇒ more likely preferred; the logistic σ\sigma turns a score difference into a probability in [0,1][0,1].

Step 3 — Fit rθr_\theta by maximum likelihood (minimize negative log-likelihood over the AI-labeled dataset D\mathcal D):

Why this step? Maximizing the probability of the observed choices = minimizing log-\log of them.

Step 4 — Optimize the policy πϕ\pi_\phi to earn high reward without drifting too far from the reference model πref\pi_{\text{ref}} (the SL-CAI model):

Why the KL term? Without it the policy would "hack" the reward and produce degenerate text. The KL leash keeps it fluent and on-distribution; β\beta controls the leash length.


Worked examples


Common mistakes (Steel-man → fix)


Active recall

Recall What are the two stages of CAI? (think, then reveal)
  1. SL stage: model critiques + revises its own answers against the constitution; fine-tune on the revisions. 2) RL stage (RLAIF): AI judge produces preference pairs → train reward model → PPO with KL penalty.
Recall Where does human labor go in CAI vs RLHF?

RLHF: humans rank outputs (incl. harmful ones). CAI: humans write the constitution; AI does the per-example feedback.

Recall Why is the KL term in the RL objective essential?

It keeps the policy close to the reference model, preventing reward hacking and degenerate/repetitive text while still maximizing reward.

Recall (Feynman, explain to a 12-year-old)

Imagine a kid writes a rude answer to a homework question. Instead of a teacher correcting every single answer, you give the kid a small rulebook ("be kind, be honest, don't help cheating"). The kid learns to read their own answer, spot what breaks a rule, and rewrite it nicely. Do this thousands of times and the kid just naturally writes good answers. Later, when unsure between two answers, the kid uses the rulebook to pick the better one and learns from that too. That's Constitutional AI — the AI grades itself using a small set of written rules.



Connections

What does the "constitution" in Constitutional AI consist of?
A small set of written natural-language principles the model uses to critique/judge responses during training.
What are the two phases of CAI?
(1) Supervised self-critique + revision fine-tuning (SL-CAI), (2) RL from AI Feedback (RLAIF) with a reward model + PPO.
What does RLAIF stand for and how does it differ from RLHF?
Reinforcement Learning from AI Feedback; preference labels come from an AI judge applying a principle instead of from humans.
Write the Bradley–Terry preference probability for two responses.
P(ywyl)=σ(rθ(x,yw)rθ(x,yl))P(y_w \succ y_l)=\sigma(r_\theta(x,y_w)-r_\theta(x,y_l)).
What is the reward-model loss in CAI?
E[logσ(rθ(x,yw)rθ(x,yl))]-\mathbb{E}[\log\sigma(r_\theta(x,y_w)-r_\theta(x,y_l))] over AI-labeled preference pairs.
Why include a KL penalty in the RL objective?
To keep the policy near the reference model, preventing reward hacking and degenerate text.
In Stage 1, what two operations transform a bad answer into training data?
Critique (name the principle violation) then Revise (fix it), optionally repeated.
Does CAI eliminate humans?
No — humans write the constitution and prompts; AI generates the per-example feedback.
If r(x,yw)=2.0r(x,y_w)=2.0, r(x,yl)=0.5r(x,y_l)=0.5, what is P(ywyl)P(y_w\succ y_l)?
σ(1.5)0.82\sigma(1.5)\approx 0.82.
Is the underlying RL algorithm different in RLAIF vs RLHF?
No — same Bradley–Terry + PPO+KL machinery; only the label source (AI vs human) differs.

Concept Map

too costly, toxic, opaque

guides

has two stages

has two stages

prompt then critique then revise

fine-tune weights

samples two responses

produces

trains

optimize via PPO

sampled principle P

RLHF human labeling

Constitutional AI

Constitution principles

Stage 1 SL self-critique

Stage 2 RLAIF

Revised good pairs

SL-CAI model

AI judge applies principle

Preference pairs

Reward model r_theta

RL-CAI final model

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Constitutional AI ka core idea simple hai: normal RLHF mein humans ko har answer ko rank karna padta hai, including harmful wale — ye expensive bhi hai aur labelers ke liye mentally draining bhi. CAI bolta hai — chalo ek chhota sa constitution (rules ki list) likh dete hain, aur model ko hi bolte hain ki apne answer ko in rules ke against khud check kare aur galti ho to khud sudhaare.

Do stages hain. Stage 1 (Supervised): model ek initial (shayad rude) answer deta hai, phir hum use bolte hain "is answer ko principle P ke hisaab se critique karo", phir "ab revise karo". Ye critique→revise loop chalta hai, aur final accha answer par model ko fine-tune kar dete hain. Stage 2 (RLAIF): ab do answers generate karke ek AI judge se puchte hain "kaunsa principle P ko better follow karta hai?". Uske choices se ek reward model train hota hai (Bradley-Terry formula se), aur phir PPO se policy ko optimize karte hain — saath mein ek KL penalty taaki model reference se zyada door na bhaage aur bakwaas repetitive text na banaye.

Important baat: RLAIF aur RLHF ka math same hai — sirf label kaun de raha hai (AI vs human) wahi difference hai. Aur ye mat samajhna ki humans hat gaye — humans ab bhi constitution likhte hain, bas per-example labeling ka kaam AI ko de diya. Exam/interview ke liye 80/20: yaad rakho "do stages: self-critique fine-tuning, phir AI-judged reward + PPO with KL". Bas yahi core hai.

Go deeper — visual, from zero

Test yourself — Alignment, Prompting & RAG

Connections