unpad_sequence(padded_sequences: Tensor, lengths: Tensor | list[int], batch_first: bool = False)Split a padded batch back into its variable-length sequences.
The inverse of pad_sequence for right-padded batches: sequence
b is the first lengths[b] steps of the b-th batch entry.
Parameters
Returns
list of TensorB tensors, the b-th of shape (lengths[b], *).
Raises
ValueErrorIf
padded_sequences has fewer than two axes, lengths is
not 1-D with one entry per batch element, or an entry lies outside
[0, T].Examples
>>> import lucid
>>> from lucid.nn.utils.rnn import pad_sequence, unpad_sequence
>>> a, b = lucid.ones(4, 2), lucid.ones(2, 2)
>>> padded = pad_sequence([a, b], batch_first=True)
>>> [s.shape for s in unpad_sequence(padded, [4, 2], batch_first=True)]
[(4, 2), (2, 2)]