快速鍵

GELU

class torch.nn.GELU(approximate='none')[來源][來源]

套用 Gaussian Error Linear Units 函數。

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

其中 Φ(x)\Phi(x) 是高斯分佈的累積分布函數 (Cumulative Distribution Function)。

當 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)))
參數

approximate (str, optional) – 要使用的 gelu 近似演算法: 'none' | 'tanh'。 預設值: 'none'

形狀
  • 輸入: ()(*), 其中 * 表示任意數量的維度。

  • 輸出: ()(*), 與輸入相同的形狀。

../_images/GELU.png

範例

>>> m = nn.GELU()
>>> input = torch.randn(2)
>>> output = m(input)

文件

存取 PyTorch 的完整開發者文件

檢視文件

教學課程

取得針對初學者和進階開發者的深入教學課程

檢視教學課程

資源

尋找開發資源並獲得您的問題解答

檢視資源