GELU
- class paddle.nn. GELU ( approximate: Union[Literal['tanh', 'none'], bool] = False, name: Optional[str] = None ) [source]
-
GELU Activation.
approximate parameter must be True, False, “tanh”, “none”.
If approximate is True or “tanh”
\[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 (str|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 api_guide_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(False) >>> 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("none") >>> 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("tanh") >>> 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]]) >>> 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.