torch.nn.functional.gelu¶ torch.nn.functional.gelu(input, approximate='none') → Tensor¶ 當 approximate 參數為 ‘none’ 時,它會逐元素地應用函數 GELU(x)=x∗Φ(x)\text{GELU}(x) = x * \Phi(x)GELU(x)=x∗Φ(x) 其中 Φ(x)\Phi(x)Φ(x) 是高斯分佈的累積分佈函數。 當 approximate 參數為 ‘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)))請參閱 Gaussian Error Linear Units (GELUs)。