torch.nn.utils.rnn.pack_sequence
-
torch.nn.utils.rnn.pack_sequence(sequences, enforce_sorted=True)
[source] -
Packs a list of variable length Tensors
sequences
should be a list of Tensors of sizeL x *
, whereL
is the length of a sequence and*
is any number of trailing dimensions, including zero.For unsorted sequences, use
enforce_sorted = False
. Ifenforce_sorted
isTrue
, the sequences should be sorted in the order of decreasing length.enforce_sorted = True
is only necessary for ONNX export.Example
>>> from torch.nn.utils.rnn import pack_sequence >>> a = torch.tensor([1,2,3]) >>> b = torch.tensor([4,5]) >>> c = torch.tensor([6]) >>> pack_sequence([a, b, c]) PackedSequence(data=tensor([ 1, 4, 6, 2, 5, 3]), batch_sizes=tensor([ 3, 2, 1]))
- Parameters
- Returns
-
a
PackedSequence
object
© 2019 Torch Contributors
Licensed under the 3-clause BSD License.
https://pytorch.org/docs/1.8.0/generated/torch.nn.utils.rnn.pack_sequence.html