Rate this Page
โ˜… โ˜… โ˜… โ˜… โ˜…

GELU#

class torch.nn.modules.activation.GELU(approximate='none')[source]#

Applies the Gaussian Error Linear Units function.

GELU(x)=xโˆ—ฮฆ(x)\text{GELU}(x) = x * \Phi(x)

where ฮฆ(x)\Phi(x) is the Cumulative Distribution Function for Gaussian Distribution.

When the approximate argument is โ€˜tanhโ€™, Gelu is estimated with:

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)))
Parameters

approximate (str, optional) โ€“ the gelu approximation algorithm to use: 'none' | 'tanh'. Default: 'none'

Shape:
  • Input: (โˆ—)(*), where โˆ—* means any number of dimensions.

  • Output: (โˆ—)(*), same shape as the input.

../_images/GELU.png

Examples:

>>> m = nn.GELU()
>>> input = torch.randn(2)
>>> output = m(input)
extra_repr()[source]#

Return the extra representation of the module.

Return type

str

forward(input)[source]#

Runs the forward pass.

Return type

Tensor