mindspore.ops.glu

查看源文件
mindspore.ops.glu(x, axis=- 1)[源代码]

门线性单元函数(Gated Linear Unit function)。

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

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

参数:
  • x (Tensor) - 被分Tensor,数据类型为Number, shape为 (1,N,2) ,其中 * 为任意额外维度。

  • axis (int,可选) - 指定分割轴。数据类型为整型,默认值: -1 ,输入x的最后一维。

返回:

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

异常:
  • TypeError - x 数据类型不是Number。

  • TypeError - x 不是Tensor。

支持平台:

Ascend GPU CPU

样例:

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