Lab

Meaning as a map

How word vectors place each word as a point, so words used alike land close together and relationships become directions.

A language model only ever sees numbers. So how does it know that Wellington and Auckland are related, that a nurse and a doctor work in the same place, or that “bank” can mean money? Nobody wrote those facts down for it.

The answer is that every token gets a list of numbers, called an embedding, and those lists are arranged so that words used in similar ways get similar lists. Meaning becomes position: words with related uses sit near each other, and some relationships, like country to capital, become directions you can measure.

On this page you can explore a real set of word vectors in your browser: find a word’s neighbours, compute their similarity by hand, do arithmetic with meaning, and see the stereotypes that come along with them.

Before this: How text becomes tokens shows how text becomes token IDs. Each ID picks one row of the embedding table you are about to explore.

Nearest neighbours

20,271 words, 50 numbers each
Presets
Loading 20,271 word vectors (about 1.3 MB) in a background thread. Nothing you type leaves this page.
your word10 nearestnext 20compare2D map keeps – of the spread
Nobody told the model what a city is. wellington sits next to …: words that appear in the same kinds of sentences. The other Wellington, the boot, barely registers (boots: …).

From a token to a list of numbers

A model’s vocabulary is fixed: each token has an ID, and the model keeps one row of numbers for each ID in a big table. Looking a token up is just reading its row. The rest of the model works with those rows, never with the letters.

The vectors on this page come from GloVe, a well-known set of word vectors published by Stanford researchers in 2014. We use 20,271 of its most common words, each with 50 numbers: a table of 1,013,550 numbers in all. Unlike a modern tokeniser, GloVe works with whole lowercase words, so it has one row for “wellington” and none for word pieces.

Fifty numbers is not many. Each one on its own means nothing you could name; meaning is spread across all of them. What matters is how the lists compare, and that needs a way to measure “close”.

What “close” means

Think of each word as an arrow from the origin, 50 numbers long. Two arrows pointing the same way are similar; arrows at right angles are unrelated. The standard measure is cosine similarity, the cosine of the angle between them:

cos⁡(a,b)=∑i=150aibi∑ai2·∑bi2

Multiply the two lists number by number and add up the products: that is the dot product. Divide by the two lengths and you get a score from −1 (opposite) through 0 (unrelated) to 1 (same direction). Dividing by the lengths means only direction counts, not how long the arrow is.

Cosine similarity, by hand

50 numbers per word
Pairs
Loading 20,271 word vectors (about 1.3 MB) in a background thread. Nothing you type leaves this page.
#1: – × – = –
Dot product, Σ aᵢbᵢ
–
dimension 1 adds –
Length of cat
–
‖a‖ = √Σ aᵢ²
Length of dog
–
‖b‖ = √Σ bᵢ²
Cosine similarity
–
– ÷ (– × –)
Blue cells are positive, pink negative. The third row multiplies the two words number by number; adding up that row gives the dot product. … of 50 products are positive here.

The nearest-neighbour list above is just this calculation run against all 20,271 words and sorted. Because the vectors are stored at length 1, each comparison is a single dot product, and the whole scan takes a few milliseconds in a background thread.

How the vectors were learned

GloVe starts by counting. Across 6 billion tokens of Wikipedia and newswire text, it records how often each word appears within ten words of each other word, with nearby words counting more. Then it adjusts the vectors, a little at a time, until the dot product of two words’ vectors roughly predicts the logarithm of how often they appear together.

The formula, for the curiouswi·w̃j+bi+b̃j≈log⁡Xij

Here Xij is the count for words i and j, and the b terms let common words be common. The w̃ vectors are a second, separate set that GloVe learns for each word in its role as context; the released vectors add the two sets together.

Words that keep the same company end up with similar vectors, which is why Wellington lands next to Auckland, Brisbane and Christchurch: they appear in the same kinds of sentences.

