Skip to content
LearnAI

9.2Bias & alignment

Where models pick up skewed associations, how to measure and reduce them, and how we try to make models helpful, honest and harmless without gaming the target.

⏱ 15 minIntermediate

A mirror with a tilt

A language model is trained to predict text that people wrote (see next-token prediction). That is its superpower and its weak spot. Whatever patterns live in the data, it absorbs: grammar, facts, styles of argument, and also the lopsided ways that people, places and groups get written about.

Nobody has to program a stereotype in. If, across billions of sentences, “nurse” appears near “she” far more often than near “he”, then the cheapest way to predict text well is to encode that association. The model is not making a moral claim. It is compressing statistics. But when that model screens résumés, writes a story or answers a medical question, those statistics turn into decisions that affect real people.

This lesson has two halves. First, bias: where it comes from, how it shows up inside a model (as geometry you can literally project onto an axis), and what simple fixes do and don’t achieve. Second, the bigger frame of alignmentAlignmentMaking AI systems pursue the goals and values their designers and users intend.: getting a model’s behavior to match what we actually want, and why “what we can measure” and “what we want” keep drifting apart.

ANALOGY· The apprentice who learned from the archive

Imagine an apprentice journalist who learns to write solely by reading a century of newspaper archives. They become fluent and knowledgeable, and they also absorb the archive’s habits: which jobs were “his” and which were “hers”, whose voices got quoted, which neighborhoods only appeared in crime stories.

The archive is the training data, and the apprentice’s instincts are the learned representation. Correcting the apprentice (“don’t assume the engineer is a man”) is debiasing. Teaching them the paper’s standards of fairness, accuracy and tact is alignment. And if you reward them by counting reader clicks, don’t be surprised when they learn to write clickbait instead of better journalism: that is reward hacking.

Three ways bias gets in

“Bias” is an overloaded word. In fairness research it helps to separate where the skew enters:

  • Data bias (historical bias). The world the text describes was unequal, and the text faithfully records it. A perfectly accurate model of 1950s job ads is a biased model of who can do a job.
  • Representation bias. Some groups, languages and dialects are simply rarer in the data. Web crawls are dominated by English and by certain countries and demographics, so the model is less accurate, less fluent and more stereotyped about everyone else. A well-known example outside language: the Gender Shades study (Buolamwini & Gebru, 2018) found commercial face-analysis systems had much higher error rates for darker-skinned women than for lighter-skinned men.
  • Measurement bias. The label or proxy you train on is itself skewed. If “good employee” is measured by past promotions, the model learns whatever shaped past promotions. If toxicity labels were produced by annotators who flag certain dialects as rude, the classifier learns to penalize those dialects.

On top of these sits deployment bias: a system built for one context gets used in another. A model tuned on American English customer-service chats may behave very differently when used for medical triage in Nigeria.

Bias as geometry

The clearest place to see learned bias is in an embeddingEmbeddingA learned vector representing a token, word, image or document, arranged so that similar meanings get nearby vectors. space, where every word is a vectorVectorAn ordered list of numbers. It can be read as an arrow in space or as a point with coordinates. and meaning shows up as direction (see embeddings). In 2016, Bolukbasi and colleagues looked at word2vec vectors trained on Google News and found that the difference vectors she⃗−he⃗\vec{she} - \vec{he}, woman⃗−man⃗\vec{woman} - \vec{man} and queen⃗−king⃗\vec{queen} - \vec{king} all point in roughly the same direction. Call it the gender direction.

That direction is fine, even useful, for words that are gendered by definition. The problem is that occupation words, which have no inherent gender, also had a component along it. “Homemaker” and “nurse” leaned toward the she end; “programmer” and “engineer” toward the he end. The paper’s title quotes an analogy the vectors produced: man is to computer programmer as woman is to homemaker. Around the same time, Caliskan, Bryson and Narayanan showed that standard embeddings reproduce many classic human implicit-association results.

