评价此页

GELU#

class torch.nn.GELU(approximate='none')[source]#

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

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

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

当 approximate 参数为 ‘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))) (x+0.044715x3)))
参数

approximate (str, optional) – 要使用的 gelu 近似算法:'none' | 'tanh'。默认为:'none'

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

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

../_images/GELU.png

示例

>>> m = nn.GELU()
>>> input = torch.randn(2)
>>> output = m(input)
extra_repr()[source]#

返回模块的额外表示。

返回类型

str

forward(input)[source]#

执行前向传播。

返回类型

张量