Machine learning building blocks
GELU (exact, erf form)
ml.geluAlso called gelu, gaussian error linear unit, gelu exact, gelu erf
x times the standard normal CDF Φ(x). This is the exact form, the default of torch.nn.GELU; the tanh approximation is a separate entry, ml.gelu-tanh.
Notation
input
x ∈ ℝ
Result: the activation
scalar
Worked examples
Each result is solved exactly and confirmed by two independent computations.
Given
Result
Given
Result
≈ 0.841344746069
Given
Result
≈ -0.158655253931
Given
Result
≈ 1.9544997361
Common mistakes
Uses the tanh approximation
The result is x/2 (1 + tanh(√(2/π)(x + 0.044715x3))), which differs from the exact form by up to about 5e-4.
Fix: Use the erf form, or torch.nn.GELU() with its default approximate='none'.
Uses the sigmoid approximation x σ(1.702x)
The result is the cheaper sigmoid approximation, which differs from the exact form by up to about 2e-2.
Fix: Use the erf form.
Source
Hendrycks and Gimpel 2016
Hendrycks, Dan; Gimpel, Kevin. Gaussian Error Linear Units (GELUs). arXiv:1606.08415, 2016.