techtree / Building blocks
Embeddings
Each token id is looked up as a vector; similar meanings point in similar directions.
Transcript
A sentence has become a list of token ids. But an id is only a name tag. The number itself means nothing.
So the model keeps a table, with one row for each token in the vocabulary. Each row holds a list of numbers: a vector.
To embed a token, use its id to find its row. That vector is the token's embedding.
Each token in the sentence gets its own vector.
Nobody writes these numbers by hand. They are tuned, so that tokens with similar meanings get vectors that point in similar directions.
Real embeddings have hundreds of entries. These made-up ones have just two, so we can draw them.
Cat and dog point almost the same way. Their cosine similarity is point nine eight. Cat and truck point far apart: point two one.
The id says which token it is. The embedding says what it is like.
Needs
- Tokens video
Text is chopped into pieces, and each piece gets an id number. - Length, angle, and cosine similarity video
Length comes from the dot product with itself; dividing out lengths leaves the angle.
Everything this builds on (5 topics, in order)
Leads to
- Position information video
Add a position vector to each token vector so order is not lost. - Queries, keys, and values video
Three matrices turn each token vector into a query, a key, and a value.