GELU

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

GELU Activation.

If approximate is True

GELU(x)=0.5x(1+tanh(2π(x+0.044715x3)))

else

GELU(x)=0.5x(1+erf(x2))
Parameters
  • approximate (bool, optional) – Whether to enable approximation. Default is False.

  • name (str|None, 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: Tensor ) Tensor

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 ( ) str

extra_repr

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