mindspore.mint.nn.functional.glu

查看源文件
mindspore.mint.nn.functional.glu(input, dim=- 1)[源代码]

计算输入Tensor的门线性单元激活函数(Gated Linear Unit activation function)值。

GLU(a,b)=aσ(b)

其中,a 表示输入Tensor input 拆分后的前一半元素, b 表示 input 拆分后的另一半元素。 其中 σ 是sigmoid函数, 是Hadamard乘积。 请参考 Language Modeling with Gated Convluational Networks

参数:
  • input (Tensor) - 待计算的Tensor,数据类型为浮点型,shape为 (1,N,2) ,其中 * 为任意额外维度,且要求 N 为偶数。 Ninput 在被 dim 选中的维度上的大小。

  • dim (int,可选) - 指定分割 input 的轴,取值范围 [-r, r) ,其中 rinput 的维度数。默认值: -1 ,输入 input 的最后一维。

返回:

Tensor,数据类型与输入 input 相同,shape为 (1,M,2),其中 M=N/2

异常:
  • TypeError - input 不是Tensor或 dim 不是整型。

  • IndexError - dim 的值超出了 [-r, r) 的范围,其中 rinput 的维度数。

  • RuntimeError - input 数据类型不被支持。

  • RuntimeError - input 在被 dim 选中的维度上的长度不为偶数。

支持平台:

Ascend

样例:

>>> from mindspore import Tensor, mint
>>> input = Tensor([[0.1, 0.2, 0.3, 0.4], [0.5, 0.6, 0.7, 0.8]])
>>> output = mint.nn.functional.glu(input)
>>> print(output)
[[0.05744425 0.11973753]
 [0.33409387 0.41398472]]