Token Embeddings and Position
From an ID to a vector
If a vocabulary has 50,000 tokens and each embedding has 768 numbers, its embedding table has shape [50000,768]. Looking up token ID 42 returns row 42. The table is learned during training; the integer 42 itself is not a semantic measurement.
For a tiny example, use token embeddings bank=[0.8,0.2], river=[0.1,0.9], and money=[0.9,0.1]. These two-dimensional values are invented to illustrate the idea. Real learned dimensions are not reliably interpretable as named axes.
Context changes the representation
The same initial embedding for “bank” can become different contextual representations in “river bank” and “bank transfer.” Transformer layers combine information from the surrounding allowed tokens. Do not confuse a fixed token embedding lookup with a contextual hidden state produced after processing a sequence.
Sentence embedding models produce vectors meant for comparing whole passages. Taking an arbitrary hidden state from a language model is not guaranteed to yield a good search representation. Pooling strategy and training objective matter.
Position makes order available
Self-attention without a positional mechanism cannot by itself distinguish every permutation of the same token set. Sequence models therefore incorporate order information. Approaches include learned position embeddings, sinusoidal encodings, relative-position biases, and rotary positional embeddings, often called RoPE.
“Customer refunded merchant” and “Merchant refunded customer” contain the same words but mean different things. Position helps the model represent the order; it does not guarantee correct reasoning about the sentence.
flowchart TD A[Token ID sequence] --> B[Learned embedding vectors] C[Position information] --> D[Position-aware sequence processing] B --> D D --> E[Contextual representations]
Memory and scale example
The illustrative table above contains 50,000×768 = 38,400,000 values. At two bytes per value its raw storage is about 76.8 million bytes, excluding alignment and other model weights. Some architectures share embedding and output-projection weights; others do not.
Checkpoint with answers
Does a larger token ID mean a stronger semantic concept? No. IDs index a vocabulary.
Are token embeddings and document embeddings interchangeable? No. They have different purposes and may use different encoders, dimensions, and normalization.
Exercise: A sequence has 10 tokens, each with 16 embedding values. What is its embedding-array shape before adding a batch dimension? Answer: [10,16].