Shortcuts

GELU

class torch.nn.GELU(approximate='none')[源代码]

应用高斯误差线性单元函数。

GELU(x)=xΦ(x)\text{GELU}(x) = x * \Phi(x)

其中 Φ(x)\Phi(x) 是高斯分布的累积分布函数。

当近似参数为‘tanh’时,Gelu 使用以下公式进行估计:

GELU(x)=0.5x(1+Tanh(2/π(x+0.044715x3)))\text{GELU}(x) = 0.5 * x * (1 + \text{Tanh}(\sqrt{2 / \pi} * (x + 0.044715 * x^3)))
Parameters

近似 (str, 可选) – 使用的gelu近似算法: 'none' | 'tanh'。默认值:'none'

Shape:
  • 输入:()(*),其中 * 表示任意数量的维度。

  • 输出: ()(*), 与输入形状相同。

../_images/GELU.png

示例:

>>> m = nn.GELU()
>>> input = torch.randn(2)
>>> output = m(input)
优云智算