espnet2.speechlm.utils.data.pad_list
Less than 1 minute
espnet2.speechlm.utils.data.pad_list
espnet2.speechlm.utils.data.pad_list(sequences: List[ndarray | Tensor], pad_value: float = 0.0) → Tuple[Tensor, Tensor]
Pad a list of sequences to the same length and stack them.
Uses right padding (padding at the end of sequences). Assumes the FIRST dimension is the time/sequence length.
- Parameters:
- sequences – List of sequences to pad and stack. Each can be of any shape [seq_len, …] where seq_len is variable
- pad_value – Value to use for padding (default: 0.0)
- Returns:
- Padded and stacked tensor of shape [batch, max_seq_len, …]
- Length tensor of shape [batch] with original sequence lengths (dtype=long)
- Return type: Tuple of
- Raises:
- ValueError – If sequence list is empty or sequences have inconsistent shapes
- TypeError – If sequences contain non-tensor/non-array types
