Approximate GELU
×A smooth feature-wise activation, computed through its tanh approximation.
- in
- [B batch, T positions, 3072 d_ff]
- out
- [B batch, T positions, 3072 d_ff]
Explanation
The function is near zero for strongly negative inputs, dips to about −0.17 near −0.75, and approaches the identity for large positive ones.
y = x. Function evaluated from −4 to 4.Sources
In codegelu(…), applied to conv1d(x, 'c_fc', n_state)
Direct evidence
The released graph defines the tanh approximation used by GPT-2.
model.py 25–26 ↗ · openai/gpt-2 @ 9b63575ef427
Excerpt
def gelu(x):
return 0.5*x*(1+tf.tanh(np.sqrt(2/np.pi)*(x+0.044715*tf.pow(x, 3))))