0
我打算在每層中實現2層和256個單元的LSTM。我正在嘗試瞭解PyTorch LSTM框架。我可以編輯的torch.nn.LSTM中的變量是input_size,hidden_size,num_layers,bias,batch_first,dropout和雙向。如何在Pytorch中實現帶有多個單元的LSTM層?
但是,如何在單個圖層中有多個單元?
我打算在每層中實現2層和256個單元的LSTM。我正在嘗試瞭解PyTorch LSTM框架。我可以編輯的torch.nn.LSTM中的變量是input_size,hidden_size,num_layers,bias,batch_first,dropout和雙向。如何在Pytorch中實現帶有多個單元的LSTM層?
但是,如何在單個圖層中有多個單元?
這些單元格將根據您在輸入中的序列大小自動展開。請看看這個代碼:
# One cell RNN input_dim (4) -> output_dim (2). sequence: 5, batch 3
# 3 batches 'hello', 'eolll', 'lleel'
# rank = (3, 5, 4)
inputs = Variable(torch.Tensor([[h, e, l, l, o],
[e, o, l, l, l],
[l, l, e, e, l]]))
print("input size", inputs.size()) # input size torch.Size([3, 5, 4])
# Propagate input through RNN
# Input: (batch, seq_len, input_size) when batch_first=True
# B x S x I
out, hidden = cell(inputs, hidden)
print("out size", out.size()) # out size torch.Size([3, 5, 2])
您可以在https://github.com/hunkim/PyTorchZeroToAll/找到更多的例子。