gelu(Gaussian error linear units,高斯误差线性单元)
论文链接:https://arxiv.org/abs/1606.08415
数学表达如下:
相比Relu:Relu将小于0的数据映射到0,将大于0的给与 等于 映射操作,虽然性能比sigmoid好,但是缺乏数据的统计特性,而Gelu则在relu的基础上加入了统计的特性。
python实现
import tensorflow as tf
def gelu(x):
"""Gaussian Error Linear Unit.
x: float Tensor to perform activation.
Returns:
`x` with the GELU activation applied.
"""
cdf = 0.5 * (1.0 + tf.tanh(
(np.sqrt(2 / np.pi) * (x + 0.044715 * tf.pow(x, 3)))))
return x * cdf