Bias Mitigation: Debiasing, CDA, and Fair Fine-tuning › Debiasing Word Embeddings

Michael BrenndoerferMarch 15, 20267 min read
Language AI HandbookAll chapters
Part 58 of 67Bias and Fairness
Chapter 443Bias Mitigation: Debiasing, CDA, and Fair Fine-tuning › Debiasing Word Embeddings
Reading section 4 of 13 · Debiasing Word Embeddings · 7 minSection 4 of 13 · 7 min

Book contents

Section 4 of 13 · 7 min read

Bias Mitigation: Debiasing, CDA, and Fair Fine-tuning › Debiasing Word EmbeddingsOne section · Sections in this chapter4 / 13 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Static word embeddings (Word2Vec, GloVe, FastText) encode bias in their vector geometry. The famous example from Bolukbasi et al. (2016): the embedding arithmetic king - man + woman = queen works, but so does doctor - man + woman = nurse. The bias is not incidental; it is baked into the directions of the vector space.

To understand why this happens, recall from the earlier chapters on word embeddings that these models are trained to predict co-occurrence statistics from large text corpora. If "doctor" co-occurs with "he" far more often than with "she" in the training corpus, the model places "doctor" closer to the male pole of whatever gender dimension emerges in the vector space. The geometry faithfully reflects the corpus statistics. Debiasing embeddings therefore requires identifying and modifying the specific directions in that space that carry demographic information.

Debiasing embeddings requires identifying and modifying those directions. The approach decomposes into two phases: isolating the bias subspace and then projecting it out.

Identifying the Bias Direction

The gender bias direction in an embedding space is not a single vector but a low-dimensional subspace. The most reliable way to identify it is through principal component analysis on a set of definitionally gendered word pairs.

For a set of kk gendered pairs (ai,bi)(a_i, b_i), where aia_i is the "male" word and bib_i is the "female" counterpart:

g=PCA({a⃗i−b⃗i2:i=1,…,k})[0]\mathbf{g} = \text{PCA}\left(\left\{\frac{\vec{a}_i - \vec{b}_i}{2} : i = 1, \ldots, k\right\}\right)[0]

where:

  • kk: the number of definitionally gendered seed pairs (e.g., man/woman, he/she, king/queen)
  • a⃗i\vec{a}_i: the embedding vector for the "male" word in pair ii
  • b⃗i\vec{b}_i: the embedding vector for the "female" word in pair ii
  • a⃗i−b⃗i2\frac{\vec{a}_i - \vec{b}_i}{2}: the midpoint-centered difference vector, capturing the direction from female to male for each pair
  • [0][0]: the first principal component, the direction of maximum variance across all kk difference vectors

The first principal component g\mathbf{g} captures the dominant direction of variation across gendered pairs. This vector is the bias direction: words near +g+\mathbf{g} are male-associated, words near −g-\mathbf{g} are female-associated, and words with near-zero projection should be neutral.

In practice, 10-20 well-chosen pairs suffice. The pairs should be definitionally gendered (not merely stereotypically associated): man/woman, he/she, king/queen, father/mother. Using stereotypically associated pairs like doctor/nurse would contaminate the estimated bias direction with the very associations you want to remove. This distinction between definitional gender (a term whose meaning explicitly encodes gender) and stereotypical gender (a term that statistically correlates with gender in text) is conceptually central to the entire hard-debiasing framework.

The PCA approach has an important property worth showing: it is reliable to noise in individual pairs. If one pair has an unusual embedding due to polysemy (for example, "prince" may carry musical associations from Prince the artist in corpora that include entertainment news), the first principal component will still find the dominant gender direction from the other pairs. This robustness depends on having enough pairs, which is why collecting at least ten is standard practice.

Hard Debiasing

Hard debiasing, proposed by Bolukbasi et al., modifies embeddings to make gender-neutral words exactly equidistant from all definitionally gendered word pairs. The procedure has two steps.

Step 1: Neutralize. For all gender-neutral words (words that should not carry gendered associations), project out the bias component:

w⃗neutral=w⃗−(w⃗⋅g)g\vec{w}_{\text{neutral}} = \vec{w} - (\vec{w} \cdot \mathbf{g})\mathbf{g}

where:

  • w⃗\vec{w}: the original embedding vector for a gender-neutral word
  • g\mathbf{g}: the unit-length gender bias direction (from the PCA step above)
  • (w⃗⋅g)(\vec{w} \cdot \mathbf{g}): the scalar projection of w⃗\vec{w} onto the gender direction, measuring how strongly the word aligns with the gender axis
  • (w⃗⋅g)g(\vec{w} \cdot \mathbf{g})\mathbf{g}: the vector component of w⃗\vec{w} lying along the gender direction, i.e., the part we want to remove
  • w⃗neutral\vec{w}_{\text{neutral}}: the debiased embedding, orthogonal to g\mathbf{g}

This is a standard orthogonal projection: subtract the component of w⃗\vec{w} along the gender direction g\mathbf{g}. The resulting vector retains all meaning except the gendered dimension. Geometrically, you can think of the original embedding space as having a "gender axis" passing through it; the neutralize step lifts every occupation word off that axis, placing it on the equatorial plane where neither male nor female is closer.

