Functions and operators

sign⁡(x)\operatorname{sign}(x) Sign function

The sign of a number: +1 if positive, −1 if negative, 0 at zero. Applied elementwise to vectors.

In ML papers

sign⁡(x)\operatorname{sign}(x) (also sgn⁡\operatorname{sgn}) keeps only the direction of a number: +1+1, −1-1 or 00. On a vector it acts on each entry.

It turns up wherever only the direction of a gradient matters. The fast gradient sign method (Goodfellow et al. 2015) perturbs an input by ϵsign⁡(∇xL)\epsilon \operatorname{sign}(\nabla_\mathbf{x} \mathcal{L}); signSGD (Bernstein et al. 2018) and the Lion optimizer (Chen et al. 2023) update every parameter by the same step size in the direction of the sign.

How to type it

LaTeXShows
\operatorname{sign}(x)sign⁡(x)\operatorname{sign}(x)
\operatorname{sgn}(x)sgn⁡(x)\operatorname{sgn}(x)

A worked example

sign⁡(−0.3,0,2)=(−1,0,1)\operatorname{sign}(-0.3, 0, 2) = (-1, 0, 1)

Every nonzero entry becomes ±1\pm 1, whatever its size.

Common confusions

Related

∣x∣|x|Absolute value (bars)∇θL\nabla_\theta \mathcal{L}Nabla (gradient)f(x)={xx>00otherwisef(x) = \begin{cases} x & x > 0 \\ 0 & \text{otherwise} \end{cases}Cases (piecewise)

Decode this example →