espnet2.speechlm.dataloader.batch.batchfy
Less than 1 minute
espnet2.speechlm.dataloader.batch.batchfy
espnet2.speechlm.dataloader.batch.batchfy(keys: List[T], key_to_length: Dict[T, int], batch_token: int, batch_method: str) → List[List[T]]
Create batches using the specified batching method.
- Parameters:
- keys – List of sample keys to batch.
- key_to_length – Dictionary mapping each key to its length.
- batch_token – Maximum number of tokens allowed per batch.
- batch_method – Batching method to use (“bucket” or “pack”).
- Returns: List of batches, where each batch is a list of keys.
- Raises:ValueError – If batch_method is invalid or if any sample length exceeds batch_token.
