Inferensys

Glossary

Special Tokens

Reserved vocabulary entries with specific control functions, such as [CLS] for classification, [SEP] for separation, [MASK] for masked language modeling, and [PAD] for batching.
ML engineer managing model versions on laptop, version history visible, technical Git-like workflow.
RESERVED VOCABULARY ENTRIES

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.

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.

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.

CONTROL VOCABULARY

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.

01

[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
768-1024
Typical embedding dimensions
02

[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]
03

[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
04

[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
05

[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
06

[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
CONTROL TOKENS

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.

RESERVED VOCABULARY COMPARISON

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 TokenBERT (Encoder)GPT (Decoder)T5 (Encoder-Decoder)

Classification Token

[CLS]

Sequence Separation

[SEP]

<|endoftext|>

</s>

Masked Language Modeling

[MASK]

<extra_id_N>

Padding Token

[PAD]

<|padding|>

<pad>

Unknown Token

[UNK]

<|unk|>

<unk>

Beginning of Sequence

<|startoftext|>

<s>

Lossless Decoding

SPECIAL TOKENS

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.

Prasad Kumkar

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.