Word Embeddings

How machines learn meaning in a vector space

What are word embeddings?

AnalogyDefinition

Picture a huge city where every word is a house. Words with similar meaning live in the same neighbourhood: "dog" and "cat" as next-door neighbours, "Berlin" and "Paris" two streets over in the capitals district.

Here is the magic: directions in this city carry meaning. The walk from "man" to "woman" goes the exact same distance and direction as "king" to "queen". That is exactly what this demo measures: king − man + woman ≈ queen.

How do word embeddings work?

A model reads billions of sentences. From each sentence it learns: which words tend to appear in the same context? From those signals it builds one vector per word — usually 50 to 300 dimensions — so that contextually similar words get similar vectors.

  1. 1
    Skip-gram / CBOWThe model predicts each word's neighbours (or vice versa) and updates the vectors so the prediction gets better.
  2. 2
    Semantic axesDuring training, latent directions emerge — "gender", "capital-of-country", "plural" — without anyone programming them.
  3. 3
    2D projectionFor display, the 100-dimensional space is flattened to 2D with PCA. Clusters stay visible, but distances on the map are only roughly right — that's why neighbours and analogies are calculated on the full vectors.
  4. 4
    Vector arithmeticBecause semantic axes exist as directions, a − b + c works as an analogy operation. The classic example is king − man + woman ≈ queen.

Interactive demo — explore the meaning space

This map is the meaning space: every dot is a word, the coloured areas are topic clusters, and spatial closeness means similar meaning. Drag to pan, scroll or pinch to zoom. Pick a task below.

The map in words

This map turns meaning into place: words become locations, and the paths between them become directions. If you cannot see the canvas, here is the shape the numbers below leave out.

What you see
Around 190 small dots scattered across the field like a night sky. Dots of the same colour huddle into islands: the animals sit in one corner, the countries in another, the emotions somewhere else again. The closer two dots lie, the more alike their meaning.
What happens
Click a word and short lines reach out to its nearest neighbours in the same neighbourhood. In the arithmetic task an arrow appears, and the result drops in as a new dot right where the expected word already sits. Analogies show up as parallel arrows: the step from king to queen points the same way as the step from man to woman.
What you can do
Three tasks are ready: Neighbourhood shows a word's closest neighbours, Arithmetic lets you try a − b + c, and Challenge quizzes you on analogies. You can click individual dots, drag the map, and zoom.
What to watch for
Watch the parallel arrows. That king-to-queen takes the same path as man-to-woman is no accident — the model has learned a rule like gender as a fixed direction in space. That is exactly why meaning here becomes nearness and direction.
Drag to pan · scroll to zoom

Every word is a point in space. Click one — the highlighted neighbours are the most similar in meaning, measured by cosine similarity.

Auto-complete: arrow keys + Enter, or just click.

Click a point in the space or search a word to see its nearest neighbours.

Loading embeddings…

Where word embeddings live

Embeddings are not a gimmick — they are the foundation of almost every modern language AI:

Semantic search

Search engines find documents by meaning, not just exact words — a search for "car" also finds "vehicle".

Recommender systems

Similar products, songs or articles are found via the closeness of their vectors — "you might also like".

Machine translation

Multilingual embeddings align different language spaces with each other — the basis of modern translators.

Language models (LLMs)

Every token in ChatGPT and friends starts as an embedding — it is the very first layer of every transformer.

Key takeaways

  1. Words become vectors: every word gets a position in space — learned from the context it appears in.
  2. Closeness means meaning: semantically similar words sit close together; this is measured with cosine similarity.
  3. Directions carry meaning: the same step as man→woman leads from king→queen — which is why king − man + woman ≈ queen.
  4. Learned, not programmed: the semantic axes emerge on their own during training on billions of sentences.
  5. Limit of static embeddings: one word has exactly one vector; polysemy is only solved by contextual models like BERT.

Did you get it?

  • I can explain why words with similar meaning sit close together in the space.
  • I understand what cosine similarity between two word vectors measures.
  • I can follow why king − man + woman ≈ queen works.
  • I know the main limit of classic (static) embeddings: one word, one vector.

Test your knowledge

Question 1 / 4
Not completed

Why does "king − man + woman ≈ queen" actually work?

Select one answer
Answer Key: 1) A · 2) B · 3) C · 4) B
TheoryHistoryPseudocodeStep by StepFlow Diagram

Words as points in space

A computer cannot do anything with the text king — but it can with numbers. A word embedding assigns each word a vector of many numbers (in practice 50 to 300 dimensions). The trick: words with similar meaning get similar vectors and thus lie close together. That turns meaning into a geometry that can be measured and computed with.

The basic idea: you recognize a word by its company

How is the model supposed to know that cat and dog are related? From context. Both often appear next to words like feed, fur or vet. This distributional hypothesis (Firth, 1957: You shall know a word by the company it keeps) is the core idea: words that appear in similar surroundings usually mean similar things. Nobody programs the meanings by hand — they arise purely from raw text.

Skip-gram: predicting neighbors

The word2vec method (Mikolov et al., 2013) slides a context window over the text. In the skip-gram variant, the model tries to predict a target word's neighbors from it; the reverse is called CBOW (predicting the target word from the neighbors). With every hit, the vectors involved are nudged a bit closer together, and for randomly drawn non-neighbors, further apart. This tugging across millions of sentences gradually shapes the vector space. The so-called negative sampling is an efficient approximation of the full softmax, not an exact probability calculation.

Computing with meaning

Because training produces whole directions for concepts like gender or capital-to-country, you can compute with vectors. The famous discovery from 2013: king − man + woman ≈ queen. You shift the vector for king along the gender direction and land near queen. Important: the result is the nearest vector, not an exact equation — it works for many, but not all, analogies, and the input words themselves are excluded from the search.

Properties and limits

  • Self-supervised: learns only from raw text, without any labels
  • Similarity = cosine: what is measured is the angle between vectors, not their length
  • Static: classical embeddings give every word one vector — bank (financial institution) and bank (river bank) collapse into one
  • Biases: what is in the text is also in the model — societal biases in the corpus end up measurably in the vectors

Play with the demo! Click a word and see its nearest neighbors along with the cosine value. Then switch to compute mode and try king − man + woman — or Berlin − Germany + France. Watch how well the analogy lands and where it misses.