A DataLoader turns a Dataset into iterable batches for training, validation, or testing. It controls batch size, shuffling, worker processes, incomplete batches, and optional collation. section 6.3 section 7.4
The Dataset prepares individual examples; the DataLoader assembles them into tensors consumed by the model. For classification, padding produces uniform sequences, while instruction tuning uses a custom collate function to batch variable-length inputs and targets. section 6.3 section 7.4
Configure separate loaders for each data split:
- Shuffle training data and drop the final incomplete batch. section 6.3
- Keep validation and test ordering stable and retain incomplete final batches. section 6.3
- Set batch size and worker count, then inspect the resulting batch shapes. section 6.3
- Attach a custom collate function when batching requires padding, masking, truncation, or device transfer. section 7.4
Classification batch
With batch_size=8, a training loader can yield an input tensor shaped [8, 120] and a label tensor shaped [8]. Instruction loaders may instead yield matching variable sequence shapes such as [8, 61] and [8, 61]. section 6.3 section 7.4
Figure 6.7 A single training batch consisting of eight text messages represented as token IDs. Each text message consists of 120 token IDs. A class label array stores the eight class labels corresponding to the text messages, which can be either 0 (“not spam”) or 1 (“spam”).
Inspect the eight-example classification batch, including its token-ID matrix and binary label array. section 6.3



