Embeddings and Positional Encoding

1 / 6

Token embeddings

  • Vocabulary size V, embedding dim D
  • Weight table W has shape (V, D)
  • Lookup by token IDs returns vectors
2 / 6

Sparse updates

The lookup path contributes only to selected rows. Repeated IDs accumulate into the same parameters. Other uses, optimizer state, or weight decay can affect unused rows.

3 / 6

Positional embeddings

  • Without positions, unmasked attention permutes outputs with inputs
  • This is equivariance, not invariance
  • Add learned position vectors P[pos]
  • P shape: (Tmax, D)
4 / 6

Combine

input[i] = token_emb[i] + pos_emb[i]

Shape: (T, D)

5 / 6

Tokenization note

We use character-level tokens in this pack for simplicity.

6 / 6
←/→ or click edges to navigate · ? help · N notes · F fullscreen