Zenaique

Which pooling choice is standard when an embedding model keeps a decoder-only LLM's causal mask?

MCQ·Hard·4.0 · 0·~1 min·Asked atCanvaInduced AiReplicate
Attempt it
TL;DR

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.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

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.

Key concepts

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:

maskij={0i≥j−∞i<j\text{mask}_{ij} = \begin{cases} 0 & i \geq j \\ -\infty & i < j \end{cases}

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.

Why mean pool is a weaker fit on decoder hidden states
Last-token pool and the instruction prefix interaction
The LLM2Vec escape hatch and pooling by architecture
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

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.
Sign in to see more production examples.

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?
A

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.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

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.

Sign in to see all red flags and common mistakes.

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

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Why is cosine similarity preferred over Euclidean distance for text embeddings?
Flashcard·Easy