GRUCell#
- class torch.nn.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: 或 张量,包含输入特征,其中 = input_size。
hidden: 或 张量,包含初始隐藏状态,其中 = hidden_size。如果未提供,则默认为零。
output: 或 张量,包含下一个隐藏状态。
- 变量:
weight_ih (torch.Tensor) – 可学习的输入-隐藏权重,形状为 (3*hidden_size, input_size)
weight_hh (torch.Tensor) – 可学习的隐藏-隐藏权重,形状为 (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)
注意
所有权重和偏差均从 中均匀初始化,其中 。
在某些 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)