liveBook · Manning

Padding token

As explained in Hugging Face in Action

A padding token is a special token inserted into shorter sequences so batched sequences have a uniform length.

A padding token is inserted into shorter tokenized sequences so every sequence in a batch has the same length. Transformer models use this uniform shape for efficient batch processing. section 5.2.2

Recognizing padding in BERT inputs

With bert-base-uncased, trailing 0 values in input_ids convert to [PAD] tokens. The corresponding attention_mask values are 0, distinguishing padding from the original sequence tokens, whose mask values are 1.

How Hugging Face in Action covers it

How deep it goes
Explains insertion, visible token IDs, converted [PAD] tokens, and attention-mask indicators without descending into model internals.
Examples
Demonstrates trailing zero input IDs, converted [PAD] tokens, and matching zero values in an attention mask.
What it assumes
Assumes familiarity with tokenized datasets and token IDs while identifying padding and attention masks through concrete outputs.
What you can do after
Apply padding through Hugging Face AutoTokenizer and inspect its input IDs, tokens, and attention mask.
How it connects
Connects padding tokens with tokenization, input IDs, attention masks, BERT, and transformer models.

Also explained in

Compare how 4 books explain padding token →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Hugging Face in Action. The section links point to the parts of the book it draws on.