The sign of a number: +1 if positive, −1 if negative, 0 at zero. Applied elementwise to vectors.
In ML papers
sign(x) (also sgn) keeps only the direction of a number: +1, −1 or 0. 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); 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
LaTeX
Shows
\operatorname{sign}(x)
sign(x)
\operatorname{sgn}(x)
sgn(x)
A worked example
sign(−0.3,0,2)=(−1,0,1)
Every nonzero entry becomes ±1, whatever its size.
Common confusions
Some papers define sign(0)=1 to keep outputs binary; check if it matters.
Its derivative is 0 almost everywhere, so binarized networks train through it with a straight-through estimator (Stop-gradient).