02 · B · Embed
Embeddings and position
Tokens enter a vector space. RoPE injects order by rotating query/key pairs.
Token embedding
A learned matrix stores one row per token. Looking up token is a gather; equivalently, a one-hot times .
- token embedding matrix, V×d
- the d-vector for token x_t
- one-hot sequence, T×V
Absolute position (GPT-2 style)
Without a position signal the Transformer is a bag of tokens. Absolute embeddings add a learned vector per index.
- learned positions, T_max × d
- residual-stream vector at layer 0
RoPE (Llama-style default)
Rotary position embeddings (Su et al., 2021) add no extra vector to the residual stream. After Q and K are formed, each even/odd pair of coordinates is rotated by an angle that depends on position. Inner products then depend on the difference , not on absolute and separately.
- head dimension (even)
- pair index 0, 1, …, d_h/2 − 1
- base frequency, usually 10,000 (or a long-context variant)
Write for the block-diagonal matrix of all pair rotations at position . Rotations compose, and :
Why it mattersThe rotation is orthogonal, so it preserves norms. The backward pass is the inverse rotation (the transpose). Relative position is baked into the attention score, which is why RoPE extrapolates farther than absolute embeddings.