评价此页

torch.nn.functional.gelu#

torch.nn.functional.gelu(input, approximate='none') Tensor#

当 approximate 参数为 ‘none’ 时,它对元素应用函数 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)))

参见 Gaussian Error Linear Units (GELUs)