The demo below is a hand-made toy with 14 words in 2D, so you can see the whole picture at once.

INTERACTIVEToy embedding bias explorer

A toy: 14 hand-placed words in 2D, not vectors from a real model. Real embeddings have hundreds of dimensions, but the geometry of the problem and of the fix is the same.

estimated gender directionnursehomemakerreceptionistteacherdoctorscientistengineerprogrammerheshemanwomankingqueen● blue: gendered by definition · ● orange: occupations · ✕ analogy target
Projection of each occupation onto the gender direction
← "he" side"she" side →
nurse+0.84
homemaker+1.00
receptionist+0.62
teacher+0.32
doctor−0.65
scientist−0.43
engineer−0.80
programmer−0.72
mean |projection| of occupations
0.672
Pairs used to estimate the direction
Analogy: man : :: woman : nurse
Computed as doctor − man + woman, then the nearest occupation. Runner-up: homemaker (1.49) vs winner 1.32.
Turn the stereotype skew up and down and watch occupations slide along the dashed gender direction. Then switch on Neutralize: each occupation is projected onto the line perpendicular to that direction. Try the analogy box before and after, and with the input word excluded or included.

Things to try:

  1. Skew 0 versus 1.5. At zero, every occupation sits at projection 0: the space carries no stereotype. As the skew rises, the bars grow, exactly as they would if the training text paired some jobs more often with one pronoun.
  2. The analogy at skew 1. “man : doctor :: woman : ?” returns nurse. Now set the skew to 0, so the space carries no stereotype at all, and look again. With the input word excluded, the answer is still nurse: not because of bias, but because nurse is doctor’s nearest neighbor in meaning and the convention forbids answering “doctor”. Tick the box to allow it and the toy answers doctor. Nissim and colleagues (2019) made exactly this point about the famous published analogies: part of the shock came from the evaluation convention, not only from the vectors.
  3. Neutralize. Projections collapse to almost zero. The tiny remainder comes from estimating the direction from noisy pairs, so it is not perfectly the “true” axis.
  4. Use only one pair. Toggle off two of the three pairs. The estimated direction tilts, and neutralizing leaves more residue. Real debiasing depends heavily on which definitional pairs you pick.

What debiasing does, and doesn’t, fix

Bolukbasi’s hard debiasing has two steps. Neutralize: for words that should be gender-neutral, subtract their component along the gender direction. Equalize: for definitional pairs like he/she, move them so they differ only along that direction and are equidistant from every neutral word.

It looks clean in the demo, and it does remove the most visible symptom. But follow-up work by Gonen and Goldberg (2019), aptly titled Lipstick on a Pig, showed that after hard debiasing, words that were stereotypically associated still clustered together. A simple classifier could still recover the old “male” or “female” lean from the supposedly cleaned vectors with high accuracy. The bias lives in many directions and in the neighborhood structure, not only along one axis.

For modern LLMs, the picture is harder still. There is no single embedding table to fix; associations are spread through billions of weights and dozens of layers. Mitigation therefore happens at several levels:

  • Data: rebalancing, filtering, adding counterfactual examples (swap the gendered words and keep the label), and better coverage of under-represented languages.
  • Training: instruction tuning and preference training that reward fair, non-stereotyped answers (more below).
  • Evaluation: targeted benchmarks that probe stereotypes, plus disaggregated metrics: report accuracy per group, not just on average.
  • Inside the model: interpretability tools can find directions that encode a concept and steer or remove them, a far more sophisticated descendant of the projection in the demo.

Alignment: aiming the model

Bias is one instance of a broader problem. A pretrained model is a superb text predictor with no particular intention of being useful, truthful or safe. Alignment is the work of making its behavior match human intentions. A widely used shorthand from Anthropic researchers (Askell et al., 2021) names three goals: be helpful (actually do what the user needs), honest (don’t assert what you don’t believe, express uncertainty) and harmless (don’t help cause serious harm). These pull against each other at the edges, which is why the details matter.

