GRUCell#
- class torch.nn.modules.rnn.GRUCell(input_size, hidden_size, bias=True, device=None, dtype=None)[源代码]#
一个门控循环单元 (GRU) 单元。
其中 是 sigmoid 函数, 是 Hadamard 积。
- 参数
- 输入:input, hidden
input : tensor containing input features
hidden : tensor containing the initial hidden state for each element in the batch. Defaults to zero if not provided.
- 输出:h’
h’ : tensor containing the next hidden state for each element in the batch
- 形状
input: or tensor containing input features where = input_size。
hidden: or tensor containing the initial hidden state where = hidden_size。若未提供,则默认为零。
output: or tensor containing the next hidden state。
- 变量
weight_ih (torch.Tensor) – the learnable input-hidden weights, of shape (3*hidden_size, input_size)
weight_hh (torch.Tensor) – the learnable hidden-hidden weights, of shape (3*hidden_size, hidden_size)
bias_ih – the learnable input-hidden bias, of shape (3*hidden_size)
bias_hh – the learnable hidden-hidden bias, of shape (3*hidden_size)
注意
All the weights and biases are initialized from where
在某些 ROCm 设备上,当使用 float16 输入时,此模块将对反向传播使用不同精度。
示例
>>> rnn = nn.GRUCell(10, 20) >>> input = torch.randn(6, 3, 10) >>> hx = torch.randn(3, 20) >>> output = [] >>> for i in range(6): ... hx = rnn(input[i], hx) ... output.append(hx)