GRUCell¶
- class torch.nn.GRUCell(input_size, hidden_size, bias=True, device=None, dtype=None)[source][source]¶
一个门控循环单元 (GRU) Cell。
其中 是 Sigmoid 函数,而 是 Hadamard 积。
- 参数
- 输入:input, hidden
input :包含输入特征的 Tensor
hidden :包含批次中每个元素的初始隐藏状态的 Tensor。如果未提供,默认为零。
- 输出:h’
h’ :包含批次中每个元素的下一个隐藏状态的 Tensor
- 形状
input: 或 包含输入特征的 Tensor,其中 = input_size。
hidden: 或 包含初始隐藏状态的 Tensor,其中 = hidden_size。如果未提供,默认为零。
output: 或 包含下一个隐藏状态的 Tensor。
- 变量
weight_ih (torch.Tensor) – 可学习的输入到隐藏层权重,形状为 (3*hidden_size, input_size)
weight_hh (torch.Tensor) – 可学习的隐藏层到隐藏层权重,形状为 (3*hidden_size, hidden_size)
bias_ih – 可学习的输入到隐藏层偏置,形状为 (3*hidden_size)
bias_hh – 可学习的隐藏层到隐藏层偏置,形状为 (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)