GELU

class paddle.nn. GELU ( approximate=False, name=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) – 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) # [-0.158655 0.345731 0.841345 1.39979]

m = paddle.nn.GELU(True)
out = m(x) # [-0.158808 0.345714 0.841192 1.39957]
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.