2017-10-15 1 views
0

각 레이어에 2 개의 레이어와 256 개의 셀이있는 LSTM을 구현하려고합니다. 나는 PyTorch LSTM 프레임 워크를 이해하려고 노력하고있다. 내가 편집 할 수있는 torch.nn.LSTM의 변수는 input_size, hidden_size, num_layers, bias, batch_first, dropout 및 bidirectional입니다.Pytorch에서 여러 셀이있는 LSTM 레이어를 구현하는 방법은 무엇입니까?

그러나 단일 레이어에 여러 개의 셀을 저장하려면 어떻게해야합니까?

답변

0

이 셀은 입력의 시퀀스 크기에 따라 자동으로 펼쳐집니다. 이 코드를 확인하시기 바랍니다 :

# 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/에 더 많은 예제를 찾을 수 있습니다.

관련 문제