AI Dictionary of Terms

Batch Size

The number of training examples utilized in one iteration (forward and backward pass) before the model’s internal parameters are updated.

The Simple Version

How many flashcards a student looks at before taking a practice test to see how much they’ve learned. A small batch size means updating knowledge frequently but noisily; a large batch size means updating knowledge less often but more accurately.

Detailed Explanation

In mini-batch gradient descent, the dataset is divided into subsets (batches). The loss is calculated for the batch, gradients are computed, and weights are updated.

Key Characteristics

Business Context

Real-World Analogy

Eating a meal. Batch size 1 is taking one bite and checking if you’re full after every bite (slow, noisy). Batch size = whole meal is eating the entire plate at once and checking (fast, but you might overeat/crash). Mini-batch is eating in sensible portions.

Code Example

# Conceptual: Setting batch size in a PyTorch DataLoader
from torch.utils.data import DataLoader

# dataset = MyCustomDataset(...)

# Batch size of 32 means the model sees 32 examples before updating weights
train_loader = DataLoader(dataset, batch_size=32, shuffle=True)

for batch_inputs, batch_labels in train_loader:
    # Forward pass, calculate loss, backward pass, optimizer step
    pass

Common Misconceptions

Sources & Further Reading