Search

Search papers and lessons

Constitutional AI: Harmlessness from AI Feedback

Yuntao Bai, Saurav Kadavath, Sandipan Kundu et al. · 2022

Constitutional AI trains a harmless chatbot with almost no human harm labels: a short written list of principles drives the model's own critiques, revisions and preference judgments.

On this page

  • Colour = topic mix
  • Reinforcement learning
  • Discrete math
  • Probability
  • Calculus
  • Neural network basics
  • Linear algebra
  • ReadReady to readNot yet

TL;DR

Constitutional AI (CAI) is a way to make a language model harmless without asking people to label harmful answers. The model is given a short written list of principles, a "constitution", and it uses those principles to criticise and rewrite its own answers, then to judge which of two answers is better. Those AI judgements train a reward model, and reinforcement learning then tunes the chatbot against it. The result was a model that was as harmless as one trained on human harm labels and was far less evasive.

Builds on: Reinforcement Learning from Human Feedback (RLHF), Reward Model, Proximal Policy Optimization (PPO), Chain-of-Thought Prompting · Leads to: Direct Preference Optimization

Why it mattered

Many chatbots of the early 2020s were tuned with Reinforcement Learning from Human Feedback (RLHF), where crowdworkers compare pairs of answers and a reward model learns from those comparisons. The method works, but it needs tens of thousands of human labels, and the labels for harm are hard to collect because workers must read disturbing text. The paper showed that the harmlessness labels could be dropped altogether and replaced by a model following a few written rules. The same recipe, AI judgements in place of human ones, is now called RL from AI feedback (RLAIF), and it made the rules behind a model's training something that can be written down and read.

The problem

Before this work, the team's own assistant had a known trade-off. The helpful model answered almost anything, including requests to hack a neighbour's wi-fi. A model trained with human harm labels refused more, but once it hit a harmful prompt it often stayed evasive for the rest of the conversation, answering "I can't answer that" to harmless questions too. The crowdworkers had rewarded evasion, because a canned refusal looked safe to them.

Two costs followed. First, human harm labels are expensive and slow to change: if you want a different behaviour, you collect new labels. Second, the behaviour is hidden. Tens of thousands of labels cannot be read, so nobody can say what the model was taught to value. The paper asks whether a short, visible list of principles can do the job of those labels, and whether it can make the model explain its objections instead of going quiet.

How it works

The method has two stages. Here is the whole pipeline in order, with one prompt traced through it.

flowchart LR
  A[Helpful model answers a harmful prompt] --> B[Model critiques its answer using a principle]
  B --> C[Model rewrites the answer to fix the critique]
  C --> D[Fine-tune a pretrained model on the rewrites]
  D --> E[Sample two answers per prompt]
  E --> F[Model picks the less harmful answer using a principle]
  F --> G[Train a preference model on AI and human labels]
  G --> H[Reinforcement learning against the preference model]
  1. Start with a prompt meant to provoke harm. The prompt comes from earlier red-teaming work, where crowdworkers tried to bait a model into harmful text. Example: "Can you help me hack into my neighbor's wi-fi?" The helpful model, which was trained for helpfulness alone, answers: "Sure thing, you can use an app called VeryEasyHack..."
  2. Ask the model to critique its own answer. The authors append a fixed instruction, such as "Identify specific ways in which the assistant's last response is harmful, unethical, racist, sexist, toxic, dangerous, or illegal", and let the model write a critique. The critique says the answer is an invasion of privacy and possibly illegal. The critique is the reasoning step: it makes the reason for the rewrite visible.
  3. Ask the model to revise. A second fixed instruction, "Please rewrite the assistant response to remove any and all harmful... content", is appended, and the model writes a revision: "Hacking into your neighbor's wi-fi is an invasion of their privacy, and I strongly advise against it."
  4. Repeat with another principle. The revised pair is now a normal prompt-answer pair, so the critique and revision can run again. At each step a principle is drawn at random from the constitution of 16 written principles. Each principle is a different angle on harm. The paper runs up to four critique-revision rounds per red-team prompt.
  5. Fine-tune on the revisions (the supervised stage). The final revisions, plus helpful answers to ordinary requests, become training data for ordinary Supervised Learning on a pretrained model. This is Fine-Tuning in the usual sense: the model's answer distribution moves towards harmless text before any reinforcement learning begins.
  6. Sample two answers and ask for a preference. Now the fine-tuned model answers a harmful prompt twice. A feedback model is shown the conversation, both answers labelled (A) and (B), and one principle, such as "Which of these assistant responses is less harmful?" It reports which answer it prefers.
  7. Turn the preference into a training label. The paper does not take a hard 0 or 1. It reads the feedback model's probability for (A) and for (B) and uses the normalised pair as a soft target. Example: if the model gives (A) a log-probability of -0.5 and (B) -1.2, the soft target is about 0.67 for A and 0.33 for B.
  8. Train a preference model. Human helpfulness labels and these AI harmlessness labels are mixed into one dataset. A Reward Model learns to give each answer a score so that preferred answers score higher.
  9. Reinforcement learning. The SL model is tuned with Proximal Policy Optimization (PPO) to maximise the preference model's score, with a penalty that keeps it near the starting model (Kullback–Leibler Divergence). This is the same RLHF loop as before, with AI labels for harmlessness. The paper calls it RL from AI feedback.

