代码拉取完成,页面将自动刷新
class torch.nn.GRUCell(
input_size,
hidden_size,
bias=True)(input, hidden) -> Tensor
For more information, see torch.nn.GRUCell.
class mindspore.nn.GRUCell(
input_size: int,
hidden_size: int,
has_bias: bool=True)(x, hx) -> Tensor
For more information, see mindspore.nn.GRUCell.
PyTorch: Recurrent Neural Network unit.
MindSpore: MindSpore API implements the same functions as PyTorch.
Categories | Subcategories | PyTorch | MindSpore | Difference |
---|---|---|---|---|
Parameters | Parameter 1 | input_size | input_size | - |
Parameter 2 | hidden_size | hidden_size | - | |
Parameter 3 | bias | has_bias | Same function, different parameter names | |
Inputs | Input 1 | input | x | Same function, different parameter names |
Input 2 | hidden | hx | Same function, different parameter names |
# PyTorch
import torch
from torch import tensor
import numpy as np
grucell = torch.nn.GRUCell(2, 3, bias=False)
input = torch.tensor(np.array([[3.0, 4.0]]).astype(np.float32))
hidden = torch.tensor(np.array([[1.0, 2.0, 3]]).astype(np.float32))
output = grucell(input, hidden)
print(output)
# tensor([[ 0.9948, 0.0913, -0.1633]], grad_fn=<AddBackward0>)
# MindSpore
import mindspore.nn as nn
from mindspore import Tensor
import numpy as np
grucell = nn.GRUCell(2, 3, has_bias=False)
x = Tensor(np.array([[3.0, 4.0]]).astype(np.float32))
hx = Tensor(np.array([[1.0, 2.0, 3]]).astype(np.float32))
output = grucell(x, hx)
print(output)
# [[-0.94861907 0.6191679 2.1289415 ]]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。