https://pytorch.org/tutorials/beginner/nlp/sequence_models_tutorial.html
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
torch.manual_seed(1)
lstm = nn.LSTM(3, 3)
inputs = [torch.randn(1, 3) for _ in range(5)]
hidden = (torch.randn(1, 1, 3),
torch.randn(1, 1, 3))
for i in inputs:
out, hidden = lstm(i.view(1, 1, 3), hidden)
print(out)
# print(hidden)
print("\n")
inputs = torch.cat(inputs).view(len(inputs), 1, 3)
hidden = (torch.randn(1, 1, 3),
torch.randn(1, 1, 3))
out, hidden = lstm(inputs, hidden)
print(out)
# print(hidden)
在这两个示例中,“输出”如何打印出不同的内容? for循环的顺序应该与将它们堆叠并运行LSTM一样?