Read the equation
rotate_half maps a pair of coordinate blocks(x 1,x 2) to(−x 2,x 1). Multiplication by cosine and addition of the sine-weighted rotated vector implements a two-dimensional rotation for each coordinate pair. The surrounding interleave-to-block reshape determines which coordinates are paired. Norm is preserved when the paired sine/cosine coefficients have unit squared sum.
Terms & definitions
| Term | Meaning in this source |
|---|---|
| k | Key vector after source-prescribed pairing |
| cos | Cosines for the token position |
| sin | Sines for the token position |
How it works
Read the definition from its right-hand expression to the quantity on the left. Its surrounding source records the intended input, state, or parameter context. Where the source leaves an operation unspecified, this page preserves that gap.
Assumptions & limits
Source recovery establishes that the expression appears in this record. Its mathematical validity, implementation behavior, and interpretation must be assessed separately. See the linked source and research notes for the checks available for this version.
Original context
Read the surrounding source passage
k = k.view(b, h, s, d // 2, 2).transpose(4, 3).reshape(b, h, s, d)
q_embed = (q * cos) + (rotate_half(q) * sin)
k_embed = (k * cos) + (rotate_half(k) * sin)
return q_embed, k_embedExact original notation
k_embed = (k * cos) + (rotate_half(k) * sin)