Concepts / Bias Mitigation in Language Models

Bias Mitigation in Language Models

Finetuning is most valuable when the model was not sufficiently trained on your task. The adjustment is driven by the data you provide, so the examples you choose determine what the model moves toward.

  • Programming

When a General Model Falls Short

Imagine a general-purpose model that scores well on many public benchmarks, yet keeps stumbling on the one job your product needs done. It might write a fluent answer that still breaks the JSON format your software expects. It might translate queries correctly for standard SQL but fail on the dialect your company's database uses. The model is not broken. It was simply not trained much on your particular situation.

This is the situation that finetuning addresses. In this article we follow what happens to a model when it is finetuned, then examine three uses the source material singles out: shaping output structure and task performance, reducing biases, and producing smaller models that behave like larger ones. Keep the first situation in mind, because each of those uses starts from a model that is good in general but not yet good at your specific need.

What do you think happens?

In model distillation, which model is the one that gets finetuned?

  • The larger model that generates the data

  • The smaller model that learns to imitate it

Reveal answer
Answer:

The smaller model is finetuned. It learns to imitate the behavior of a larger model, using data generated by that larger model.

The large model acts as the source of the training data, and the small model is the one whose parameters are adjusted by finetuning.

What Finetuning Starts From

Definition

Finetuning is a process for improving a model's quality, both in its general capabilities and in its task-specific capabilities. It takes a model that already exists and continues training it on data that reflects what you want.

The key word is continues. Because the model starts from its existing knowledge, finetuning is an adjustment rather than a construction from nothing. You are not teaching the model language from scratch. You are nudging a model that already knows a great deal toward the behavior your data demonstrates.

The source identifies the primary reason for finetuning as this improvement in quality, and names two kinds of gain that follow from it. The first is task performance: a model that is weak on a specific task can become stronger on that task once it sees examples of it. The second is structure: finetuning is commonly used to make a model produce outputs that follow a specific structure, such as JSON or YAML formats.

Key point

Finetuning is most valuable when the model was not sufficiently trained on your task. The adjustment is driven by the data you provide, so the examples you choose determine what the model moves toward.

How Finetuning Reshapes Task Behavior and Output Structure

Consider what changes when a model is trained on examples of the output you want. The source gives two concrete cases of a model that is close to useful but not quite there. In the first, a model converts text to standard SQL well but fails with a less common dialect. Finetuning that model on data written in the less common dialect is expected to help. In the second, a model handles standard SQL for common queries but struggles with queries specific to one customer. Finetuning on those customer-specific queries may help in the same way.

The diagram above shows the shape of the change. The base model's reply is fluent but unstructured, which is exactly the failure the opening example described. After finetuning on examples that demonstrate the required format, the same kind of request produces a reply that follows the structure your software expects. The model's underlying knowledge is the same starting point; what has moved is the pattern it reliably produces for this task.

Worked example

Finetuning a model to return ticket categories as JSON

A team has a general model that answers support messages in free prose. Their software needs each answer as a JSON object with a category field and a priority field. The team writes a small set of example pairs, each showing a support message and the exact JSON answer they want.

  1. 1
    Starting state

    The base model answers in prose, so a reply such as 'This looks like a billing problem and is fairly urgent' cannot be parsed by the software.

  2. 2
    Curate the examples

    Each training pair pairs a message with the correct JSON structure, so the model sees the format and the content together.

  3. 3
    Finetune

    The model continues training on these pairs, adjusting toward producing the demonstrated structure.

  4. 4
    Resulting state

    On a new message, the model is now more likely to return a JSON object with the category and priority fields, which the software can read.

Result

The model's behavior on this task changed from free prose to the required output structure, because the training data demonstrated that structure repeatedly.

Curated Data as a Corrective Force

The source describes bias mitigation as an especially interesting use of finetuning. The reasoning starts from a limitation of training data: if a base model has absorbed certain biases from the data it was trained on, it will tend to repeat them. Finetuning offers a remedy. By exposing the model to carefully curated data during finetuning, you can counteract those biases.

The mechanism is straightforward to state. A bias is a default association the model has learned, such as linking a particular role with a particular kind of name. Curated data works against that default by presenting the underrepresented pattern often enough that the default association weakens.

Worked example

Correcting a CEO name bias with curated data

A base model consistently assigns male-sounding names to CEOs when asked to write about company leaders.

  1. 1
    Identify the bias

    The model's default association links the CEO role with male-sounding names.

  2. 2
    Curate the finetuning data

    Build a dataset that contains many female CEOs, so the underrepresented pattern appears often in the training examples.

  3. 3
    Finetune the model

    The model is trained on this curated data, so it repeatedly sees CEOs with female-sounding names.

  4. 4
    Check the default

    Because the model sees the underrepresented pattern often enough, its default association is expected to weaken.

