Machine learning building blocks
GELU (tanh approximation)
ml.gelu-tanhAlso called gelu tanh, gelu approximate, gelu new, approximate gelu
The tanh approximation of GELU, torch.nn.GELU(approximate='tanh') and the form used in many transformer codebases. The exact erf form is ml.gelu.
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.841191990608
Given
Result
≈ -0.158808009392
Given
Result
≈ 1.95459769409
Common mistakes
Computes the exact erf form
The result is x Φ(x), the exact GELU, where the tanh approximation is specified.
Fix: Use the tanh formula, or torch.nn.GELU(approximate='tanh').
Source
Hendrycks and Gimpel 2016
Hendrycks, Dan; Gimpel, Kevin. Gaussian Error Linear Units (GELUs). arXiv:1606.08415, 2016.