双向RNN--(GRU)输出什么?

 

模型架构 一层Embedding, 一层双向GRU

双向RNN--(GRU)输出什么?_第1张图片

num_embeddings=2  有两条数据需要输入
input_size=3 GRU层的输入维度,也就是嵌入层的embedding维度
hidden_size=2 隐层维度是2

import torch

Embedding = torch.nn.Embedding(num_embeddings=2,embedding_dim=3)
GRU = torch.nn.GRU(input_size=3,hidden_size=2,num_layers=1,bidirectional=True)

inputs = torch.randint(0,2,(2,2)) # embedding层需检查张量内部具体值的大小,并确保它们的值在有效范围内[0, num_embeddings-1]
print(inputs)
emd = Embedding(inputs)
print(emd)
out, hidden = GRU(emd)
print('out:\n','-'*100)
print(out)
print('hidden:\n','-'*100)
print(hidden)
print(out.size())
print(hidden.size())

输出结果

tensor([[0, 0],
        [0, 1]])
tensor([[[ 0.7150,  0.4217, -1.0267],
         [ 0.7150,  0.4217, -1.0267]],

        [[ 0.7150,  0.4217, -1.0267],
         [-1.5367, -1.1130,  0.5921]]], grad_fn=)
out:
 ----------------------------------------------------------------------------------------------------
tensor([[[-0.0069,  0.0011, -0.3263, -0.1013],
         [-0.0069,  0.0011, -0.3115, -0.0267]],

        [[-0.0117,  0.0023, -0.1905, -0.0704],
         [-0.0939,  0.5676, -0.1734,  0.1007]]], grad_fn=)
hidden:
 ----------------------------------------------------------------------------------------------------
tensor([[[-0.0117,  0.0023],
         [-0.0939,  0.5676]],

        [[-0.3263, -0.1013],
         [-0.3115, -0.0267]]], grad_fn=)
torch.Size([2, 2, 4])
torch.Size([2, 2, 2])
 

注意

双向RNN--(GRU)输出什么?_第2张图片

 

 

你可能感兴趣的:(python编程,python,深度学习)