PackedSequence with DataLoader
Hey, I’m trying to reproduce some previous work I did with Theano in PyTorch, with RNNs. I want to be able to mask the sequences I pass as input to an RNN based model. This should be easy enough… However, there’s a couple of annoying issues that are bugging me: Cheers!
miguelvr
jekbradbury
What’s the best way to sort / rearrange tensors in PyTorch?
miguelvr
is this correct usage? <SCODE>import torch
x = torch.autograd.Variable(torch.randn(5, 3, 2))
l = torch.nn.Linear(2, 2)
r = torch.nn.RNN(2, 2)

px = torch.nn.utils.rnn.pack_padded_sequence(x, [5, 3, 1])
ph = torch.nn.utils.rnn.PackedSequence(l(px.data), px.batch_sizes)
py, h = r(ph)
<ECODE>
ShigekiKarita
Yes, that looks right to me.
jekbradbury
Is this true? It is not working for me since nn.Linear requires attribute ‘dim’.
stefanonardo
I’m observing the same behavior. I don’t think linear layers can take packed sequences as inputs.
eplu
nlgranger
Moore
Is there possible any better way now to apply the packed sequence with the linear layers?
Moore