Functions and operators

PE(pos,2i)=sin⁡(pos100002i/d)PE_{(pos, 2i)} = \sin\left(\frac{pos}{10000^{2i/d}}\right) Sine

The sine function; in ML papers mostly inside positional encodings and rotary embeddings.

In ML papers

sin⁡x\sin x is the sine of an angle xx in radians. It goes up and down between −1-1 and 11 with period 2π2\pi.

In ML papers it shows up mainly as a way to encode position. The Transformer (Vaswani et al. 2017) adds sinusoidal positional encodings: even dimensions get sin⁡(pos⋅ωi)\sin(pos \cdot \omega_i) and odd ones cos⁡(pos⋅ωi)\cos(pos \cdot \omega_i), with a different frequency ωi\omega_i per pair. Rotary embeddings (Su et al. RoFormer 2021) rotate each pair of query and key features by an angle mθim\theta_i, using sin⁡\sin and cos⁡\cos of it. Fourier features and NeRF-style encodings do the same with sin⁡(2kπx)\sin(2^k \pi x).

How to type it

LaTeXShows
\sinsin⁡\sin
\arcsin inverse sinearcsin⁡\arcsin

A worked example

sin⁡0=0,sin⁡π2=1,sin⁡π=0\sin 0 = 0, \quad \sin\tfrac{\pi}{2} = 1, \quad \sin \pi = 0

At position 1 and frequency 1, the first positional-encoding dimension is sin⁡1≈0.841\sin 1 \approx 0.841.

Common confusions

Equations that use it

Related

cos⁡(u,v)=u⊤v∥u∥ ∥v∥\cos(\mathbf{u}, \mathbf{v}) = \frac{\mathbf{u}^\top \mathbf{v}}{\|\mathbf{u}\| \, \|\mathbf{v}\|}Cosineωi=10000−2i/d\omega_i = 10000^{-2i/d}OmegaPE(pos,2i)=sin⁡(pos/100002i/dmodel)PE_{(pos, 2i)} = \sin\left(pos / 10000^{2i/d_{model}}\right)Multi-letter names

Decode this example →