Batch Size

Batch size is the number of training examples a model processes at once before updating its parameters. It controls the chunk size used during each step of training.

Data & AI

Instead of looking at the whole dataset at once (slow and memory-hungry) or one example at a time (noisy), training usually processes data in small batches such as 32 or 64 examples, updating after each batch.

Smaller batches give noisier but more frequent updates; larger batches give smoother updates but use more memory. The batch size is a key knob you tune for speed and stability.

Examples

Python

from torch.utils.data import DataLoader

loader = DataLoader(dataset, batch_size=32, shuffle=True)
for batch_x, batch_y in loader:
    print(batch_x.shape)
    break

Output:

torch.Size([32, 784])

Learn it in a lesson

See also

Back to the Dictionary