Positional Encoding

Layer 2 · Mechanics

Positional Encoding

The four schemes, mechanically: how each one actually computes a position signal and injects it into attention.

10 min read70 XP

Sinusoidal absolute encoding

The original Transformer paper (Vaswani et al., 2017) assigns each position a vector built from sine and cosine waves of different frequencies, one pair of dimensions per frequency band. Low-numbered dimensions oscillate fast (fine-grained position), high-numbered ones oscillate slowly (coarse-grained position) — the same idea as a clock with a second hand and an hour hand encoding time at two resolutions simultaneously. This vector is added elementwise to the token embedding before the first layer.

Go deeper: L3 Code