the basics · lab 1 of 2

How a Model Reads

A language model cannot read letters. Everything it will ever see is a number, and the journey from text to numbers happens in two steps: tokens, then embeddings. Every number in this lab is real; work through the three stations in order.

back to the contents

The three stations:

  1. 1From letters to tokens
  2. 2From tokens to numbers
  3. 3What did the numbers learn?

lab 1: how a model reads

How a Model Reads

A language model cannot read letters. Everything it will ever see is a number, and the journey from text to numbers happens in two steps. First the text is chopped into pieces called tokens. Then each token is swapped for a long list of numbers called an embedding. This lab builds both steps from scratch, and ends with the trick that makes embeddings useful: measuring how similar two meanings are.

1.From letters to tokens

The problem: a model has a fixed table of entries (its vocabulary) but language never stops producing new words. The fix is to learn the pieces instead of the words. The algorithm, byte-pair encoding (BPE), is almost embarrassingly simple: start with single characters, count which two neighboring pieces appear together most often, and glue them together. Repeat millions of times. Frequent words become single tokens; rare words stay as readable fragments.

Work through it yourself. Each click of Learn a merge performs one real fusion on a nine-word corpus, exactly as the algorithm would.

Lab 1a: teach a tokenizer from scratch

Click Learn a merge repeatedly. Each click fuses the most frequent adjacent pair in the corpus.

merge 0 of 6

training corpus (9 words, _ marks the end of a word):

l o w _l o w _l o w _l o w e r _l o w e s t _n e w e s t _w i d e s t _n e w _n e w e s t _

learned vocabulary so far (11 tokens): the 11 characters that appear in this corpus, plus every merged pair:

nothing learned yet

now tokenize a word with what the tokenizer knows (training words in bold):

lowest + end-marker → l · o · w · e · s · t · _

Byte-pair encoding (BPE) starts from single characters and repeatedly fuses the most frequent adjacent pair. Watch the cascade: l + o becomes lo (appears 5 times), lo + w becomes low, then e + s, es + t, est + _. Frequent words compress into single tokens (lowest reads as low · est_ after five merges); rare words stay in pieces. Real models repeat this millions of times over terabytes of text, which is how GLM-5.3-Flash ended up with a 154,000-entry vocabulary while Kimi K3 uses 163,840.

Notice what the merges bought us. After five rounds, lowest reads as two tokens instead of seven, and a word the corpus never contained, like slowly, still tokenizes into sensible pieces. That is the whole trick that lets a 154,000-token vocabulary cover all of English, code, and most of the internet.

2.From tokens to numbers

Now the model needs to turn the token king into something it can do arithmetic with. It keeps a giant table: one row per vocabulary entry, where each row is a vector of numbers (4,096 of them in GLM-5.3-Flash; we use 4 here so you can see every digit). Finding a token's embedding is literally looking up its row. The interesting question is what those numbers mean and how the model compares two of them. The answer is one operation you already know from grade school: multiply matching positions and add everything up.

Lab 1b: an embedding is just a row of numbers

Pick two words. The table multiplies their vectors dimension by dimension; that is the whole calculation.

word A:
word B:
dimensionkingqueenproduct
royal0.900.850.90 × 0.85 = 0.765
gender0.500.550.50 × 0.55 = 0.275
fruit0.100.150.10 × 0.15 = 0.015
size0.800.750.80 × 0.75 = 0.600
dot product (sum)1.655
cosine similaritydot ÷ (‖king‖·‖queen‖) = 0.997

Above 0.9: these vectors point in nearly the same direction. The model treats these words as close.

Where does the number come from? Every token gets a row in a giant lookup table (the embedding matrix): one row per vocabulary entry, 4,096 numbers per row in a model like GLM-5.3-Flash. The values are not designed by anyone; they are learned so that words used in similar contexts end up with similar rows. The numbers in this toy carry names like “royal” only so you can read them; real models have thousands of dimensions with no human names.

That score, the cosine similarity, is the model's only notion of “these two words are related.” There is no dictionary anywhere in the model. There are only vectors that point in similar directions.

3.What did the numbers actually learn?

Nobody tells the embedding table that king and queen are related. During training the model sees billions of sentences and is repeatedly asked to predict the next word. To be good at that, it is forced to place words used in similar contexts at similar coordinates. king and queen appear before of England, wore a crown, and ruled for in the same ways, so their vectors drift together. Words that never share contexts (say, banana and king) end up far apart, even though both are perfectly ordinary words.

This gives us a genuinely useful test for whether two concepts are similar, and it has nothing to do with definitions. Throw a word at the map below: it lands next to the words the model would score as its closest neighbors.

Lab 1c: the dart map

1. Pick a word: its 2D position is its embedding. 2. Click anywhere on the map to throw. 3. Read the distances.

1. your word:
kingqueenprincemanwomanchildbananaapplemangocartruckbicyclesadhappyangrypythonjavascriptcompilerpick a word above to begin

dashed teal circles are equal-distance lines around your word: everything on one ring is equally similar to it.

This is really how similarity works inside a model, just in more dimensions: each word is a point, similarity is a distance computation, and “finding similar words” means ranking every point by distance. The only simplification here is the count of dimensions: 2 instead of 4,096. Opposite meanings (happy, sad) still land close because similarity measures shared context, not sameness. Attention (lab 2) runs this ranking before every single word a model reads.

Two things on that map are worth remembering forever. First, opposites land close together (happy next to sad) because similarity measures interchangeability of context, not sameness of meaning. Second, the map has countries nobody designed: feelings, fruits, vehicles, programming languages. The geography emerged from text statistics alone. Keep both facts in mind and half of every model guide on this site becomes common sense.