Special Tokens › Special Tokens
Language AI HandbookAll chapters Special Tokens › Special TokensOne section · Sections in this chapter1 / 12 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Subword tokenization gives models a manageable vocabulary of meaningful pieces. But vocabulary alone doesn't tell a model what it's supposed to do with a sequence. Is this text the input to a classifier or just half of a pair? Where does one sentence end and another begin? Which positions should be ignored because the batch had variable-length sequences? What word was deliberately erased for the model to predict?
These questions are answered not by ordinary tokens, but by special tokens: purpose-built vocabulary entries that carry structural and semantic signals rather than word-level meaning. Think of special tokens as punctuation for the machine: just as a period signals the end of a sentence and a question mark changes how you interpret what came before it, special tokens signal to the model how to interpret the structure of the whole input sequence. Without them, a raw sequence of subword IDs is ambiguous in ways that would make multi-task learning nearly impossible.
Special tokens are the grammar of the tokenizer interface. They let a single model architecture serve radically different tasks without changing its weights, simply by changing how the input is framed. A BERT model fine-tuned for question answering uses the same underlying weights as one fine-tuned for sentiment classification. The only difference in how inputs are prepared is the arrangement of special tokens around the content. This architectural elegance is one reason the transformer paradigm scaled so successfully across domains.
Understanding special tokens is essential for two reasons. First, they appear in every modern transformer-based model, and misusing them is one of the most common sources of subtle bugs in NLP applications. A missing attention mask for padding tokens, a double-injected [CLS], or an incorrectly handled segment ID can corrupt model inputs in ways that are hard to detect without careful inspection. Second, their design reveals important decisions about model architecture: why BERT uses [CLS] the way it does, why some models need segment embeddings while others don't, and why padding tokens require special handling during attention. Understanding the reasoning behind these choices makes you a better practitioner, not just someone who can copy tokenization boilerplate.
This chapter covers special tokens: what each one does, why it was designed that way, how models learn from them, and how to handle them correctly in practice. We'll go deep on BERT's core special tokens, trace the evolution toward generative models with their own boundary conventions, and finish with a practical guide to custom special tokens for task-specific models. By the end, you will understand the mechanics and the design philosophy that makes special tokens such a flexible control mechanism.