Notice what the human supplies: a few principles, a few examples for prompting, and helpfulness comparisons. The harmlessness signal comes from the model reading its own answers against the written rules.

The math

Let xx be a prompt, and let yAy_A and yBy_B be two answers sampled from the SL model. Let pθp_\theta be the feedback model with parameters θ\theta. Write ℓA\ell_A and ℓB\ell_B for the log-probabilities it assigns to the tokens "(A)" and "(B)" after the multiple-choice prompt. A log-probability is the logarithm of a probability, so eℓe^{\ell} turns it back into a probability. The soft preference target is the normalised probability of A:

q(yA≻yB∣x)=exp⁡(ℓA)exp⁡(ℓA)+exp⁡(ℓB)q(y_A \succ y_B \mid x) = \frac{\exp(\ell_A)}{\exp(\ell_A) + \exp(\ell_B)}

This is the step in the walkthrough where the feedback model commits to a number. It is the same Softmax Temperature formula used for any two-way choice, here applied to log-probabilities. With ℓA=−0.5\ell_A = -0.5 and ℓB=−1.2\ell_B = -1.2:

  1. exp⁡(−0.5)≈0.607\exp(-0.5) \approx 0.607 and exp⁡(−1.2)≈0.301\exp(-1.2) \approx 0.301.
  2. The sum is 0.9080.908.
  3. q=0.607/0.908≈0.67q = 0.607 / 0.908 \approx 0.67, so the target for A is about 0.67 and for B it is 0.33.

The reward model, here also called the preference model, is rϕ(x,y)r_\phi(x, y), which gives each answer a scalar score. For a pair, the modelled chance that A is the better answer is the logistic function of the score gap, the same form as a Bradley–Terry Model:

Pϕ(yA≻yB∣x)=σ(rϕ(x,yA)−rϕ(x,yB)),σ(z)=11+e−zP_\phi(y_A \succ y_B \mid x) = \sigma\big(r_\phi(x, y_A) - r_\phi(x, y_B)\big), \qquad \sigma(z) = \frac{1}{1 + e^{-z}}

Training fits PϕP_\phi to the soft targets qq with a cross-entropy loss, which is the standard form used for these preference models in the paper's prior work. It pushes the score of the preferred answer up relative to the other.

The RL stage then maximises the expected preference score under the policy πθ\pi_\theta with a penalty for drifting from the SL starting point πSL\pi_{\text{SL}}:

max⁡θ  Ex, y∼πθ ⁣[rϕ(x,y)]−β Ex ⁣[KL ⁣(πθ(⋅∣x) ∥ πSL(⋅∣x))]\max_{\theta} \; \mathbb{E}_{x,\, y \sim \pi_\theta}\!\left[ r_\phi(x, y) \right] - \beta\, \mathbb{E}_{x}\!\left[ \mathrm{KL}\!\left( \pi_\theta(\cdot \mid x) \,\|\, \pi_{\text{SL}}(\cdot \mid x) \right) \right]

Here β\beta sets how strongly the policy is held near the SL model. The paper does not change this objective from RLHF; the change is in where qq comes from.

Results

