Which pooling choice is standard when an embedding model keeps a decoder-only LLM's causal mask?
Causal decoder embedders usually use last-token pool because causal masking gives only the final position full-sequence visibility; mean-pooling mixes vectors with mismatched context coverage.
Picture an assembly line where each worker only sees the parts that came before them. Worker 1 has seen one part. Worker 32 has seen everything. If you ask the line for a summary, you ask worker 32, the one who has seen the whole product. Averaging all the workers' opinions is silly because worker 1 was answering about one part while worker 32 was answering about the whole thing. Last-token pool asks worker 32. Mean pool averages every worker, which mixes apples and oranges.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Decoder-only LLMs have become the dominant pretraining base (Llama, Mistral, Qwen, DeepSeek). A natural question followed: can these models serve as embedding backbones? The answer is yes, but it changes the usual pooling choice.
Mental model: in a decoder, only the last token has seen the whole sequence. Pooling that last position is the standard aggregation. Mean pool mixes vectors with mismatched context coverage.
The causal mask and context coverage per position
What the causal mask does
A decoder-only transformer applies a causal (lower-triangular) attention mask:
This means token i can attend to positions 0 through i. Future positions (j > i) are masked out. The mask is what makes autoregressive generation work: the model cannot peek at future tokens.
Context coverage per position
Define context coverage c(i) as the number of positions token i has attended to. Under causal masking:
- Token 0: c(0) = 1 (only itself).
- Token 1: c(1) = 2 (itself plus one prior).
- ...
- Token N-1: c(N-1) = N (the full sequence).
The coverage grows linearly across positions. This growth is what decides the pooling choice.
Contrast with encoder bidirectional attention
In an encoder (BERT, RoBERTa), every position attends to every other position. c(i) = N for every i. All token vectors are computed from the full input. Mean pool works because the vectors are interchangeable views of the same content.
In a decoder, the vectors are NOT interchangeable. Token 0's vector has almost no context information. Token N-1's vector has full context. Averaging them mixes full-context and partial-context views.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- e5-mistral-7b-instruct (Microsoft, 2024) popularized the decoder-only last token with instruction pattern.
- NV-Embed-v2 (NVIDIA, 2024) ranked first on MTEB in August 2024; it removes the causal mask during contrastive training and pools with a latent attention layer on a Mistral-7B base.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhat does removing the causal mask and re-finetuning a decoder buy you?
It converts the decoder into a bidirectional encoder, enabling mean pool. Models like LLM2Vec do this. Cost: extra fine-tuning compute, and generation breaks unless both modes are trained, as in GritLM. Benefit: better embedding quality in some cases, but the gain is small and the engineering is invasive.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Reaching for mean pool because it is the encoder default. Mean pool assumes every position has seen the full input, which a causal decoder does not provide; the early-position vectors are not comparable to the late-position ones.
60 second bullets to scan on the way to the call.
What the causal mask does to attention in a decoder-only LLM
Per-position context coverage in a decoder vs an encoder
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.