gelu

    逐元素计算 Gelu激活函数。更多细节请参考 。

    如果使用近似计算:

    out\=0.5∗x∗(1+erf(x2‾√))out\=0.5∗x∗(1+erf(x2))

    参数:

    • x (Variable) - Gelu Op 的输入,多维 Tensor 或 LoDTensor,数据类型为 float32 或 float64。

    返回:

    • 多维 Tensor 或 LoDTensor, 数据类型为 float32 或 float64, 和输入 x 的数据类型相同,形状和输入 x 相同。

    返回类型:

    • Variable

    代码示例

    1. # imperative mode
    2. import numpy as np
    3. import paddle.fluid.dygraph as dg
    4. place = fluid.CPUPlace()
    5. with dg.guard(place) as g:
    6. x = dg.to_variable(data)
    7. y_np = y.numpy()
    8. # array([[ 0.87165993, -1.0541513 , -0.37214822],
    9. # [ 0.15647964, 0.32496083, 0.33045998]], dtype=float32)
    10. y_np
    11. # array([[ 0.70456535, -0.15380788, -0.13207214],