評價此頁

GELU#

class torch.nn.modules.activation.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]#

執行前向傳播。

返回型別

張量