espnet.nets.pytorch_backend.nets_utils.roll_tensor
Less than 1 minute
espnet.nets.pytorch_backend.nets_utils.roll_tensor
espnet.nets.pytorch_backend.nets_utils.roll_tensor(x: Tensor, lengths: Tensor, roll_amounts: Tensor | None = None, fixed_intervals: int | None = None) → Tensor
Left-roll tensor x by roll_amounts, only within lengths and : optionally quantized.
- Parameters:
- x – input tensor (B, T, D)
- lengths – lengths of each sequence (B,)
- roll_amounts – random shift amounts (B,). If None, random shift amounts are generated.
- fixed_intervals – if not None, roll_amounts are quantized to multiples of this.
- Returns: rolled tensor (B, T, D)
- Return type: rolled_x
Useful to apply roll augmentation to the input, while considering the input length for each sample.