Result

The bias is mitigated by the data itself doing the corrective work, rather than by any change to the rule the model uses.

The source also reports research by Garimella et al. (2022). They found that finetuning BERT-like language models on text authored by women can reduce these models' gender biases, while finetuning them on texts by African authors can reduce racial biases. The lesson is that the choice of finetuning data is itself the lever. Different curated sources target different biases.

Model Distillation: From Teacher to Student

The source notes that you can finetune a big model to make it even better, but finetuning smaller models is much more common. This leads to model distillation, which the source describes as a common approach: finetune a small model to imitate the behavior of a larger model, using data generated by that large model.

Larger modelproduces the outputsGenerated dataoutputs used as trainingexamplesSmaller modelfinetuned to imitate thelarger modelgeneratesfinetunes on
Where does the training signal come from, and how does it move from the large model into the small one?

The training signal comes from the large model. It produces outputs, those outputs become the training data, and the small model is finetuned on that data so that it imitates the large model's behavior. Because the approach carries the larger model's knowledge over into the smaller one, it is called distillation. The source notes that it is covered in a later chapter together with other data synthesis techniques, so this article only introduces the core flow.

Key point

In distillation, the data is not hand-written examples alone. It is generated by the larger model, and the smaller model learns from that generated data through finetuning.

Why the Smaller Model Is Attractive

The source gives the practical reasons smaller models are finetuned more often. Smaller models require less memory, which makes them easier to finetune. They are also cheaper and faster to run in production. These are the trade-offs that make a distilled or finetuned small model appealing even when a large model is available.

Larger modelmore parameters to adjustSmaller modelfewer parameters to adjustHigher memory needsharder to finetuneLower memory needseasier to finetuneHigher run cost andslowerin productionCheaper and fasterin production
How do the smaller and larger models differ in size, memory, cost, and speed, and what does each trade-off gain or lose?

A smaller model finetuned on one task can outperform a much larger out-of-the-box model on that task. The source gives a concrete case. Grammarly found that its finetuned Flan-T5 models (Chung et al., 2022) outperformed a GPT-3 variant specialized in text editing across a wide range of writing assistant tasks, even though the Flan-T5 models were 60 times smaller. The finetuning process used only 82,000 (instruction, output) pairs, which the source notes is smaller than the data typically needed to train a text-editing model from scratch.

Mistakes Learners Make About Finetuning

  • Common mistake

    Thinking finetuning builds a model from nothing

    Why it fails

    Finetuning starts from a model that already exists and continues training it on data that reflects what you want.

    Do this instead

    Think of finetuning as adjusting an existing model toward your task and output format.

  • Common mistake

    Assuming any curated data will remove a bias

    What it looks like

    Adding random examples that do not include the underrepresented pattern.

    Why it fails

    The data is the corrective lever, so it must present the underrepresented pattern often enough to weaken the default association.

    Do this instead

    Select curated data that targets the specific bias you want to counteract, and remember that different sources target different biases.

  • Common mistake

    Believing that bigger models are always the better finetuning choice

    Why it fails

    Smaller models need less memory, are cheaper and faster to run in production, and can outperform a larger out-of-the-box model on one task.

    Do this instead

    Weigh the task, memory budget, and latency needs before choosing the model size to finetune.

  • Common mistake

    Treating distillation as copying the large model's weights directly

Checking Your Understanding

EASY

A team's model answers customer questions in prose, but their system needs each answer as a JSON object. Describe the change finetuning should produce, and explain what the team's training data must show for that change to happen.

Hints
  • Think about what the model's output looks like before and after finetuning.
  • Consider what the training examples must demonstrate for the model to reproduce that structure.
MEDIUM

A base model assigns a learned bias to a group. Explain why curating finetuning data that contains many examples of the underrepresented pattern can weaken that bias, and why the choice of curated source matters.

Hints
  • Recall the CEO example and what the model sees repeatedly during finetuning.
  • The Garimella et al. finding ties different sources to different biases.

Key Takeaways

  • Finetuning continues training an existing model on data that reflects what you want, improving its task performance and its ability to follow output structures such as JSON or YAML.
  • Bias mitigation uses carefully curated finetuning data to counteract biases a model absorbed from its training data, and the choice of data determines which biases are targeted.
  • Model distillation finetunes a smaller model to imitate a larger model, using data generated by the larger model.
  • Smaller models are attractive because they need less memory to finetune and are cheaper and faster to run, and a finetuned small model can outperform a much larger out-of-the-box model on a specific task.

Related concepts

More concepts starting with B