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

class mindspore.ops.DynamicRNN(cell_type='LSTM', direction='UNIDIRECTIONAL', cell_depth=1, use_peephole=False, keep_prob=1.0, cell_clip=- 1.0, num_proj=0, time_major=True, activation='tanh', forget_bias=0.0, is_training=True)[source]

Applies a recurrent neural network to the input. Only long short-term memory (LSTM) is supported currently.

it+1=σ(Wixxt+1+bix+Wihh(t)+bih)ft+1=σ(Wfxxt+1+bfx+Wfhh(t)+bfh)c~t+1=tanh(Wcxxt+1+bcx+Wchh(t)+bch)ot+1=σ(Woxxt+1+box+Wohh(t)+boh)ct+1=ft+1c(t)+itc~t+1ht+1=ot+1tanh(ct+1)

where ht+1 is the hidden state at time t+1, xt+1 is the input at time t+1, ht is the hidden state of the layer at time t or the initial hidden state at time 0, σ is the sigmoid function, and is the Hadamard product. W,b are learnable weights between the output and the input in the formula. For instance, Wix,bix are the weight and bias used to transform from input x to i.

Parameters
  • cell_type (str) – A string identifying the cell type in the operator. Default: ‘LSTM’. Only ‘LSTM’ is currently supported.

  • direction (str) – A string identifying the direction in the operator. Default: ‘UNIDIRECTIONAL’. Only ‘UNIDIRECTIONAL’ is currently supported.

  • cell_depth (int) – An integer identifying the cell depth in the operator. Default: 1.

  • use_peephole (bool) – A bool identifying if use peephole in the operator. Default: False.

  • keep_prob (float) – A float identifying the keep prob in the operator. Default: 1.0.

  • cell_clip (float) – A float identifying the cell clip in the operator. Default: -1.0.

  • num_proj (int) – An integer identifying the number projection in the operator. Default: 0.

  • time_major (bool) – A bool identifying the time major in the operator. Default: True. Only True is currently supported.

  • activation (str) – A string identifying the type of activation function in the operator. Default: ‘tanh’. Only ‘tanh’ is currently supported.

  • forget_bias (float) – A float identifying the forget bias in the operator. Default: 0.0.

  • is_training (bool) – A bool identifying is training in the operator. Default: True.

Inputs:
  • x (Tensor) - Current words. Tensor of shape (num_step,batch_size,input_size). The data type must be float16.

  • w (Tensor) - Weight. Tensor of shape (input_size+hidden_size,4hidden_size). The data type must be float16.

  • b (Tensor) - Bias. Tensor of shape (4hidden_size). The data type must be float16 or float32.

  • seq_length (Tensor) - The length of each batch. Tensor of shape (batch_size,). Only None is currently supported.

  • init_h (Tensor) - Hidden state of initial time. Tensor of shape (1,batch_size,hidden_size). The data type must be float16.

  • init_c (Tensor) - Cell state of initial time. Tensor of shape (1,batch_size,hidden_size). The data type must be float16.

Outputs:
  • y (Tensor) - A Tensor of shape (num_step,batch_size,hidden_size). Has the same type with input b.

  • output_h (Tensor) - A Tensor of shape (num_step,batch_size,hidden_size). With data type of float16.

  • output_c (Tensor) - A Tensor of shape (num_step,batch_size,hidden_size). Has the same type with input b.

  • i (Tensor) - A Tensor of shape (num_step,batch_size,hidden_size). Has the same type with input b.

  • j (Tensor) - A Tensor of shape (num_step,batch_size,hidden_size). Has the same type with input b.

  • f (Tensor) - A Tensor of shape (num_step,batch_size,hidden_size). Has the same type with input b.

  • o (Tensor) - A Tensor of shape (num_step,batch_size,hidden_size). Has the same type with input b.

  • tanhct (Tensor) - A Tensor of shape (num_step,batch_size,hidden_size). Has the same type with input b.

Raises
  • TypeError – If cell_type, direction or activation is not a str.

  • TypeError – If cell_depth or num_proj is not an int.

  • TypeError – If keep_prob, cell_clip or forget_bias is not a float.

  • TypeError – If use_peehpole, time_major or is_training is not a bool.

  • TypeError – If x, w, b, seq_length, init_h or init_c is not a Tensor.

  • TypeError – If dtype of x, w, init_h or init_c is not float16.

  • TypeError – If dtype of b is neither float16 nor float32.

Supported Platforms:

Ascend

Examples

>>> x = Tensor(np.random.rand(2, 16, 64).astype(np.float16))
>>> w = Tensor(np.random.rand(96, 128).astype(np.float16))
>>> b = Tensor(np.random.rand(128).astype(np.float16))
>>> init_h = Tensor(np.random.rand(1, 16, 32).astype(np.float16))
>>> init_c = Tensor(np.random.rand(1, 16, 32).astype(np.float16))
>>> dynamic_rnn = ops.DynamicRNN()
>>> output = dynamic_rnn(x, w, b, None, init_h, init_c)
>>> print(output[0].shape)
(2, 16, 32)