BERT prepends a [CLS] token to every input, what is its actual job in the model?
The [CLS] token's final-layer hidden state serves as BERT's pooled sequence representation, the single vector fed to downstream classification heads.
Imagine a classroom where every student writes a short note about a story they read together, and one designated 'class summary' student listens to all the other notes and writes one overall summary of the whole story. When the teacher needs to grade the class on understanding, she just reads the summary student's note instead of all the individual ones. [CLS] is BERT's summary student: it sits at position zero, listens to (attends to) every other token in the sentence, and at the end its single vector is what downstream tasks like sentiment classification or topic detection use to make a decision.
Detailed answer & concept explanation~6 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
5 min: [CLS] as a learned pooled-representation slot, how bidirectional attention enables position-zero pooling, role of NSP and MLM training, why classification heads consume only [CLS] hidden state, distinction from [SEP] and [MASK], contrast with decoder-only last-token pooling.
Real products, models, and research that use this idea.
- BERT (2018) introduced [CLS] and the pretraining recipe; still the canonical example studied in 2026 NLP courses.
- DeBERTa-v3 and ModernBERT continue the [CLS] pooling convention for classification fine-tuning, both shipped in 2024-2025 production embedding stacks.
- Cross-encoder rerankers like the bge-reranker family take the [CLS] hidden state as their relevance score head, used widely in 2026 RAG stacks alongside Llama 4 Maverick and Claude Opus 4.7.
- Sentence-BERT replaced [CLS] pooling with mean pooling for sentence embedding tasks; the trade-off depends on whether you need classification or retrieval geometry.
- Decoder-only LLMs (GPT-5.5, Llama 4) skip [CLS] entirely because causal attention prevents position-zero from seeing later tokens; they use last-token pooling instead.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does [CLS] pool well even when NSP is removed (RoBERTa)?
QHow does Sentence-BERT improve sentence embedding quality over vanilla BERT's [CLS]?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Confusing [CLS] with [SEP] or with autoregressive BOS. [CLS] is a learned aggregation slot for classification; [SEP] separates sentence pairs; BOS in GPT-style models marks generation start.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.