API symbolsnn
Copy
tensorplay.nn.utils.rnn.pack_sequence
- tensorplay.nn.utils.rnn.pack_sequence(sequences, enforce_sorted: bool = True) PackedSequence[source]
Packs a list of variable length Tensors.
Consecutive call of the next functions:
pad_sequence,pack_padded_sequence.sequencesshould be a list of Tensors of sizeL x *, where L is the length of a sequence and*is any number of trailing dimensions, including0.For unsorted sequences, use enforce_sorted = False. If
enforce_sortedisTrue, the sequences should be sorted in the order of decreasing length. enforce_sorted = True is only necessary for ONNX export.Example
>>> from tensorplay.nn.utils.rnn import pack_sequence >>> a = tp.tensor([1, 2, 3]) >>> b = tp.tensor([4, 5]) >>> c = tp.tensor([6]) >>> pack_sequence([a, b, c]) PackedSequence(data=tensor([1, 4, 6, 2, 5, 3]), batch_sizes=tensor([3, 2, 1]), sorted_indices=None, unsorted_indices=None)
- Parameters:
- Returns:
a
PackedSequenceobject
Help improve this page
Found an error, an unclear step, or a missing example?
Was this page helpful?
