collate_fn for Variable-Length Inputs
Pad and stack ragged samples.
When Samples Don't Match
Stacking into a batch needs every sample the same shape. But sentences and audio clips have different lengths, so the default collate step fails. 🧩
What collate_fn Does
The DataLoader gathers a list of samples and passes them to collate_fn, which merges them into one batch. By default it simply stacks tensors.
All lessons in this course
- Write a Custom Dataset Class
- Batching, Shuffling & num_workers
- collate_fn for Variable-Length Inputs
- Normalize and Standardize Inputs