paddlespeech.s2t.io.utility module
- paddlespeech.s2t.io.utility.pad_list(sequences: List[ndarray], padding_value: float = 0.0) ndarray [source]
- paddlespeech.s2t.io.utility.pad_sequence(sequences: List[ndarray], batch_first: bool = True, padding_value: float = 0.0) ndarray [source]
Pad a list of variable length Tensors with
padding_value
pad_sequence
stacks a list of Tensors along a new dimension, and pads them to equal length. For example, if the input is list of sequences with sizeL x *
and if batch_first is False, andT x B x *
otherwise.B is batch size. It is equal to the number of elements in
sequences
. T is length of the longest sequence. L is length of the sequence. * is any number of trailing dimensions, including none.- Example:
>>> a = np.ones([25, 300]) >>> b = np.ones([22, 300]) >>> c = np.ones([15, 300]) >>> pad_sequence([a, b, c]).shape [25, 3, 300]
- Note:
This function returns a np.ndarray of size
T x B x *
orB x T x *
where T is the length of the longest sequence. This function assumes trailing dimensions and type of all the Tensors in sequences are same.- Args:
sequences (list[np.ndarray]): list of variable length sequences. batch_first (bool, optional): output will be in
B x T x *
if True, or inT x B x *
otherwisepadding_value (float, optional): value for padded elements. Default: 0.
- Returns:
np.ndarray of size
T x B x *
ifbatch_first
isFalse
. np.ndarray of sizeB x T x *
otherwise