Skip to content

Embedding Space Walk: king − man + woman, With the Rule Shown

Vector arithmetic on vectors you supply, with the metric and the exclusion rule as switches — because the famous analogy result depends on both and neither is usually mentioned.

king − man + woman, at λ 1.00
queen

Similarity 1.000. The three input vectors are hidden. Turn that off and the top of the list becomes queen — which is the part of this demo that usually goes unmentioned.

1queen
1.000
2queens
0.866
3princess
0.816
4girl
0.577
5kings
0.577
6throne
0.577
7prince
0.408
8dog
0.408
9boy
0.000
Vectors parsed
13
Dimensions
6
Target vector
1.00, 0.00, 1.00, 1.00, 0.00, 0.00
Metric
cosine similarity
Best match with the inputs excluded
queen
Best match with nothing excluded
queen
Is the top result one of your inputs?
no
Where these numbers come from: These are not embeddings from a model. They are thirteen vectors written by hand on six axes chosen to be readable, so that the arithmetic has something honest to run on — and so that you can check every number in the ranking yourself. Paste real embeddings in the box and the page will do the identical arithmetic on those; it has no way of producing them for you, and would be inventing them if it claimed to.
What this assumes: The target is a + λ(c − b), computed componentwise, with no renormalisation unless you ask for it. Cosine ignores vector length entirely, dot product does not, and Euclidean distance is sorted ascending because for it smaller is better — the three can and do disagree, which is the point of having the switch. Excluding a, b and c is a convention, not mathematics: every well-known write-up of the king−man+woman result applies it, and most do not say so. Ragged rows are zero-padded to the longest vector rather than dropped, and the padding is reported above when it happens.

What the analogy result actually shows

The famous claim is that embedding spaces have linear structure: a direction that means "female rather than male" exists, is roughly the same direction everywhere, and can be added to any vector. The arithmetic on this page is exactly the arithmetic behind that claim, and with the axes written out you can see what makes it work. Subtracting man from king cancels the shared coordinates and leaves the difference; adding woman writes a different value into the same slots. No semantics are involved anywhere — it is vector addition.

Now drag λ back towards zero with the exclusion switch off. At λ = 0.2 the target is still almost exactly king, so king is the nearest vector to it and the "analogy result" is the word you started from. This is not a defect of the toy space. It is the reason every implementation of the demo silently excludes the three input words: in real embedding spaces the offset between related words is small relative to the distance between unrelated ones, so the inputs very often outrank the intended answer. The result people quote is the result after a filter that is rarely mentioned.

Two further things this page deliberately does not hide. Cosine and Euclidean disagree whenever the candidates have different magnitudes, so "nearest" is a choice, not a fact — swap the metric and watch the ranking move. And the linear structure that makes any of this work is a property of some spaces, not all: it was strong in word2vec and GloVe, is weaker and less reliable in contextual sentence embeddings, and does not survive at all in spaces that were never trained with a co-occurrence objective. If you paste your own vectors and the analogies do not land, that is information about your model rather than an error here.

Embedding Space Walk: king − man + woman, With the Rule Shown · Multigrid