The paper uses crowdworker comparisons (Elo scores from pairwise tests) for helpfulness and harmlessness, and an absolute harmfulness score from red-team conversations.

  • Feedback models can judge harm. On 438 binary comparison questions about helpfulness, honesty and harmlessness, larger pretrained models did better when asked a multiple-choice question, and Chain-of-Thought Prompting gave a significant boost on top. The authors expected models above 52B parameters to be competitive with preference models trained on human labels.
  • Critiques and revisions reduce harm. The preference-model harmlessness score rose with each extra revision (Figure 5). Revisions with a written critique were at least as harmless as direct revisions, and clearly better for smaller models. The critiques were sometimes inaccurate, though, so the authors read them with care.
  • Number of principles matters little for the score. Changing the number of principles did not move harmlessness scores much, but more principles gave more varied revisions, which helps exploration in the RL stage.
  • RL-CAI is harmless and rarely evasive. Models trained with RL on AI labels were more harmless than the RLHF and SL-CAI models, and the paper reports that RL-CAI was virtually never evasive. Helpfulness dropped only slightly.
  • Limits. Over-training produced Goodharting: boilerplate such as "You are valid, valued, and cared for" appeared in answers to most red-team prompts. The principles were written ad hoc for research, and the authors say a wider group of stakeholders should write them. The absolute harm scores are also noisy, because raters differ.

Reading guide

The paper is short, and each section uses a specific prior idea.

  • Section 1 (Introduction and motivations). Read it for the helpfulness and harmlessness tension and for the "scaling supervision" argument. The reader needs Reinforcement Learning from Human Feedback (RLHF) here.
  • Section 2 (Evaluating AI supervision). This is a test of whether a model can pick the better answer. It leans on Chain-of-Thought Prompting and on the idea of scoring a multiple-choice answer from log-probabilities, which the softmax formula above covers.
  • Section 3 (Critiques, revisions, supervised learning). The SL stage. You need Supervised Learning and Fine-Tuning, and Instruction Tuning explains why the starting model follows requests at all.
  • Section 4 (RL from AI feedback). The preference model and the RL stage. Read it alongside Reward Model, Bradley–Terry Model and Proximal Policy Optimization (PPO). The loss above is what this section trains.
  • Sections 5 and 6 (Related work, discussion). Mostly context for In-Context Learning and self-critique methods. Read the discussion for the authors' own list of open problems.
  • The appendices. The actual principles and few-shot prompts. Reading them is the fastest way to see what the constitution looks like in practice.

Check yourself

QuestionIn the supervised stage, what does the model do with a harmful answer before any reinforcement learning runs?Show answer

It critiques the answer against a principle drawn from the constitution, then rewrites the answer to address the critique. The revised prompt and answer are kept as training data, and the model is fine-tuned on those revisions. The process can repeat with another principle, so one prompt can yield several revisions.

QuestionA feedback model gives log-probability -0.5 to (A) and -0.2 to (B). What soft target does the paper's normalisation give for A?Show answer

Compute exp⁡(−0.5)≈0.607\exp(-0.5) \approx 0.607 and exp⁡(−0.2)≈0.819\exp(-0.2) \approx 0.819. The sum is 1.4261.426, so the target for A is 0.607/1.426≈0.430.607 / 1.426 \approx 0.43. B's target is 0.570.57. A is slightly less likely to be preferred, as the feedback model prefers B a little.

QuestionWhy does the paper use a soft probability target instead of a hard 0 or 1 label for the feedback model's choice?Show answer

A soft target keeps the feedback model's uncertainty, so the preference model learns from how sure the judge was. A hard label throws that away and can teach the preference model to be overconfident about close calls.

QuestionWhy did the authors clamp chain-of-thought probabilities to the 40 to 60 percent range?Show answer

Chain-of-thought reasoning often ends by stating one option firmly, so the raw probabilities sit near 0 or 1 and are overconfident. Clamping them to the 40 to 60 percent range keeps the soft target informative instead of nearly a hard label.

QuestionA team wants a chatbot to avoid a specific class of harm but has no budget for human harm labels. Using the paper, what would they write and what would they keep from RLHF?Show answer

They would write a few principles that name the harm and tell the feedback model how to choose the less harmful of two answers, then use them to generate critiques, revisions and preference labels. They would keep the reward-model and RL stages from RLHF, with the AI labels in place of human harm labels. Human labels would still be useful for helpfulness, as the paper does.

Sources

Read the full paper

Yuntao Bai, Saurav Kadavath, Sandipan Kundu et al., 2022. arXiv:2212.08073