Special tokens are reserved vocabulary entries that serve explicit control functions rather than representing linguistic content. Unlike standard tokens that encode words or subwords, these tokens—such as [CLS], [SEP], [MASK], and [PAD]—act as structural delimiters and task-specific signals within a model's input sequence. They are defined during vocabulary construction and assigned fixed token IDs that the model learns to associate with specific behaviors during pre-training.
Glossary
Special Tokens

What Are Special Tokens?
Special tokens are reserved vocabulary entries with specific control functions that structure input sequences and guide model behavior during pre-training and inference.
The most common special tokens include [CLS] for aggregating sequence-level representations in classification tasks, [SEP] for demarcating sentence boundaries in tasks like next-sentence prediction, [MASK] for indicating tokens to predict during masked language modeling, and [PAD] for standardizing sequence lengths in batched processing. A corresponding attention mask tensor is generated alongside these tokens to instruct the model's self-attention mechanism to ignore padding positions, ensuring only genuine content tokens influence the output representations.
Core Special Tokens in Transformer Models
Special tokens are reserved vocabulary entries that provide structural and task-specific signals to transformer models, enabling functions like sequence classification, text generation, and batch processing.
[CLS] — Classification Token
A special token prepended to the input sequence in models like BERT. The final hidden state corresponding to this token is used as the aggregate sequence representation for classification tasks. It is designed to capture the entire input's contextual meaning.
- Origin: Introduced in the BERT architecture (Devlin et al., 2018)
- Usage: The output embedding at the [CLS] position is fed into a linear classifier
- Models: BERT, RoBERTa, DistilBERT
- Note: Not used in GPT-style decoder-only models, which rely on the last token's hidden state
[SEP] — Separation Token
A delimiter token used to mark the boundary between two distinct segments of input, such as a question and a passage in question-answering tasks. It signals to the model that the preceding and following text belong to different logical units.
- Primary function: Segment differentiation in sentence-pair tasks
- Secondary function: Marks the end of a single sequence
- Used with: Token type IDs (segment embeddings) to distinguish segment A from segment B
- Example:
[CLS] What is BPE? [SEP] Byte-Pair Encoding is... [SEP]
[MASK] — Masked Language Modeling Token
A placeholder token that replaces a percentage of input tokens during pre-training. The model's objective is to predict the original vocabulary ID of the masked token based on bidirectional context. This forces the model to learn deep bidirectional representations.
- Training strategy: Typically 15% of tokens are masked; of those, 80% replaced with [MASK], 10% with random tokens, 10% unchanged
- Inference use: Enables fill-in-the-blank prompting for models like BERT
- Contrast: Not used in autoregressive (left-to-right) models like GPT
[PAD] — Padding Token
A token used to extend shorter sequences to a uniform length within a batch, enabling efficient parallel processing on GPUs. The token ID for [PAD] is typically 0, and its embedding is ignored during computation via the attention mask.
- Attention mask role: A binary tensor sets positions with [PAD] to 0, preventing the model from attending to them
- Loss calculation: Padding positions are excluded from the loss function
- Critical for: Efficient batching of variable-length inputs in both training and inference
[UNK] — Unknown Token
A fallback token representing any word or subword unit not present in the model's vocabulary. In modern subword tokenization schemes like BPE and WordPiece, the [UNK] token is rarely triggered because unknown words are decomposed into known subword units.
- Legacy relevance: Critical in word-level vocabularies where OOV rates were high
- Modern mitigation: Byte-level BPE (used in GPT-2 and later) eliminates [UNK] entirely by operating on raw bytes
- Indicator: A high frequency of [UNK] tokens signals a vocabulary mismatch between training data and inference text
[BOS] & [EOS] — Sequence Boundary Tokens
Tokens that explicitly mark the beginning of sequence and end of sequence. These are essential for autoregressive decoder models that generate text token-by-token, as [EOS] signals the model to stop generation.
- [BOS]: Prepended to the input; also called
<s>in SentencePiece and<|startoftext|>in some GPT variants - [EOS]: Appended to the target; generation halts when this token is predicted
- Critical for: Preventing infinite loops in text generation and enabling the model to learn sequence termination
- Chat models: Often use
<|im_start|>and<|im_end|>as structured variants
How Special Tokens Function in Model Architectures
An overview of how reserved vocabulary entries direct the flow of information and define structural boundaries within transformer-based language models.
Special tokens are reserved vocabulary entries that serve as explicit control signals within a model's input sequence, dictating structural boundaries and task-specific behavior rather than representing linguistic content. They function by injecting a fixed, learned embedding at a specific position, which the self-attention mechanism then uses as a global reference point to aggregate sequence-level information or to prevent cross-segment attention leakage.
During pre-training, the model learns distinct vector representations for tokens like [CLS] and [SEP] that are optimized for specific objectives. The [CLS] token's final hidden state is trained to capture a pooled representation of the entire input for classification tasks, while [SEP] and the corresponding attention mask teach the model to recognize sentence boundaries and segment pairs, enabling tasks like next-sentence prediction.
Special Tokens Across Model Families
A comparison of the primary control and structural special tokens used by major language model architectures to manage sequence boundaries, classification, and generation tasks.
| Special Token | BERT (Encoder) | GPT (Decoder) | T5 (Encoder-Decoder) |
|---|---|---|---|
Classification Token | [CLS] | ||
Sequence Separation | [SEP] | <|endoftext|> | |
Masked Language Modeling | [MASK] | <extra_id_N> | |
Padding Token | [PAD] | <|padding|> | |
Unknown Token | [UNK] | <|unk|> | |
Beginning of Sequence | <|startoftext|> | ||
Lossless Decoding |
Frequently Asked Questions
Clear, technical answers to the most common questions about the reserved vocabulary entries that control modern language model behavior.
A special token is a reserved vocabulary entry that performs a specific control or structural function rather than representing linguistic content. Unlike standard tokens that map to words or subwords, special tokens act as explicit signals to the model's architecture. Common examples include [CLS] for sequence classification, [SEP] for segment separation, [MASK] for masked language modeling, and [PAD] for batch uniformity. These tokens are typically added to a tokenizer's vocabulary during training and are never split by subword algorithms. Their embeddings are learned alongside standard tokens, allowing the model to develop dedicated representations for these control functions. Special tokens are the primary mechanism by which developers inject task-specific structure into the otherwise uniform stream of token IDs fed into a transformer model.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Special tokens are integral to a broader tokenization pipeline. Explore these related concepts to understand how control tokens interact with vocabulary construction, sequence processing, and model input formatting.
Attention Mask
A binary tensor generated during tokenization that explicitly instructs the model's self-attention mechanism to ignore padding tokens and focus solely on genuine content.
- 1 indicates a real token to attend to
- 0 indicates a [PAD] token to be ignored
- Prevents padding from corrupting the contextual representation of the sequence
- Essential for efficient batch processing of variable-length inputs
Chat Template
A structured formatting script within a tokenizer that converts a sequence of chat messages into a single tokenized string with the appropriate control tokens for a specific instruction-tuned model.
- Inserts [CLS], [SEP], and role-specific tokens automatically
- Ensures the model receives the correct conversational structure
- Varies significantly between model families (LLaMA vs. Mistral vs. Vicuna)
- Critical for maintaining prompt format fidelity in production
Vocabulary
The fixed set of unique tokens that a language model recognizes, mapping each token to a unique integer Token ID. Special tokens are explicitly reserved entries within this vocabulary.
- Built during training via algorithms like BPE or WordPiece
- Special tokens occupy the first indices (e.g., ID 0 for [PAD])
- Vocabulary size is a critical hyperparameter balancing encoding efficiency and embedding parameters
- Typical sizes range from 32k to 256k tokens
Padding
The strategy of adding a special [PAD] token to shorter sequences in a batch to ensure all input tensors have a uniform length for efficient parallel processing on GPUs.
- Enables dynamic batching without sacrificing throughput
- Padding can be applied to the left or right side depending on the architecture
- Decoder-only models typically use left-padding for autoregressive generation
- Always paired with an attention mask to nullify padded positions
Encoding
The process of converting a raw text string into a sequence of Token IDs using a tokenizer's vocabulary and merge rules. Special tokens are injected during this step to provide structural signals.
- Input:
"Hello world" - Output:
[101, 7592, 2088, 102](with [CLS] and [SEP]) - Includes normalization, pre-tokenization, and subword splitting
- The resulting integer sequence feeds directly into the model's embedding layer
Subword Tokenization
A strategy that segments words into smaller, meaning-bearing units like morphemes or frequent character sequences. This approach fundamentally reduces the Out-of-Vocabulary (OOV) problem that plagued early word-level tokenizers.
- Algorithms include BPE, WordPiece, and Unigram
- Enables models to represent rare and unseen words by composing known subwords
- Special tokens like [UNK] are rarely needed with byte-level variants
- Balances vocabulary size with encoding efficiency

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us