PyTorch DataLoader

The dataloader class provides a way to specify how many data points to sample from a dataset for each epoch in a model training loop. In addition, you can specify whether to shuffle the datapoints or not.

from torch.utils.data import DataLoader loader = DataLoader(dataset, batch_size=10, shuffle=True)

Then , when implementing a training loop, you can iterate through the loader and it would provide the specified number of points with the given shuffle criteria.

def train(model, opt, loss, loader, epochs): model.train() for epoch in epochs: for X,y in loader: #... pass pass pass