tf.keras.ops.gelu
Функция активации Gaussian Error Linear Unit (GELU).
tf.keras.ops.gelu(
x, approximate=True
)
Если approximate — True, функция определяется так: f(x) = 0.5 * x * (1 + tanh(sqrt(2 / pi) * (x + 0.044715 * x^3)))
Или, если approximate — False, функция определяется так: f(x) = x * P(X <= x) = 0.5 * x * (1 + erf(x / sqrt(2))), где P(X) ~ N(0, 1).
| Аргументы | |
|---|---|
x | Входной тензор. |
approximate | Приближённый вариант функции активации GELU. По умолчанию — True. |
| Возвращает | |
|---|---|
Тензор той же формы, что и x. |
Пример:
x = np.array([-1., 0., 1.]) x_gelu = keras.ops.gelu(x) print(x_gelu) array([-0.15865525, 0., 0.84134475], shape=(3,), dtype=float64)
© 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/keras/ops/gelu