tf.keras.activations.gelu
Stay organized with collections
Save and categorize content based on your preferences.
Applies the Gaussian error linear unit (GELU) activation function.
tf.keras.activations.gelu(
x, approximate=False
)
Gaussian error linear unit (GELU) computes
x * P(X <= x)
, where P(X) ~ N(0, 1)
.
The (GELU) nonlinearity weights inputs by their value, rather than gates
inputs by their sign as in ReLU.
Example:
x = tf.constant([-3.0, -1.0, 0.0, 1.0, 3.0], dtype=tf.float32)
y = tf.keras.activations.gelu(x)
y.numpy()
array([-0.00404951, -0.15865529, 0. , 0.8413447 , 2.9959507 ],
dtype=float32)
y = tf.keras.activations.gelu(x, approximate=True)
y.numpy()
array([-0.00363752, -0.15880796, 0. , 0.841192 , 2.9963627 ],
dtype=float32)
Args |
x
|
Input tensor.
|
approximate
|
A bool , whether to enable approximation.
|
Returns |
The gaussian error linear activation:
0.5 * x * (1 + tanh(sqrt(2 / pi) * (x + 0.044715 * x^3)))
if approximate is True or
x * P(X <= x) = 0.5 * x * (1 + erf(x / sqrt(2))) ,
where P(X) ~ N(0, 1) ,
if approximate is False .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[],[],null,["# tf.keras.activations.gelu\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v2.13.1/keras/activations.py#L326-L363) |\n\nApplies the Gaussian error linear unit (GELU) activation function. \n\n tf.keras.activations.gelu(\n x, approximate=False\n )\n\nGaussian error linear unit (GELU) computes\n`x * P(X \u003c= x)`, where `P(X) ~ N(0, 1)`.\nThe (GELU) nonlinearity weights inputs by their value, rather than gates\ninputs by their sign as in ReLU.\n\n#### Example:\n\n x = tf.constant([-3.0, -1.0, 0.0, 1.0, 3.0], dtype=tf.float32)\n y = tf.keras.activations.gelu(x)\n y.numpy()\n array([-0.00404951, -0.15865529, 0. , 0.8413447 , 2.9959507 ],\n dtype=float32)\n y = tf.keras.activations.gelu(x, approximate=True)\n y.numpy()\n array([-0.00363752, -0.15880796, 0. , 0.841192 , 2.9963627 ],\n dtype=float32)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------|--------------------------------------------|\n| `x` | Input tensor. |\n| `approximate` | A `bool`, whether to enable approximation. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| The gaussian error linear activation: `0.5 * x * (1 + tanh(sqrt(2 / pi) * (x + 0.044715 * x^3)))` if `approximate` is `True` or `x * P(X \u003c= x) = 0.5 * x * (1 + erf(x / sqrt(2)))`, where `P(X) ~ N(0, 1)`, if `approximate` is `False`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Reference --------- ||\n|---|---|\n| \u003cbr /\u003e - [Gaussian Error Linear Units (GELUs)](https://arxiv.org/abs/1606.08415) ||\n\n\u003cbr /\u003e"]]