Modern language models learn their embedding table differently. It is simply the first layer of the network, and its numbers are adjusted during training along with every other weight, by gradient descent. There is no separate counting step, but the effect is similar: tokens used alike drift together.

There is one big difference. In a language model, the table lookup is only the start. Layers of attention then mix each token’s vector with the vectors of the words around it, so “bank” in “river bank” and “bank” in “bank loan” end up as different vectors. Those are called contextual embeddings. GloVe stops at the lookup: one vector per word, whatever the sentence.

Directions carry meaning

If similar words sit close together, what about the step from one word to another? The step from man to king points roughly the same way as the step from woman to queen. So you can start at king, take away man, add woman, and look for the nearest word.

Analogies as arithmetic

king − man + woman
Presets
Country → capital test
–
computing
Loading 20,271 word vectors (about 1.3 MB) in a background thread. Nothing you type leaves this page.
inputstop answerother answersexpectedb − a + c
The solid arrow is the step from man to king. The dashed arrow adds the same step to woman and lands on the cross. The nearest word to the cross is … (cosine …).

The famous examples work: king − man + woman gives queen (cosine 0.853), and paris − france + japan gives tokyo. But look closer.

  • The inputs are hidden. The standard method leaves the three input words out of the answers. Tick “Allow the three input words as answers” and the top answer to king − man + woman becomes king itself (0.885). Nissim, van Noord and van der Goot (2020) showed that this rule, not the vectors, produces some well-known “biased” analogies. They stress that the vectors still encode human biases; analogies are just a poor way to measure them.
  • Many answers are near misses. On this page’s vectors, mice − mouse + child gives infants, with children near the top.
  • Two-word names break. berlin − germany + zealand gives sydney; wellington comes 13th. “New Zealand” is two tokens here, and zealand alone carries only part of the meaning.

On our small country-to-capital test, the top answer is right 46 times out of 60 (77%). In the GloVe paper, the best 6-billion-token vectors, with 300 numbers per word, score 71.7% across 19,544 analogy questions, and the paper shows smaller vectors doing worse. Analogies are a vivid demonstration, not a reliable tool.

Directions carry stereotypes too

If “man to woman” is a direction, you can measure how far any word leans along it. Average the vectors of some female words (she, her, woman, mother…), subtract the average of the matching male words, and you have a gender direction. Then take the cosine of each occupation with it.

Directions in the space

he → she

List average: –. Words near this line are ordinary for this direction.

nurse–
midwife–
receptionist–
hairdresser–
nanny–
librarian–
teacher–
dancer–
singer–
chef–
baker–
cashier–
doctor–
surgeon–
dentist–
pharmacist–
journalist–
writer–
artist–
farmer–
lawyer–
accountant–
banker–
scientist–
professor–
programmer–
engineer–
architect–
mechanic–
plumber–
electrician–
carpenter–
pilot–
soldier–
firefighter–
manager–
boss–
captain–
secretary–
Each bar is the cosine between a word and the direction from the he words to the she words. Most towards she: … (–). Most towards he: … (–).

The ranking is not subtle. midwife (0.36), hairdresser, receptionist and nurse lean towards the female words. engineer (−0.31), manager, boss and captain (−0.56) lean towards the male words. Nothing in GloVe’s training was about gender. It learned these leanings from how 2014 Wikipedia and newswire text used the words: who was written about, in which jobs, next to which pronouns. It reflects that text, not anyone’s ability.

Bolukbasi and colleagues documented this in 2016 for word2vec vectors trained on Google News, in a paper titled “Man is to computer programmer as woman is to homemaker?” They showed that a single direction captures much of the gender association, and proposed removing it. Gonen and Goldberg (2019) then showed that this mostly hides the bias rather than removing it: the gender information is still there in which words sit near which, and can be recovered from those distances. The problem carries over to modern models: any system trained on human text can inherit that text’s patterns, and measuring them is the first step.

The direction is also crude. secretary leans male (−0.34), probably because news uses it mostly in titles: its nearest neighbours are deputy, vice and affairs. A score is only as meaningful as the words you chose to define the direction.

