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.

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.LSTM

class mindspore.ops.LSTM(input_size, hidden_size, num_layers, has_bias, bidirectional, dropout, proj_size=0)[source]

Performs the Long Short-Term Memory (LSTM) on the input.

For more information, please refer to mindspore.nn.LSTM.

Parameters
  • input_size (int) – Number of features of input.

  • hidden_size (int) – Number of features of hidden layer.

  • num_layers (int) – Number of layers of stacked LSTM, , which is only support 1 on CPU.

  • has_bias (bool) – Whether the cell has bias b_ih and b_hh , which is only support False on CPU.

  • bidirectional (bool) – Specifies whether it is a bidirectional LSTM, , which is only support False on CPU.

  • dropout (float) – If not 0, append Dropout layer on the outputs of each LSTM layer except the last layer. The range of dropout is [0.0, 1.0].

  • proj_size (int) – If proj_size > 0, a projection of the corresponding size will be used, which is only supported on CPU now. Default: 0 .

Inputs:
  • input (Tensor) - Tensor of shape (seq_len,batch_size,input_size) or (batch_size,seq_len,input_size).

  • h (Tensor) - Tensor of shape (num_directionsnum_layers,batch_size,real_hidden_size).

  • c (Tensor) - Tensor of shape (num_directionsnum_layers,batch_size,hidden_size).

  • w (Tensor) - A weight Tensor.

If proj_size>0 , real_hidden_size=proj_size , otherwise real_hidden_size=hidden_size .

Outputs:

Tuple, a tuple contains (output, h_n, c_n, reserve, state).

  • output (Tensor) - Tensor of shape (seq_len,batch_size,num_directionsreal_hidden_size).

  • h_n (Tensor) - Tensor of shape (num_directionsnum_layers,batch_size,real_hidden_size).

  • c_n (Tensor) - Tensor of shape (num_directionsnum_layers,batch_size,hidden_size).

  • reserve (Tensor) - Tensor of shape (r,1).

  • state (Tensor) - Random number generator state and its shape is (s,1).

Raises
  • TypeError – If input_size, hidden_size or num_layers is not an int.

  • TypeError – If has_bias or bidirectional is not a bool.

  • TypeError – If dropout is not a float.

  • ValueError – If dropout is not in range [0.0, 1.0].

  • ValueError – If proj_size is not in range [0, hidden_size).

Supported Platforms:

GPU CPU

Examples

>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> input_size = 10
>>> hidden_size = 2
>>> num_layers = 1
>>> seq_len = 5
>>> batch_size = 2
>>>
>>> net = ops.LSTM(input_size, hidden_size, num_layers, True, False, 0.0)
>>> input_tensor = Tensor(np.ones([seq_len, batch_size, input_size]).astype(np.float32))
>>> h0 = Tensor(np.ones([num_layers, batch_size, hidden_size]).astype(np.float32))
>>> c0 = Tensor(np.ones([num_layers, batch_size, hidden_size]).astype(np.float32))
>>> w = Tensor(np.ones([112, 1, 1]).astype(np.float32))
>>> output, hn, cn, _, _ = net(input_tensor, h0, c0, w)
>>> print(output)
[[[0.9640267  0.9640267 ]
  [0.9640267  0.9640267 ]]
 [[0.9950539  0.9950539 ]
  [0.9950539  0.9950539 ]]
 [[0.99932843 0.99932843]
  [0.99932843 0.99932843]]
 [[0.9999084  0.9999084 ]
  [0.9999084  0.9999084 ]]
 [[0.9999869  0.9999869 ]
  [0.9999869  0.9999869 ]]]