Home Glossary Padding

Padding - Page 2

Padding extends shorter sequences with special placeholder values so examples of different lengths can share one tensor and be processed as a batch. Text tokenizers usually add a dedicated padding token on the left or right; image and audio pipelines may pad spatial or time dimensions with zeros or another defined value. An attention mask or length record tells the model which positions are real so padding does not influence predictions or loss. Excessive padding wastes memory and computation, making length-based batching useful. The padding side and value must match the model’s training assumptions, particularly for autoregressive generation, positional encodings, convolutional boundaries, and exported inference runtimes.