Lab · Interactive exhibit LAB-07
Word map: words that are alike sit close together
A language model does not know what “cat” means. It knows which words it appears next to. Here we compute, in front of you, a small map of words from 59 sentences. Add your own and watch the map change.
Algorithm: real PPMI and t-SNE computation, running locallyThe map
● selected word · ◆ its closest neighbour · positions are nudged slightly so that labels do not overlap
Select a word to see its closest neighbours. With a keyboard: Tab into the map and use the arrow keys to change word.
Change the data
Write a sentence using words from the map. The map is recomputed from scratch with your sentence. Try adding the same sentence two or three times.
Ready-made tests
What is computed here
- Each sentence is split into words. Very frequent words such as “and” or “the” are ignored. Different forms of a map word, such as “dog” and “dogs”, are joined using a hand-made list. Other words are reduced by removing common endings.
- We count how often each map word appears in the same sentence as every other word. The counts become weights using PPMI (positive pointwise mutual information), which gives more value to co-occurrences that are not explained simply by how frequent the words are.
- Each word thus becomes a list of numbers, a vector. Two words are similar when their vectors point in the same direction. This is measured with cosine similarity, from 0 to 1.
- To fit the dimensions of the context vectors onto a screen, the map starts from the two directions with the largest variance (principal component analysis). It then adjusts the positions with t-SNE, a method that tries to keep close together the words that are also close in the full vectors. Small distances within a group are meaningful. Large distances between groups are not precise. That is why the neighbours in the right-hand column are computed from the full vectors, not from distances on the map.
What to look for
- The word “mouse” sits between the animals and the computers, because it appears in both groups of sentences. A static vector cannot separate the two meanings. Today’s models with an attention mechanism give the word a different representation depending on the sentence.
- “Fish” sits close both to the sea and to the kitchen. The map does not know what a fish is. It only knows which sentences it met it in.
- What you write changes the relationships. If you add “the cat plays guitar” several times, the cat moves towards music. In the same way, the biases of a large body of text pass into the models trained on it.
What this experiment is not
It is not a real language model and it uses no pre-trained embeddings. The 59 sentences were written by the Museum of AI so that the groups are clearly visible. Large models learn their vectors with neural networks from billions of words, with hundreds or thousands of dimensions. The core idea is the same, though: the meaning of a word is approximated by the words that accompany it. Sentences you add stay on the page only and are lost when you close it.
Documentation
The idea that a word’s meaning shows in the words around it goes back to mid-twentieth-century linguistics, best known in J. R. Firth’s 1957 formulation. The experiment uses the mutual-information measure proposed by Church and Hanks and the context smoothing (α = 0.75) examined by Levy, Goldberg and Dagan.
- Church, K. W. & Hanks, P. (1990), Word Association Norms, Mutual Information, and Lexicography, Computational Linguistics 16(1)
- Mikolov, T. et al. (2013), Efficient Estimation of Word Representations in Vector Space
- Levy, O., Goldberg, Y. & Dagan, I. (2015), Improving Distributional Similarity with Lessons Learned from Word Embeddings, TACL 3
See also in the Museum
- 5.2 Words become numbers
- 6.2 Tokenisation
- Curatorial feature: What do we mean when we say a machine “dreams”?
Curatorial note: The map is a real computation on a very small, curated corpus. It does not show the internal state of any existing model.