torch.nn.utils.pack_sequence
function pack_sequence(sequences: Tensor[], options?: PackSequenceOptions): PackedSequencefunction pack_sequence(sequences: Tensor[], enforce_sorted: boolean, options?: PackSequenceOptions): PackedSequencePacks a list of variable length Tensors.
sequences should be a list of Tensors of size L x *, where L is the length of a sequence and * is any number of trailing dimensions.
Parameters
sequencesTensor[]- List of sequences to pack (must be sorted by length in decreasing order)
optionsPackSequenceOptionsoptional- Optional settings for packing
Returns
PackedSequence– A PackedSequence objectExamples
const a = torch.tensor([[1, 2], [3, 4], [5, 6]]); // length 3
const b = torch.tensor([[7, 8], [9, 10]]); // length 2
const c = torch.tensor([[11, 12]]); // length 1
const packed = torch.nn.utils.rnn.pack_sequence([a, b, c]);