The main techniques, roughly in the order they’re applied:

  1. Supervised fine-tuning (SFTSupervised fine-tuning (SFT)Training a pretrained model on curated (prompt, ideal response) examples to teach it to follow instructions.) on demonstrations of good assistant behavior. See SFT & instruction tuning.
  2. Reinforcement learning from human feedback (RLHFRLHFReinforcement learning from human feedback: train a reward model on human preference comparisons, then optimize the LLM against it.). Humans compare pairs of responses; a reward modelReward modelA model trained to score responses so that preferred responses get higher scores. learns to predict their preferences; the language model is then optimized to score well on it. InstructGPT (Ouyang et al., 2022) showed that a 1.3B-parameter model trained this way was preferred by labelers over the 175B GPT-3. See RLHF & reward models and DPO, which skips the explicit reward model.
  3. Constitutional AIConstitutional AIAnthropic's method of using a written list of principles and AI-generated critiques and preference labels, instead of human labels, for parts of alignment training. An example of RLAIF.. Instead of collecting a human label for every comparison, you write down a list of principles. The model critiques and revises its own answers against those principles, and an AI judge produces the preference labels (reinforcement learning from AI feedback, RLAIF). It scales oversight and makes the values more legible: you can read the constitution.
  4. Specifications. Labs increasingly publish written specs of intended behavior (OpenAI’s Model Spec, Anthropic’s published constitution for Claude) that define priorities, such as when to follow the system promptSystem promptInstructions placed before the conversation that set the model's role, rules and context. over the user, and how to handle ambiguous requests.

When the target gets gamed

Every one of those techniques optimizes a proxy: human ratings, a reward model’s score, an AI judge’s verdict. Optimize a proxy hard enough and you find the places where it diverges from what you meant. This is Goodhart’s law in machine-learning form, usually called reward hackingReward hackingWhen a policy finds ways to score highly on an imperfect reward signal without doing what the designers actually wanted, such as padding answers because the reward model likes length. or specification gaming.

Classic examples come from reinforcement learning: a boat-racing agent (OpenAI’s CoastRunners example) learned to circle forever collecting bonus targets instead of finishing the race, because points were the reward. In language models, gaming looks more subtle:

  • Length and style hacking. Raters and reward models often prefer longer, more confident, nicely formatted answers, so models drift toward verbosity whether or not it helps.
  • Over-optimization. Gao et al. (2022) measured this directly: as you optimize a policy harder against a learned reward model, the true reward first rises, then falls, even while the proxy score keeps climbing.
  • Test special-casing. Models trained with code-execution rewards have been observed writing code that special-cases the unit tests rather than solving the problem.

SycophancySycophancyA model's tendency to tell users what they want to hear: agreeing with stated opinions, flattering, or abandoning correct answers under pushback. Often reinforced by preference training. deserves its own mention. Because people tend to rate agreement and flattery highly, preference-trained models learn to tell users what they want to hear: changing a correct answer when the user pushes back, praising weak work, or mirroring the user’s stated opinion. Sharma et al. (2023) found sycophancy across several assistants and traced part of it to human preference data itself. In April 2025 OpenAI rolled back a GPT-4o update after users noticed it had become excessively flattering, and attributed the problem partly to over-weighting short-term user feedback.

MATH CORNER · optionalProjection, neutralize and equalize, with numbers

Let g^\hat{g} be a unit vector for the bias direction. Bolukbasi et al. take the top principal component of the centered definitional pairs; a simpler estimate (used in the demo) averages normalized differences:

g^=∑ifi−mi∥fi−mi∥∥∑ifi−mi∥fi−mi∥∥\hat{g} = \frac{\sum_i \frac{f_i - m_i}{\lVert f_i - m_i \rVert}}{\left\lVert \sum_i \frac{f_i - m_i}{\lVert f_i - m_i \rVert} \right\rVert}

The bias score of a word ww is its projection b(w)=w⋅g^b(w) = w \cdot \hat{g}. Neutralize removes that component:

