Part II ยท Representation
Ch 5. Meaning as position
From ID to a list of numbers
A tokenโs number is just a label: 3797 says nothing about cats. So GPT-2 swaps each token for a long list of numbers, called an embeddingembedding: A list of numbers (a vector) that stands for a token, learned during training. Ch 5. Step through to see the running example become lists of numbers. (Only the first 48 numbers are drawn; striped cells are negative.)
A token ID is just a label: 3797 for โ catโ says nothing about cats. So the first thing GPT-2 does with each token is look up a list of 768 numbers for it, called an embeddingembedding: A list of numbers (a vector) that stands for a token, learned during training. Ch 5 or a vector. Step through to see the running example become vectors. (Only the first 48 numbers are drawn; striped cells are negative.)
Nobody chose these numbers. They start out random and are adjusted during training, which Part III explains. After training, tokens that are used in similar ways end up with similar lists.[1][1][1]
A lookup table
GPT-2 keeps every tokenโs vector in one table, , with a row for each of its 50,257 tokens and 768 columns. Turning token into its vector just reads row :
where is a list of 50,257 zeros with a single 1 in place . Multiplying by it picks out one row, which is why training can adjust the table like any other weights. The table holds 50,257 ร 768 = 38,597,376 numbers, about 31% of GPT-2 smallโs 124 million weights, and GPT-2 uses it twice: at the end of the model, the same table turns the final vector back into a score for every token.
Similar meanings, nearby points
A list of numbers can be read as a place: two numbers mark a point on a flat map, three a point in a room, and longer lists mark points in a space with more directions. Nearby points mean similar things.
A list of numbers can be read as a position. Two numbers place a point on a flat map, and three place it in a room; 384 or 768 numbers place it in a space with that many directions. Nearby points have similar lists, and similar lists turn out to mean similar things.
The map below uses a small model built for comparing meanings.[2] Pick a word to see its nearest neighbors, and drag the map to turn it.
The map below uses all-MiniLM-L6-v2, a small model built for comparing meanings, which turns any text into 384 numbers.[2][2] Pick a word to see its nearest neighbors, and drag the map (or use the sliders) to turn it and see it from another side.
The map squashes many numbers down to three directions, so a few neighbors may look far apart on it.
The map is a squashed view. Squashing 384 numbers down to three directions loses most of the detail, so a few neighbors may look far apart on the map, and turning it shows words that looked close from one side sitting far apart from another. The lists of neighbors and similarity scores use all 384 numbers.
Measuring โnearbyโ
The neighbors are ranked by cosine similarity, which compares the directions of two vectors and and ignores their lengths:
where is the -th number in . It is 1 when the vectors point the same way, 0 when they are at right angles, and โ1 when they point opposite ways; cat and kitten score 0.79. This modelโs vectors all have length 1, so here cosine similarity is just the sum .
The map comes from principal component analysis: it keeps the three directions along which these wordsโ vectors spread out the most, and drops the other 381. Those three directions hold only about 18% of the spread, which is why neighbors on the map can mislead.
Directions mean something too
Tick Show king โ man + woman. Start at king, take away man, add woman, and the nearest word is queen. So directions in the space can carry meaning, like the step from man to woman. It doesnโt work for every pair of words.[3]
Tick Show king โ man + woman. Taking the vector for king, subtracting man, and adding woman gives a list of numbers whose nearest word on this map, comparing all 384 numbers, is queen. That works because the step from man to woman partly lines up with the step from king to queen: the two are about 75ยฐ apart in all 384 numbers, where parallel would be 0ยฐ. Thatโs still closer than most steps between these words. So donโt expect parallel arrows on the map; their angle changes as you turn it. This famous example was first shown in 2013 with word vectors from a model called word2vec.[3][3] It doesnโt work for every analogy, and on this map it only has a few dozen words to choose from, but it shows that directions in the space can carry meaning.
In vectors, the search finds the word whose vector is most similar to
by cosine similarity, where is the vector for word .[3] The search skips the three words that went in. Counted with them, the nearest word is king itself, at 0.63 against 0.58 for queen: the sum lands close to where it started, and queen is only the best of the rest.
Recipe card
Recap
- Each token is turned into a vector: a list of numbers (768 for GPT-2 small).
- The numbers are learned, and tokens used in similar ways end up with similar vectors.
- Similar vectors are nearby points, and some directions carry meaning, like man to woman.
- An embedding is a row of a learned table; nearness is cosine similarity, the angle between vectors.
Next question: a model turns these vectors into a chance for every next token. What is that calculation made of, and where do its numbers come from?
Sources
- Alec Radford et al. (2019). Language Models are Unsupervised Multitask Learners. OpenAI.
- Sentence Transformers (2021). all-MiniLM-L6-v2 model card. Hugging Face. Accessed October 23, 2026.
- Tomas Mikolov et al. (2013). Linguistic Regularities in Continuous Space Word Representations. NAACL-HLT 2013.
Sources
- Alec Radford et al. (2019). Language Models are Unsupervised Multitask Learners. OpenAI.
- Sentence Transformers (2021). all-MiniLM-L6-v2 model card. Hugging Face. Accessed October 23, 2026.
- Tomas Mikolov et al. (2013). Linguistic Regularities in Continuous Space Word Representations. NAACL-HLT 2013.
Sources
- Alec Radford et al. (2019). Language Models are Unsupervised Multitask Learners. OpenAI.
- Sentence Transformers (2021). all-MiniLM-L6-v2 model card. Hugging Face. Accessed October 23, 2026.
- Tomas Mikolov et al. (2013). Linguistic Regularities in Continuous Space Word Representations. NAACL-HLT 2013.