The usage for pack sequence here seems simple enough. Sort the tensors by their length then feed it to the function. However, I needed to ask if there are any additional steps that I must be aware of when using
pack_sequence to train my RNN on a dataset whose sequences have varying length. I looked through the forums but can’t find a definitive answer.
>>> from torch.nn.utils.rnn import pack_sequence >>> a = torch.tensor([1,2,3]) >>> b = torch.tensor([4,5]) >>> c = torch.tensor() >>> pack_sequence([a, b, c]) PackedSequence(data=tensor([ 1, 4, 6, 2, 5, 3]), batch_sizes=tensor([ 3, 2, 1]))