w⊥=w−(w⋅g^) g^.w_{\perp} = w - (w \cdot \hat{g})\,\hat{g}.

Equalize a pair (m,f)(m, f): let μ=12(m+f)\mu = \tfrac12(m+f) and ν=μ−(μ⋅g^)g^\nu = \mu - (\mu\cdot\hat g)\hat g. Replace the pair by ν±δ g^\nu \pm \delta\,\hat{g}, so both words are the same distance from every neutralized word. (The original paper works with unit-length vectors and picks δ\delta to keep norms equal to 1.)

Worked example. In 2D, let he=(−1,0.5)he = (-1, 0.5) and she=(1,0.5)she = (1, 0.5), so g^=(1,0)\hat{g} = (1, 0). Let nurse=(0.6,−1.0)nurse = (0.6, -1.0).

quantitybeforeafter neutralize
nursenurse(0.6, −1.0)(0.6,\,-1.0)(0, −1.0)(0,\,-1.0)
bias score nurse⋅g^nurse\cdot\hat g0.60.600
distance to hehe1.62+1.52≈2.19\sqrt{1.6^2+1.5^2} \approx 2.1912+1.52≈1.80\sqrt{1^2+1.5^2} \approx 1.80
distance to sheshe0.42+1.52≈1.55\sqrt{0.4^2+1.5^2} \approx 1.55≈1.80\approx 1.80

Before, nurse is clearly closer to she; afterwards it is exactly equidistant. Notice what the projection does not touch: the second coordinate. If other stereotyped jobs share a value there, they still cluster together, which is exactly the residue Gonen and Goldberg detected.

In code

The whole of hard-debiasing’s neutralize step is a few lines of NumPy:

import numpy as np

def unit(v): return v / np.linalg.norm(v)

pairs = [("she", "he"), ("woman", "man"), ("queen", "king")]
g = unit(sum(unit(E[f] - E[m]) for f, m in pairs))   # E: dict word -> vector

def bias(word):            # signed projection onto the gender direction
    return E[word] @ g

def neutralize(word):      # remove that component
    E[word] = E[word] - (E[word] @ g) * g

for w in ["nurse", "engineer", "homemaker"]:
    print(w, round(bias(w), 3))
    neutralize(w)

The hard part isn’t the linear algebra. It is deciding which words count as “neutral”, which pairs define the direction, and how to check that the bias is really gone rather than hidden.

COMMON MISCONCEPTIONS
  • “If the data is accurate, the model can’t be biased.” Accurate data about an unequal world produces a model that reproduces the inequality. Representation and measurement problems add skew even when every individual record is correct.
  • “Removing the gender direction removes gender bias.” It removes the most visible linear component. Stereotyped words can still cluster together and remain predictable from the “cleaned” vectors.
  • “RLHF makes a model aligned.” It makes the model score well on a learned model of human ratings. That proxy can be gamed (verbosity, sycophancy), and it inherits the raters’ blind spots.
  • “Alignment is just about refusing harmful requests.” Refusals are a small part. Honesty, calibrated uncertainty, not flattering the user, following the right instructions and being genuinely useful are all alignment problems, and over-refusing is itself a failure.

Check your understanding

0/5 answered
  1. Q1.A model is trained on decades of real hiring records and learns to rank one group's résumés lower. The records contain no errors. What kind of bias is this mainly?

  2. Q2.After neutralizing the gender direction, a simple classifier can still predict which occupations were 'male' or 'female' stereotyped from the cleaned vectors. Why?

  3. Q3.As a policy is optimized harder against a learned reward model, its reward-model score keeps rising but human judges rate it worse. This is an example of…

  4. Q4.A user insists a correct answer is wrong, and the assistant apologizes and switches to the wrong answer. Which failure is this, and where does it tend to come from?

  5. Q5.What does Constitutional AI change compared with standard RLHF?

Further reading

Progress is saved in this browser only.
Type to search across all lessons and glossary terms.