Pytorch中 bidirectional=True,Tensor的大小变化
rnn = nn.RNN(input_size=4,hidden_size=3,num_layers=2,batch_first=True, bidirectional = True) input = torch.randn(1,5,4) output , h_n = rnn(input) print(output.shape) print(h_n.shape) #----输出结果---------- input.Size([1, 5, 4]) output.Size([1, 5, 6]) # hidden_size 要乘以2 h_n.Size([4, 1, 3]) # num_layers 要乘以2 seq_len = 1 num_layers = 2 hidden_size = 3 input_size = 4 btach_size = 5