GELU¶ class torch.nn.GELU(approximate='none')[源代码]¶ 应用高斯误差线性单元函数。 GELU(x)=x∗Φ(x)\text{GELU}(x) = x * \Phi(x) GELU(x)=x∗Φ(x)其中 Φ(x)\Phi(x)Φ(x) 是高斯分布的累积分布函数。 当近似参数为‘tanh’时,Gelu 使用以下公式进行估计: GELU(x)=0.5∗x∗(1+Tanh(2/π∗(x+0.044715∗x3)))\text{GELU}(x) = 0.5 * x * (1 + \text{Tanh}(\sqrt{2 / \pi} * (x + 0.044715 * x^3))) GELU(x)=0.5∗x∗(1+Tanh(2/π∗(x+0.044715∗x3))) Parameters 近似 (str, 可选) – 使用的gelu近似算法: 'none' | 'tanh'。默认值:'none' Shape: 输入:(∗)(*)(∗),其中 ∗*∗ 表示任意数量的维度。 输出: (∗)(*)(∗), 与输入形状相同。 示例: >>> m = nn.GELU() >>> input = torch.randn(2) >>> output = m(input)