GELU¶
GELU 激活层(GELU Activation Operator)
逐元素计算 GELU 激活函数。更多细节请参考 Gaussian Error Linear Units 。
如果使用近似计算:
GELU(x)=0.5∗x∗(1+tanh(√2π∗(x+0.044715x3)))
如果不使用近似计算:
GELU(x)=0.5∗x∗(1+erf(x√2))
其中,x 为输入的 Tensor。
参数¶
approximate (bool,可选) - 是否使用近似计算,默认值为 False,即不使用近似计算。
name (str,可选) - 具体用法请参见 Name,一般无需设置,默认值为 None。
形状¶
input:任意形状的 Tensor。
output:和 input 具有相同形状的 Tensor。
代码示例¶
>>> import paddle
>>> x = paddle.to_tensor([[-1, 0.5],[1, 1.5]])
>>> m = paddle.nn.GELU()
>>> out = m(x)
>>> print(out)
Tensor(shape=[2, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
[[-0.15865529, 0.34573123],
[ 0.84134471, 1.39978933]])
>>> m = paddle.nn.GELU(True)
>>> out = m(x)
>>> print(out)
Tensor(shape=[2, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
[[-0.15880796, 0.34571400],
[ 0.84119201, 1.39957154]])