文档反馈

问题文档片段

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

提交类型
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)[源代码]

将循环神经网络应用到输入上。当前仅支持LSTM。

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)

其中, ht+1 是在 t+1 时刻的隐藏状态。 xt+1 是在 t+1 时刻的输入。 ht 是在 t 时刻的隐藏状态或在 0 时刻的初始隐藏状态。 σ 是sigmoid函数, Hadamard 积。 W,b 是公式中输出和输入之间的可学习权重。

例如, Wix,bix 是把 x 转换为 i 的权重和偏置。

参数:
  • cell_type (str) - 指定Cell类型。当前仅支持LSTM。默认值:LSTM。

  • direction (str) - 指定单向或双向。默认值:UNIDIRECTIONAL。当前仅支持UNIDIRECTIONAL。

  • cell_depth (int) - 指定cell的层数。默认值:1。

  • use_peephole (bool) - 是否使用”peephole connections”。默认值:False。

  • keep_prob (float) - 指定保留率,即每个元素被保留的概率。1.0表示所有元素全部保留。默认值:1.0。

  • cell_clip (float) - 将Cell裁剪到指定的值,负值表示禁用。默认值:-1.0。

  • num_proj (int) - 投影矩阵的输出维数。默认值:0。

  • time_major (bool) - 指定输入 x 的数据排列格式。如果为True,格式为 (num_step,batch_size,input_size),如果为False,格式为:(batch_size,num_step,input_size) 。默认值:True。当前仅支持True。

  • activation (str) - 指定激活函数。默认值:tanh。当前仅支持tanh。

  • forget_bias (float) - 指定遗忘门的偏置。默认值:0.0。

  • is_training (bool) - 指定是否开启训练。默认值:True。

输入:
  • x (Tensor) - 输入的词汇。shape为 (num_step,batch_size,input_size) 的Tensor。数据类型必须为float16。

  • w (Tensor) - 输入的权重。shape为 (input_size+hidden_size,4hidden_size) 的Tensor。数据类型必须为float16。

  • b (Tensor) - 输入的偏置。shape为 (4hidden_size) 的Tensor。数据类型必须为float16或float32。

  • seq_length (Tensor) - 每个批次中句子的真实长度。shape为 (batch_size,) 的Tensor。当前仅支持None。

  • init_h (Tensor) - 在初始时刻的隐藏状态。shape为 (1,batch_size,hidden_size) 的Tensor。数据类型必须为float16。

  • init_c (Tensor) - 在初始时刻的Cell状态。shape为 (1,batch_size,hidden_size) 的Tensor。数据类型必须为float16。

输出:
  • y (Tensor) - 所有时刻输出层的输出向量,shape为 (num_step,batch_size,hidden_size) 的Tensor。数据类型与输入 b 相同。

  • output_h (Tensor) - 所有时刻输出层的输出向量,shape为 (num_step,batch_size,hidden_size) 的Tensor。数据类型为float16。

  • output_c (Tensor) - 所有时刻的Cell状态的输出向量,shape为 (num_step,batch_size,hidden_size) 的Tensor。数据类型与输入 b 相同。

  • i (Tensor) - 更新输入门的权重,shape为 (num_step,batch_size,hidden_size) 的Tensor。数据类型与输入 b 相同。

  • j (Tensor) - 更新新门的权重,shape为 (num_step,batch_size,hidden_size) 的Tensor。数据类型与输入 b 相同。

  • f (Tensor) - 更新遗忘门的权重,shape为 (num_step,batch_size,hidden_size) 的Tensor。数据类型输入 b 相同。

  • o (Tensor) - 更新输出门的权重,shape为 (num_step,batch_size,hidden_size) 的Tensor。数据类型与输入 b 相同。

  • tanhct (Tensor) - 更新tanh的权重,shape为 (num_step,batch_size,hidden_size) 的Tensor。数据类型与输入 b 相同。

异常:
  • TypeError - cell_typedirectionactivation 不是str。

  • TypeError - cell_Deepnum_proj 不是int。

  • TypeError - keep_probcell_clipforget_bias 不是float。

  • TypeError - use_peehpoltime_majoris_training 不是bool。

  • TypeError - xwbseq_lengthinit_hinit_c 不是Tensor。

  • TypeError - xwinit_hnit_c 的数据类型不是float16。

  • TypeError - b 的数据类型既不是float16也不是float32。

支持平台:

Ascend

样例:

>>> 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)