● Occupations
Each dot is a word. Faded dots mark where each word starts; bright dots, where it lands after the gender subspace is removed; trails, how it moves.
Vocabulary:
What Are Word Embeddings?
A dictionary explains a word using other words—a human-readable representation. A word embedding represents a word using a list of numbers—a machine-readable representation. Rather than hand-coding these numbers, we learn them from data, so that words with similar meanings end up with similar vectors.
The learning principle behind word embeddings is the distributional hypothesis (Harris, 1954): a word's meaning can be inferred from the words it co-occurs with.Co-occurrence counting is one approach. Others, like Word2vec, learn by predicting context words directly. Contextual models like BERT produce different vectors for the same word depending on context. To learn embeddings, we start with a text corpus and construct a word co-occurrence matrix that counts how often pairs of words appear together within a given window.
Each row is a sparse, high-dimensional representation of a word. Words in similar contexts get similar rows, so the raw counts capture similarity—but not the kind of geometric structure that supports analogies (more on analogies below).
GloVe (Pennington et al., 2014) learns embeddings by approximately factorizing the log co-occurrence matrix. Given a co-occurrence matrix $\mathbf{X} \in \mathbb{R}^{V \times V}$ over a vocabulary of $V$ words, where $\mathbf{X}_{ij}$ counts how often words $i$ and $j$ appear near each other, the goal is to find a low-dimensional vector $\overrightarrow{w}_i$ for each word such that dot products between vectors approximate the log counts
$$\overrightarrow{w}_i \cdot \overrightarrow{w}_j + \beta_i + \beta_j \approx \log \mathbf{X}_{ij}$$
where $\beta_i$ and $\beta_j$ are per-word bias terms.Why the bias terms? Without them, a word like the that co-occurs frequently with everything would need a large vector magnitude to produce large dot products with every other word—distorting the geometry that encodes meaning. The biases $\beta_i$ absorb each word's baseline co-occurrence rate, freeing the vectors to focus on which words co-occur more or less than expected. The parameters are fit by weighted least squares over all observed word pairs. This factorization does more than compress the data. Because the model predicts log counts with dot products, relationships between words become linear operations on the vectors. The result is a space with approximately linear structure—which is what makes analogies, and this article's subspace methods, possible.
In this article, we use 100-dimensional GloVe vectors trained on 6 billion tokens of text, normalized to unit length. All computations run in your browser.
Structure in the Embedding Space
Do embeddings capture meaningful structure? We can check by visualizing groups of related words.
Since our vectors are 100-dimensional, we project them to lower dimensions for plotting using MDS (multidimensional scaling), which finds a layout that best preserves pairwise distances. Use the eigenvalue bars next to each plot to switch between 1D, 2D, and 3D views.
Let $\overrightarrow{w}_1, \dots, \overrightarrow{w}_n$ be the $D$-dimensional word vectors (for GloVe, $D = 100$) of $n$ chosen words. The goal of MDS is to find low-dimensional coordinates $(\mathbf{y}_1, \dots, \mathbf{y}_n)$ such that $\|\mathbf{y}_i - \mathbf{y}_j\| \approx \|\overrightarrow{w}_i - \overrightarrow{w}_j\|$ for every pair $i, j$.
When the distances come from Euclidean vectors (as ours do), there is a closed-form solution known as classical MDS, which is equivalent to PCA: center the vectors, compute their covariance matrix, and take its top eigenvectors as coordinate axes. Its eigenvalues $\lambda_1 \ge \lambda_2 \ge \cdots$ measure how much distance structure each dimension captures. The fraction of variance explained by the top $m$ dimensions is $\sum_{j=1}^{m} \lambda_j \big/ \sum_{j=1}^{D} \lambda_j$—this is the percentage shown next to each plot.
An important caveat: each plot below runs MDS on a small, hand-picked set of words—not the full 50,000-word vocabulary. Running MDS on the entire vocabulary would spread the variance across many more directions, and these tidy patterns would be harder to see. The structure is real—it exists in the full 100-dimensional space—but the plots look this clean primarily because we chose words that share a common axis of variation.
Word Families
Words from the same family mostly land near each other:
Superlatives
Adjective forms trace out parallel paths:
Numbers
Digits line up along a counting direction:
So do number words:
Linked, digits and their word forms occupy distinct but parallel regions:
Word Analogies
The superlatives already demonstrate analogies—poor is to poorer as rich is to richer—and the pattern generalizes. Analogous pairs share roughly the same difference vector. The classic example: man is to woman as king is to queen corresponds to
$$\overrightarrow{\text{man}} - \overrightarrow{\text{woman}} \approx \overrightarrow{\text{king}} - \overrightarrow{\text{queen}}$$
More generally, $a : b :: c : d$ means $\overrightarrow{a} - \overrightarrow{b} \approx \overrightarrow{c} - \overrightarrow{d}$. Rearranging, we can solve for an unknown fourth word: $\overrightarrow{d} \approx \overrightarrow{c} + (\overrightarrow{b} - \overrightarrow{a})$. To find $d$, we take the word whose vector has the highest cosine similarity$\cos(\overrightarrow{w}, \overrightarrow{w}') \defeq \dfrac{\overrightarrow{w} \cdot \overrightarrow{w}'}{\|\overrightarrow{w}\| \, \|\overrightarrow{w}'\|}$ to $\overrightarrow{c} + (\overrightarrow{b} - \overrightarrow{a})$, leaving out $a$, $b$, and $c$ themselves. Leaving them out matters: otherwise the answer is usually $c$ itself (Linzen, 2016). For man : woman :: king, king scores 0.84 and queen 0.77, so queen is the answer only because king is ruled out. This rule has been standard since Mikolov et al. (2013), and it can make analogies look more striking than they are (Nissim et al., 2020).
Why does this work? King and queen appear in many of the same contexts—royalty, thrones, crowns—so their co-occurrence patterns are similar. They differ mainly in gendered contexts, and that difference is the same one that separates man from woman. Because GloVe embeds words so that dot products approximate log co-occurrence counts, these shared and differing patterns become geometric structure: the difference vector $\overrightarrow{\text{king}} - \overrightarrow{\text{queen}}$ points in roughly the same direction as $\overrightarrow{\text{man}} - \overrightarrow{\text{woman}}$.
Try Your Own
Identifying Subspaces
The consistency of these analogies suggests that many word pairs share a common direction—one we can find systematically rather than stumble across one pair at a time.
Consider the difference vectors for several gendered pairs: $\overrightarrow{\text{woman}} - \overrightarrow{\text{man}}$, $\overrightarrow{\text{she}} - \overrightarrow{\text{he}}$, $\overrightarrow{\text{queen}} - \overrightarrow{\text{king}}$. If gender is captured by a low-dimensional subspace,A direction is a unit vector, an arrow of length one. A subspace is everything you can reach by adding up multiples of some directions, none of which is a combination of the others. One direction gives a line through the origin, two give a plane, and $k$ give a $k$-dimensional subspace. these difference vectors should all point in roughly the same direction. And they do, far more than chance: the cosines between these three are 0.44 to 0.64, while 99% of cosines between differences of random word pairs fall below 0.31.
Gender is not the only concept that shows up this way. Here are word pairs that differ primarily in size:
To find such a subspace systematically, we collect many such pairs and compute a scatter matrix from their difference vectors. Given $p$ pairs $(w_i^+, w_i^-)$, let $\boldsymbol{\delta}_i \defeq \overrightarrow{w}_i^+ - \overrightarrow{w}_i^-$ be the difference vector for the $i$th pair. The scatter matrix $\mathbf{C} \defeq \sum_{i=1}^{p} \boldsymbol{\delta}_i \, \boldsymbol{\delta}_i^\top$ is a $D \times D$ positive semidefinite matrix whose top eigenvector is the unit vector $\overrightarrow{u}$ that maximizes $\sum_{i=1}^{p} (\overrightarrow{u} \cdot \boldsymbol{\delta}_i)^2$. Taking the eigendecomposition $\mathbf{C} = \mathbf{U} \boldsymbol{\Lambda} \mathbf{U}^\top$ and keeping the top-$k$ columns of $\mathbf{U}$ gives an orthonormal basis $\mathcal{B} = \{\overrightarrow{u}_1, \dots, \overrightarrow{u}_k\}$ for the subspace that best explains the pair differences. We name $\mathcal{B}$ after the pairs used to find it: gendered pairs give the gender subspace, size pairs the size subspace. The name is a label, not a guarantee. Ranking the 10,000 most common words along $\overrightarrow{u}_1$ puts pregnancy, babies, mothers, and women's names at one end, and defensive, tackle, NFL, and men's names at the other: gender, mixed with the topics the text pairs with it.
Since $\mathbf{C}$ is a sum of $p$ rank-one matrices, it has rank at most $p$—so with 10 word pairs, at most 10 eigenvalues are nonzero. Truncating to $k \le p$ focuses on the dominant directions and discards weaker ones. Choosing $k$ involves a tradeoff: too small and we miss secondary directions of the concept (e.g., pronouns and names may carry gender along different directions); too large and we remove variation unrelated to the concept, distorting the embedding. In practice, examining the eigenvalue spectrum of $\mathbf{C}$ helps—a sharp drop after the first few eigenvalues suggests the concept is low-dimensional. Bolukbasi et al. (2016) used $k = 1$; in this article, we use $k = 10$, the full rank of our 10 gendered pairs. With 10 pairs in a 100-dimensional space, this removes 10 of the 100 dimensions. Our 10 pairs are pronouns and basic gender words: she/he, her/him, hers/his, herself/himself, woman/man, girl/boy, girls/boys, gal/guy, female/male, and females/males. Pairs like queen/king are left out, so we can test on them below.
Steering by Subspace Projection
Once we have a subspace, we can steer the embeddings by projecting it out. Bolukbasi et al. (2016) call a related operation debiasing. Theirs differs from ours: they remove the subspace only from words that should be gender-neutral, such as occupations, and keep pairs like grandmother/grandfather apart. We remove it from every word. We say steering because the same operation applies to any subspace, not only to bias.
The idea is simple: to remove a concept, subtract each word's projection onto that subspace and renormalize.
$$\begin{aligned} \overrightarrow{w}_{\text{steered}} &\defeq \frac{\overrightarrow{w} - \overrightarrow{w}_{\mathcal{B}}}{\|\overrightarrow{w} - \overrightarrow{w}_{\mathcal{B}}\|} \\ \text{where} \quad \overrightarrow{w}_{\mathcal{B}} &\defeq \sum_{j=1}^{k} (\overrightarrow{w} \cdot \overrightarrow{u}_j) \, \overrightarrow{u}_j \end{aligned}$$
This removes each word's component along the chosen subspace and keeps the rest of the vector. The renormalization step is not inherent to the projection—it is a consequence of working with unit-length vectors. Our similarity is a dot product, which equals cosine similarity only for unit vectors, so we renormalize after projection to stay on the unit sphere.
The animation below walks through the full pipeline: it starts from gendered word pairs, moves their difference vectors to a common origin to reveal a shared direction, and projects that direction out. A caveat: the animation runs in the 2D or 3D layout you see, not in the original 100 dimensions, and it shows the projection without the renormalization. In 100 dimensions, the direction, the projection, and the renormalization all happen in a space we cannot visualize directly—MDS gives us a faithful summary of distances, but not of directions.
The plot below shows the real result: steering computed in the full 100-dimensional space, then projected to 2D via joint MDS over both the original and steered positions. Faded dots mark where each word started; trails show how it moved:
Steering in Action
Before steering, the analogy man : woman :: doctor yields nurse. As with king, the word most similar to $\overrightarrow{\text{doctor}} + (\overrightarrow{\text{woman}} - \overrightarrow{\text{man}})$ is doctor itself (0.87). Next comes nurse (0.77), ahead of physician (0.72), which is doctor's nearest neighbor. That nurse outranks physician reflects a gendered association in the embeddings:
After steering, both man : woman :: doctor and woman : man :: doctor yield physician. But this result is guaranteed: woman/man is one of the pairs we used to find the subspace, and steering makes $\overrightarrow{\text{woman}}$ and $\overrightarrow{\text{man}}$ identical, so the analogy reduces to doctor's nearest neighbor:
A fairer test uses a pair that steering never saw. There, gender survives: king : queen :: doctor still yields nurse, though its lead over physician shrinks from 0.17 to 0.05.
Discussion
Subspace projection removes directions learned from example pairs and leaves the rest of each vector unchanged, apart from renormalization. It has limitations worth noting.
Projecting out a subspace discards information indiscriminately: if some gender information is useful for a downstream task—distinguishing actress from actor, for example—it will be lost along with the unwanted stereotypical associations.
Steering is only as good as the subspace it removes, and that subspace has to be learned from examples. It can be a poor fit: it may describe the example pairs rather than the concept, or the concept may not be linearly encoded at all, in which case no subspace captures it. Either way, the fit should be measured, for example by testing the subspace on pairs that weren't used to learn it. Ours only partly passes: steering weakens gender in words it never saw but doesn't remove it, as the king : queen :: doctor example shows. Gonen & Goldberg (2019) found the same for debiasing methods generally, and Wang et al. (2020) showed that word frequency distorts the learned direction.
More recent work has explored alternatives: Zhao et al. (2018) proposed learning gender-neutral embeddings during training rather than correcting them post hoc, and Ravfogel et al. (2020) proposed iteratively projecting out every direction a classifier can exploit, removing a concept more thoroughly than a single projection. Belrose et al. (2023) did this in closed form, provably preventing any linear classifier from detecting the concept while changing the embeddings as little as possible. These methods address some of the limitations here, but the core idea—that a concept shared by many word pairs shows up as a subspace we can find and remove—remains foundational. The same linear structure that makes analogies possible also makes steering possible.
The same idea applies to other embeddings: my research graph lays out my papers and blog posts with MDS, and each slider scales one topic's coordinates, so setting it to 0 removes that topic from the layout.
Explore
Try it yourself: type word groups below (one group per line). Words on the same line are plotted together and connected by arrows. Special lines:
word - word— a steering pair, also plotted. The hyphen needs a space on each side, so hyphenated words likex-rayare read as one word.~ a - b, c - d— steering pairs that are not plotted (~ label: a - b, ...also works; the label is ignored).? a : b :: c— analogy: solves for the fourth word, leaving out $a$, $b$, and $c$.> label: a - b, c - d— direction arrow: the top eigenvector of the pairs' scatter matrix $\mathbf{C}$.> label: w1 w2 w3— direction arrow: the top principal component of the words, pointing from the first to the last.= connect— also join the $i$th word of each line to the $i$th word of the next.# label— draw a labeled outline around the words of the lines below it, up to the next#line (a bare#ends the group). The outline is convex, so it also takes in any word that falls inside it.
With steering pairs, the plot shows where each word starts and where steering moves it, or, if there is an analogy line, the analogy solved after steering. Steering with $p$ pairs projects out $k = \min(p, 10)$ dimensions. With 10 pairs or fewer, that is every direction the pairs span, so the two words of each pair end up as the same vector.
Closing Remarks
This article grew out of a homework assignment co-written with David Mueller for a machine learning course at Johns Hopkins University.
I wrote this article with extensive help from Claude Code. The framing and the final editorial decisions are mine, as are any mistakes.
Found an error or have a suggestion? Please open an issue on GitHub.
References
- Belrose, N., Schneider-Joseph, D., Ravfogel, S., Cotterell, R., Raff, E., & Biderman, S. (2023). LEACE: Perfect linear concept erasure in closed form. In NeurIPS.
- Bolukbasi, T., Chang, K.-W., Zou, J., Saligrama, V., & Kalai, A. (2016). Man is to computer programmer as woman is to homemaker? Debiasing word embeddings. In NeurIPS.
- Devlin, J., Chang, M.-W., Lee, K., & Toutanova, K. (2019). BERT: Pre-training of deep bidirectional transformers for language understanding. In NAACL.
- Gonen, H., & Goldberg, Y. (2019). Lipstick on a pig: Debiasing methods cover up systematic gender biases in word embeddings but do not remove them. In NAACL.
- Harris, Z. S. (1954). Distributional structure. Word, 10(2–3), 146–162.
- Linzen, T. (2016). Issues in evaluating semantic spaces using word analogies. In RepEval Workshop.
- Maas, A. L., Daly, R. E., Pham, P. T., Huang, D., Ng, A. Y., & Potts, C. (2011). Learning word vectors for sentiment analysis. In ACL.
- Mikolov, T., Chen, K., Corrado, G., & Dean, J. (2013). Efficient estimation of word representations in vector space. arXiv:1301.3781.
- Nissim, M., van Noord, R., & van der Goot, R. (2020). Fair is better than sensational: Man is to doctor as woman is to doctor. Computational Linguistics, 46(2), 487–497.
- Pennington, J., Socher, R., & Manning, C. D. (2014). GloVe: Global vectors for word representation. In EMNLP.
- Potts, C. (2015). Distributed word representations: overview. Lecture slides, CS224U, Stanford University.
- Ravfogel, S., Elazar, Y., Gonen, H., Twiton, M., & Goldberg, Y. (2020). Null it out: Guarding protected attributes by iterative nullspace projection. In ACL.
- Wang, T., Lin, X. V., Rajani, N. F., McCann, B., Ordonez, V., & Xiong, C. (2020). Double-hard debias: Tailoring word embeddings for gender bias mitigation. In ACL.
- Zhao, J., Zhou, Y., Li, Z., Wang, W., & Chang, K.-W. (2018). Learning gender-neutral word embeddings. In EMNLP.