mindspore/docs/api/api_python/ops/mindspore.ops.func_gelu.rst

36 lines
1.5 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

mindspore.ops.gelu
==================
.. py:function:: mindspore.ops.gelu(input_x, approximate='none')
高斯误差线性单元激活函数。
GeLU的描述可以在 `Gaussian Error Linear Units (GELUs) <https://arxiv.org/abs/1606.08415>`_ 这篇文章中找到。
也可以去查询 `BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding <https://arxiv.org/abs/1810.04805>`_
`approximate``none` GELU的定义如下
.. math::
GELU(x_i) = x_i*P(X < x_i),
其中 :math:`P` 是标准高斯分布的累积分布函数, :math:`x_i` 是输入的元素。
`approximate``tanh` GELU的定义如下
.. math::
GELU(x_i) = 0.5 * x_i * (1 + tanh(\sqrt(2 / \pi) * (x_i + 0.044715 * x_i^3)))
GELU相关图参见 `GELU <https://en.wikipedia.org/wiki/Activation_function#/media/File:Activation_gelu.png>`_
参数:
- **input_x** (Tensor) - 用于计算GELU的Tensor。数据类型为float16、float32、float64。
- **approximate** (str) - gelu近似算法。有两种'none' 和 'tanh'。默认值none。
返回:
Tensor具有与 `input_x` 相同的数据类型和shape。
异常:
- **TypeError** - 如果 `input_x` 的数据类型不是Tensor。
- **TypeError** - `input_x` 的数据类型既不是float16、float32或者float64。
- **ValueError** - 如果 `approximate` 的值既不是 `none` 也不是 `tanh`