Step 2: Equalize. For definitionally gendered pairs, adjust their embeddings so they differ only along the bias direction. If "grandmother" and "grandfather" should be equidistant from "grandparent", their non-gendered components should be identical.

The goal is to make both words in a pair (e.g., "grandfather" and "grandmother") share identical non-gendered components, differing only along the gender axis. The process proceeds in two sub-steps.

Sub-step 2a: Remove bias component from each word. For each word wbw_b in the pair, subtract the projection onto the bias subspace BB:

w⃗b⊥=w⃗b−projBw⃗b\vec{w}_b^{\perp} = \vec{w}_b - \text{proj}_B \vec{w}_b

where:

  • w⃗b\vec{w}_b: the original embedding of one word in the gendered pair
  • BB: the bias subspace (spanned by g\mathbf{g})
  • w⃗b⊥\vec{w}_b^{\perp}: the gender-neutral residual component of the embedding

Sub-step 2b: Re-inject symmetric gender component. Normalize the residual and re-add a symmetric gender component so the two words are equidistant from the gender axis:

w⃗bdebiased=1−∥μ⃗⊥∥2⋅w⃗b⊥∥w⃗b⊥∥±1−∥μ⃗⊥∥2⋅g\vec{w}_b^{\text{debiased}} = \sqrt{1 - \|\vec{\mu}^{\perp}\|^2} \cdot \frac{\vec{w}_b^{\perp}}{\|\vec{w}_b^{\perp}\|} \pm \sqrt{1 - \|\vec{\mu}^{\perp}\|^2} \cdot \mathbf{g}

where:

  • μ⃗⊥\vec{\mu}^{\perp}: the mean of the two w⃗b⊥\vec{w}_b^{\perp} vectors, representing the shared non-gendered content
  • ∥μ⃗⊥∥\|\vec{\mu}^{\perp}\|: the magnitude of that shared component
  • 1−∥μ⃗⊥∥2\sqrt{1 - \|\vec{\mu}^{\perp}\|^2}: the scaling factor that ensures the final vector has unit length
  • ±g\pm \mathbf{g}: the ++ sign is used for the male word and −- for the female word, placing them symmetrically about the origin along the gender axis

The math is involved but the intuition is clean. After debiasing, doctor sits exactly equidistant from he and she, while king and queen still differ along the gender axis as intended. The equalization step matters because definitionally gendered words like "grandfather" and "grandmother" should retain their gendered character while still being equally related to gender-neutral words like "family" or "elder." Without equalization, the neutralize step applied only to occupation words would leave an inconsistency: "nurse" is equidistant from "he" and "she," but "grandmother" (which was never in the neutral set) might still sit closer to "she" than to "grandchild."

Soft Debiasing

Hard debiasing is a post-hoc operation that modifies pre-trained embeddings. Soft debiasing is a training-time approach that incorporates a fairness penalty directly into the embedding objective.

The idea is to add a regularization term that penalizes the alignment between the learned representations and sensitive attribute directions:

Lsoft=Ltask+λ∑i∈neutral(w⃗i⋅g)2\mathcal{L}_{\text{soft}} = \mathcal{L}_{\text{task}} + \lambda \sum_{i \in \text{neutral}} (\vec{w}_i \cdot \mathbf{g})^2

where:

  • Ltask\mathcal{L}_{\text{task}}: the primary training objective (e.g., cross-entropy or reconstruction loss)
  • λ\lambda: the fairness regularization strength, balancing task performance against debiasing
  • neutral\text{neutral}: the set of word indices that should not carry demographic associations
  • w⃗i\vec{w}_i: the learned embedding vector for neutral word ii
  • (w⃗i⋅g)2(\vec{w}_i \cdot \mathbf{g})^2: the squared projection onto the gender direction, penalized to drive it toward zero

The penalty term (w⃗i⋅g)2(\vec{w}_i \cdot \mathbf{g})^2 is zero only when the word vector is perfectly orthogonal to the gender direction. Summing across all neutral words, gradient descent naturally pushes each embedding off the gender axis during training.

The hyperparameter λ\lambda controls the tradeoff between fitting the data and reducing bias. A large λ\lambda enforces stronger debiasing at the cost of some predictive performance; a small λ\lambda preserves utility while achieving modest debiasing.

Soft debiasing is more principled than hard debiasing because it optimizes both objectives simultaneously rather than retrofitting the bias correction after the fact. The tradeoff is that it requires modifying the training loop, which is not always feasible. It also requires that the bias direction g\mathbf{g} be estimated before or during training, which introduces a chicken-and-egg problem: you cannot accurately estimate the bias direction until you have embeddings, but you need the direction to train debiased embeddings. The standard solution is to run a short warm-up phase to produce initial embeddings, estimate g\mathbf{g} from those, and then restart training with the penalty active. Alternatively, g\mathbf{g} can be estimated from a reference embedding (such as pre-trained GloVe vectors) and treated as a fixed target during training.