Positional Encodings and Relative Offsets

Add sequence position to token states and derive how pairs of sinusoidal coordinates encode relative movement.

Source
Anbloq
Language
English
Created
Updated
Chapters
2
Reading time
1 min
In this article2 chapters
  1. Token content alone has no fixed position representation
  2. Different mechanisms expose different combinations

Token content alone has no fixed position representation

A lookup gives the same embedding for repeated token identifiers. Position features can be added to those vectors or used directly in attention scores. In a sine–cosine pair of frequency \(\omega\), the feature at position \(i\) uses \((\cos\omega i,\sin\omega i)\). The dot product with position \(j\) is \(\cos(\omega(i-j))\) by the angle difference identity.

Different mechanisms expose different combinations

A model can use several frequencies, learned absolute positions or explicitly relative terms. Evaluating beyond the training length may reach positions or separations rarely observed, even when formulas are defined there. The denominator and masking of attention also change what a long sequence presents. Tokens and embeddings distinguish position from identity. Attention describes where these features affect score calculation.[1]

References

  1. Ashish Vaswani et al., Attention Is All You Need ↩