mindspore2022/docs/api/api_python/nn/mindspore.nn.RNNCell.rst

35 lines
1.5 KiB
ReStructuredText
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

mindspore.nn.RNNCell
=====================
.. py:class:: mindspore.nn.RNNCell(input_size: int, hidden_size: int, has_bias: bool = True, nonlinearity: str = 'tanh')
循环神经网络单元激活函数是tanh或relu。
.. math::
h_t = \tanh(W_{ih} x_t + b_{ih} + W_{hh} h_{(t-1)} + b_{hh})
其中 :math:`h_t` 是在 `t` 时刻的隐藏状态, :math:`x_t` 是在 `t` 时刻的输入, :math:`h_{(t-1)}` 是在 :math:`t-1` 时刻的隐藏状态,或初始隐藏状态。
如果 `nonlinearity` 是'relu',则使用'relu'而不是'tanh'。
**参数:**
- **input_size** (int) - 输入层输入的特征向量维度。
- **hidden_size** (int) - 隐藏层输出的特征向量维度。
- **has_bias** (bool) - Cell是否有偏置项 `b_ih``b_hh` 。默认值True。
- **nonlinearity** (str) - 用于选择非线性激活函数。取值可以是'tanh'或'relu'。默认值:'tanh'。
**输入:**
- **x** (Tensor) - 输入Tensor其shape为 :math:`(batch\_size, input\_size)`
- **hx** (Tensor) - 输入Tensor其数据类型为mindspore.float32及shape为 :math:`(batch\_size, hidden\_size)``hx` 的数据类型与 `x` 相同。
**输出:**
- **hx'** (Tensor) - shape为 :math:`(batch\_size, hidden\_size)` 的Tensor。
**异常:**
- **TypeError** - `input_size``hidden_size` 不是int或不大于0。
- **TypeError** - `has_bias` 不是bool。
- **ValueError** - `nonlinearity` 不在['tanh', 'relu']中。