Skip to content
StackDecode
LLM Library
FoundationsAnimated

Embeddings

Each token becomes a vector of numbers that captures meaning.

The idea

An embedding table maps each token id to a learned vector. Similar tokens end up with similar vectors, and later layers refine them using context.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

× N layersText inTokenizerEmbedding + positionNormCausal self-attentionAdd (residual)NormFeed-forward (MLP)Add (residual)Final normLM head (vocabulary scores)Softmax, then sample next token

Raw text enters the system, for example "The cat sat on the".

stage:
1/12
part:
Text in
1/12

The green dot is one token travelling through the model. The boxed section repeats for every layer.

Step by step

  1. 1Look up the vector for each token id
  2. 2Stack them into a matrix
  3. 3Add position information
  4. 4Pass the matrix into the first layer

Where it is used

The first step of every transformer; also used for search and RAG.

Watch out for

The same word has the same starting vector. Context is added by attention in later layers.