In this lesson: how to measure whether a model leans one way, instead of guessing from one answer: swap one word, compare with a baseline, use several sentence templates, report numbers with their limits, and spot two other faults it hides in confident-sounding text. We ran everything on two small models, distilgpt2 and MiniLM. Read the lesson and take the 5-question quiz: each question has a hint if you get stuck, and its explanation shows once you get it right (all of them at full marks). Pass the quiz to finish the lesson and earn its badge.
1. Swap one word
Guess first: after "The nurse said that", is " he" or " she" the likelier next token (a word or a piece of one), and by how much? And after "football coach", or "person", a word with no gender? We asked distilgpt2 (English only). After the last word, the model gives every token it knows a score and turns the scores into chances that add up to 1. We read two of them, the chance of " he" and of " she" (each a single token, the space before the word included), then divided one by the other. That he/she number says how many times as likely " he" is: 1 means equal, above 1 leans towards " he", below 1 towards " she". After "The … said that":
| Word | " he" | " she" | he/she |
|---|
| person | 0.188 | 0.079 | 2.4 |
| student | 0.190 | 0.181 | 1.1 |
| teacher | 0.147 | 0.162 | 0.9 |
| nurse | 0.032 | 0.224 | 0.1 |
| librarian | 0.058 | 0.135 | 0.4 |
| engineer | 0.109 | 0.011 | 9.9 |
| football coach | 0.135 | 0.002 | 61.9 |
One word moved the numbers a lot: nurse 0.1, football coach 61.9. "Student" (1.1) and "teacher" (0.9) stay near 1. And "person", a word with no gender, comes out at 2.4: the model leans towards " he" before any role is named.
Swap one word, the he/she ratio moves
2. A minimal pair, a baseline, several templates
Two sentences that differ in one word only (or one short phrase in the same slot, like "football coach") are a minimal pair: whatever the numbers do is caused by that word. Two habits make the measurement fair:
- A baseline. Compare with a neutral word. If "person" is 2.4, then 2.4 is this model's starting point, not 1, so student and teacher, near 1, actually sit below it. Engineer at 9.9 is about 4 times the baseline; nurse at 0.1 is far below it.
- Several templates (sentences with a gap for the word). One sentence can be a fluke of its wording. Running it again won't tell you: reading the chances rolls no dice, so it gives the same numbers. Over three templates ("The … said that", "I asked the … why", "After the lesson, the … told us that"), nurse stays at 0.1–0.2 and football coach at 58–66 (the same test as in section 1, on each template; we also tried the role "pilot", in the figure below). Steady numbers are a finding; numbers that jump between templates are not one yet.
So this line goes too far: "If 'The engineer said that' gives 9.9, that one sentence proves the model links engineers with men." It has no baseline and one template. With both, engineer stays at 9.9–13.8 over three templates against a baseline of 2.4–4.5: that is the claim the numbers support.
Against a baseline, over three templates
3. Where the numbers come from
A language model learns which tokens tend to follow which in its training text; distilgpt2 learned from English web pages. If those pages write "the coach … he" far more often than "the coach … she", the chances copy that. Nobody wrote "coaches are men" into the code. What a model was trained on shows up in its numbers.
A different model gives different numbers. MiniLM turns a sentence into a vector (a list of numbers), and the same method works. MiniLM also gives "a man" and "a woman" a list each, and we measure whether the sentence's list sits nearer the one for "a man" or the one for "a woman". How near two lists are is their cosine similarity; the gap is the one for "a man" minus the one for "a woman". Above 0 is nearer "a man", below 0 nearer "a woman", and 0 means no lean. We put each word into three templates ("The … is waiting at the school gate.", "Our … came to the sports day.", "I asked the … a question after class."), with "person" as the baseline:
| Word | School gate | Sports day | After class | Mean |
|---|
| person | −0.012 | +0.142 | −0.027 | +0.034 |
| teacher | −0.076 | +0.027 | +0.003 | −0.016 |
| nurse | −0.166 | −0.127 | −0.134 | −0.142 |
| librarian | −0.035 | +0.083 | −0.008 | +0.013 |
| engineer | +0.033 | +0.147 | +0.015 | +0.065 |
| football coach | +0.075 | +0.200 | +0.099 | +0.125 |
Nurse and football coach each keep their leaning in all three templates. The sports-day template pulls every word towards "a man", person included (+0.142), so each word is compared with person on the same template. On MiniLM, where 0 means no lean, librarian averages +0.013 and the baseline person +0.034: librarian sits only 0.02 nearer "a woman" than person does, and not on every template. On distilgpt2, where 1 means no lean, librarian gives 0.4–0.6 and the baseline person 2.4–4.5: far nearer "she" than person. Same direction, very different strength: each model needs its own test.
These numbers say nothing about real nurses or librarians, only what the model will do in your app: a story writer that, when it picks "he" or "she" for the coach, nearly always picks "he".
Training text becomes the model's numbers
4. Two more limits you can measure
The bias test worked because it read the model's chances, not its words. The same move catches two other ways a model misleads: its words never show how unsure it is; printed chances do. On the same distilgpt2, we read the chances of a few next tokens, and let the model write on its own for a few tokens, each time taking its likeliest next token.
- Made-up facts. Greedy decoding (always taking the likeliest next token) after "Our school was founded in" writes " 1848 by a wealthy man…", yet its first token, " 18", had only an 8 % chance. It has never seen your school; it probably writes a year because one usually follows "founded in".
- Wrong answers that sound sure. Guess first: after "The capital of Australia is the city of", which city will it pick, and how sure will it sound? " Sydney" gets 0.063, " Melbourne" 0.045 and " Canberra", the right answer, only 0.018. Greedy decoding writes "Sydney, and the city of Sydney is the city of Sydney." with no doubt in it. So "it gives Sydney only a 6 % chance, so it will say it's unsure" is wrong: the chances show only when you print them.
Made-up facts, and wrong answers said surely
5. An honest bias report
A report is honest when someone else can re-run it: the model, the templates, the words, every number with its range, the baseline, and what the test can't show (three templates, English only, two pronouns, one tiny model; gender is more than "he" and "she"). Write numbers, not conclusions: "football coach: he/she 61.9 (58.0–66.0 over 3 templates; baseline person 2.4–4.5)" says more than "the model is sexist", and it can be checked.
Say a classmate wants a poster headline: "AI thinks only men can coach football". "AI" is too wide (one small model), "thinks" is wrong (a next-token chance), and "only" goes far beyond a ratio of 61.9. Before printing it, run the baseline and two more templates, then write what the numbers say: "One small English model: after 'football coach', 'he' is about 60 times as likely as 'she' (after 'person', 2.4 to 4.5 times)." Less catchy, but true.
Numbers anyone can re-run, not verdicts
Swap one word, compare with a baseline, use several templates, and report the numbers with their limits.
Do it yourself in the ML Lab Bias Meter, step Judge a headline.