Passing PackedSequence as input to nn.Linear

I am implementing neural machine translation using attention. The pre-attention LSTM takes a PackedSequence as input, and produces a PackedSequence as output. But to compute the attention-energies, I need to pass this output (from the pre-attention RNN) through a nn.Linear. So, how to extract the variable length output-sequences from this PackedSequence?

  • Also, Is there a way to extract the individual output sequences from the PackedSequence.data tensor?

I think the torch.nn.utils.rnn.pad_packed_sequence() should do the job.