文档反馈

问题文档片段

问题文档片段包含公式时,显示为空格。

提交类型
issue

有点复杂...

找人问问吧。

请选择提交类型

问题类型
规范和低错类

- 规范和低错类:

- 错别字或拼写错误,标点符号使用错误、公式错误或显示异常。

- 链接错误、空单元格、格式错误。

- 英文中包含中文字符。

- 界面和描述不一致,但不影响操作。

- 表述不通顺,但不影响理解。

- 版本号不匹配:如软件包名称、界面版本号。

易用性

- 易用性:

- 关键步骤错误或缺失,无法指导用户完成任务。

- 缺少主要功能描述、关键词解释、必要前提条件、注意事项等。

- 描述内容存在歧义指代不明、上下文矛盾。

- 逻辑不清晰,该分类、分项、分步骤的没有给出。

正确性

- 正确性:

- 技术原理、功能、支持平台、参数类型、异常报错等描述和软件实现不一致。

- 原理图、架构图等存在错误。

- 命令、命令参数等错误。

- 代码片段错误。

- 命令无法完成对应功能。

- 界面错误,无法指导操作。

- 代码样例运行报错、运行结果不符。

风险提示

- 风险提示:

- 对重要数据或系统存在风险的操作,缺少安全提示。

内容合规

- 内容合规:

- 违反法律法规,涉及政治、领土主权等敏感词。

- 内容侵权。

请选择问题类型

问题描述

点击输入详细问题描述,以帮助我们快速定位问题。

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)[源代码]

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)