Skip to content
fn

unpack_sequence

→list of Tensor
unpack_sequence(packed_sequences: PackedSequence)

Split a PackedSequence into its variable-length sequences.

The inverse of pack_sequence: the sequences come back in the order they were packed in, whether or not they were sorted.

Parameters

packed_sequencesPackedSequence
Packed batch to split.

Returns

list of Tensor

One tensor per sequence, the b-th of shape (length_b, *).

Raises

ValueError
As pad_packed_sequence, for a malformed batch_sizes or unsorted_indices.

Examples

>>> import lucid
>>> from lucid.nn.utils.rnn import pack_sequence, unpack_sequence
>>> packed = pack_sequence([lucid.ones(2, 3), lucid.ones(4, 3)], enforce_sorted=False)
>>> [s.shape for s in unpack_sequence(packed)]
[(2, 3), (4, 3)]

Used by 1