A direction built from two groups of people’s names mostly measures how 2014 news covered those groups: which topics, events and places they were written about with. It says nothing about the people themselves.

Squashing 50 dimensions into 2

Every map on this page is flat, but the vectors have 50 numbers. To draw them we use principal component analysis (PCA). It finds the single direction along which the chosen words spread out most, then the next most spread-out direction at right angles to the first, and plots each word’s position along those two.

A map of many words

Loading 20,271 word vectors (about 1.3 MB) in a background thread. Nothing you type leaves this page.
Kept by axis 1
–
Kept by axis 2
–
Kept by this map
–
– lies in the other 48 directions
All words as a list, sorted by axis 1
Point at or tap a dot to name it. Labels are drawn only where they fit. The two axes are the directions along which these words differ most; they have no names of their own. Labels are dataset tokens, so place names appear without their macrons (taupo for Taupō).

With all five categories on, they mostly form their own regions: 204 of the 258 words (79%) have a nearest dot from their own category. Animals mix most, with occupations and with food. But the flat map keeps only part of the picture: 15.8% of the spread on the first axis and 12.9% on the second, 28.6% together. The other 71.4% lies in the 48 directions you cannot see. Two words that look close on the map can be far apart in the full space, which is why neighbour lists are always computed in all 50 dimensions, never from the picture.

What this means for local AI

Search and retrieval use the same idea. An embedding model turns a whole passage into one vector, and searching means finding the stored vectors with the highest cosine similarity to your question. That is the core of retrieval-augmented generation (RAG): find the most relevant passages first, then give them to a language model. Embedding models are small enough to run on a laptop; How RAG finds the right passage lists a few.

Vector size costs memory. Storing one million passages at 384 numbers each, 4 bytes per number, takes about 1.43 GiB. At 768 numbers it is about 2.86 GiB. Storing each number in one byte, as this page does with its own vectors, cuts the 384-number case to about 0.36 GiB at a small cost in accuracy; quantisation explains the trade-off.

In small models, the table is a big share. Qwen2.5-0.5B has a vocabulary of 151,936 tokens and 896 numbers per token. Its embedding table is 136,134,656 parameters, about 28% of the model’s 0.49 billion. Large vocabularies help many languages tokenise well, but on a small model they take a large slice of memory.

English-trained vectors see te reo Māori second-hand. GloVe learned whanau, marae and aroha only from English-language news and Wikipedia, mostly without macrons. Building better ones is not only a technical question, and How text becomes tokens explains why whose data it is, and under whose control, matters as much.

What we simplified

  • Whole words, not tokens. GloVe has one vector per lowercase word. Language models use subword tokens, so one word can be several rows of the table.
  • Static vectors. Each word has one vector regardless of context. Language models build contextual vectors on top of the table.
  • Small vectors. 50 numbers per word, where language models use hundreds to thousands. Larger GloVe vectors score better on analogies.
  • One byte per number. The vectors are stored as 8-bit integers with a scale per word. Each vector keeps a cosine of at least 0.9999 with its original, but ranks and last digits can shift a little: in the original float vectors river ranks 2,104th against bank; here it is 2,112th. Every number on this page is computed on the one-byte vectors.
  • A subset. 20,271 of GloVe’s 400,000 words: the 20,000 most common plus some chosen lists. Rare words are missing.
  • Few macrons. The source text was lowercased and mostly lacks macrons. Full GloVe has a few macron spellings, such as whānau and hapū, but this subset keeps only māori, so te reo words appear as whanau, maori and so on. Their vectors reflect English-language usage.
  • A two-dimensional map. PCA keeps the largest spread and drops the rest; distances on the maps are approximate.

Next: after the layers in between, which How attention decides what matters opens up at step 5, a model turns its final vector into a score for every token in the vocabulary, then picks one. How a model picks the next token shows how.

Inspired by, and worth your time