Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

PR

Just a small problem.

I can fix it online!

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.ops.GLU

View Source On Gitee
class mindspore.ops.GLU(axis=- 1)[source]

Computes GLU (Gated Linear Unit activation function) of the input tensor.

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

where a is the first half of the x Tensor after x is split and b is the second half.

Here σ is the sigmoid function, and is the Hadamard product. See Language Modeling with Gated Convluational Networks .

Parameters

axis (int, optional) – Axis to split the input x. The value range is [-r, r) where r is the number of dimensions of x. Default: -1 , the last dimension in x.

Inputs:
  • x (Tensor) - Tensor to be calculated. Dtype is floating point and the shape is (1,N,2) where * means, any number of additional dimensions. N is required to be an even number, where N is the size of x on the dimension selected by axis.

Outputs:

Tensor, the same dtype as x, with the shape (1,M,2) where M=N/2.

Raises
  • TypeError – If x is not a Tensor or axis is not an int.

  • IndexError – If the value of axis is out of the range of [-r, r), where r is the number of dimensions of x.

  • RuntimeError – If dtype of x is not supported.

  • RuntimeError – If the length of x in the dimension selected by axis is not even.

Supported Platforms:

Ascend CPU

Examples

>>> from mindspore import ops, Tensor
>>> from mindspore import dtype as mstype
>>> import numpy as np
>>> axis = 0
>>> x = Tensor(np.array([0.3220, 0.9545, 0.7879, 0.0975, 0.3698,
...                            0.5135, 0.5740, 0.3435, 0.1895, 0.8764,
...                            0.4980, 0.9673, 0.9879, 0.6988, 0.9022,
...                            0.9304, 0.1558, 0.0153, 0.1559, 0.9852]).reshape([2, 2, 5]), mstype.float32)
>>> glu = ops.GLU(axis=axis)
>>> y = glu(x)
>>> print(y)
[[[0.20028052 0.6916126  0.57412136 0.06512236 0.26307625]
  [0.3682598  0.3093122  0.17306386 0.10212085 0.63814086]]]