Embeddings: giving every token a meaning
We gave every token a number. But why should hare be closer to rabbit than to Tuesday?
Can we feed the ids into the network?
Last time we turned text into a list of ids, and numbers are what a network takes. So let us simply feed them into the network.
Try the IDs below. “Hat” and “hare” happen to be neighbours; “hare” and “rabbit” are far apart.
The numbers are labels, not measurements of meaning. Feeding them in as quantities would suggest relationships that the vocabulary never promised.
We do not want to give the model a false picture of what the tokens mean. So instead of deciding the meaning for it, we let the model learn its own representation of each token.
A value that the network learns
Give each token an entry in an embedding table. The ID tells us where to look.
Start the entries randomly, then let prediction errors train them along with the rest of the network.
So the network learns a useful representation of each token, rather than treating its ID as a meaningful measurement. Looking a token up is just reading its entry: nothing is multiplied or added in the lookup itself.
One number is not enough
A single number can only place a token along a line, and tokens are alike in many ways at once. Two numbers make a map, and more numbers leave room for more kinds of meaning.
The number of coordinates is the model’s width, also called its hidden size. Designers choose it before training.
A token’s list of coordinates is its embedding. The table holds one such list per vocabulary entry.
What the model learns
Here is a real embedding table, but a tiny one: 60 tokens (here, whole words), each with 64 numbers, learned by a small model from made-up sentences. Watch a sentence become an input table: one column for each token of the sentence.
Explore the map below. Do tokens used in similar settings end up near one another?
This is a two-dimensional projection of much larger vectors. Neighbours are a clue, not a guarantee of similar meaning.
The input embedding stays the same for a token in every sentence. Later layers build its context-dependent representation.
How big is the embedding table?
The table has one column for every token in the vocabulary, and each column is as tall as the width. So its size follows from the two choices we have met: how many tokens, and how many numbers for each.
The embedding table is large before anything has been learned: over a gigabyte in four of these five models (at 2 bytes per number), and about 150 MB in GPT-2. And a narrow model with a huge vocabulary (Gemma) can end up with a smaller embedding table than a wide model with a smaller one (Llama).
The output needs a table of the same shape. Some models reuse the input table; others learn a separate one.
GPT-2 and Gemma share it. Llama 3.1 and DeepSeek-V3 keep separate tables.
Now we can build a language model
We now have both ends of the network.
- In: an input table, one column for every token.
- Out: one output neuron for every token, predicting the next one.
In between, we want a very large network. But stack many layers and the learning signal fades. The fix was the residual stream: run the data straight through on one line, and hang each layer off it as an offshoot that adds to it.
So the input table is the stream. Hang layer after layer off it, then read the last column for the prediction.
A sentence on its way through a language model
The output gives every token a score; softmax turns those scores into probabilities. We choose the next token, append it and continue.
But why read only the last column? That is the next story.
Sources and assumptions
- Bengio and colleagues: A Neural Probabilistic Language Model (2003), for learned distributed representations.
- Model shapes and tied output weights: GPT-2 config, Llama 3 report, DeepSeek-V3 config, gpt-oss config, and Gemma 2 report.
Table sizes count vocabulary entries × hidden width, at two bytes per number, before serving overhead. The embedding demonstration uses a small trained model and made-up sentences; the map is a projection of its vectors, not a map of a commercial model’s knowledge.