GELU

class paddle.nn. GELU ( approximate=False, name=None ) [source]

GELU Activation.

If approximate is True

\[GELU(x) = 0.5 * x * (1 + tanh(\sqrt{\frac{2}{\pi}} * (x + 0.044715x^{3})))\]

else

\[GELU(x) = 0.5 * x * (1 + erf(\frac{x}{\sqrt{2}}))\]
Parameters
  • approximate (bool, optional) – Wether to enable approximation. Default is False.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Shape:
  • input: Tensor with any shape.

  • output: Tensor with the same shape as input.

Examples

>>> import paddle
>>> x = paddle.to_tensor([[-1, 0.5],[1, 1.5]])
>>> m = paddle.nn.GELU()
>>> out = m(x)
>>> print(out)
Tensor(shape=[2, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
[[-0.15865529,  0.34573123],
 [ 0.84134471,  1.39978933]])
>>> m = paddle.nn.GELU(True)
>>> out = m(x)
>>> print(out)
Tensor(shape=[2, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
[[-0.15880796,  0.34571400],
 [ 0.84119201,  1.39957154]])
forward ( x )

forward

Defines the computation performed at every call. Should be overridden by all subclasses.

Parameters
  • *inputs (tuple) – unpacked tuple arguments

  • **kwargs (dict) – unpacked dict arguments

extra_repr ( )

extra_repr

Extra representation of this layer, you can have custom implementation of your own layer.