← 返回 2026-02-02

LMK > CLS:面向稠密向量的 Landmark Pooling LMK > CLS: Landmark Pooling for Dense Embeddings

Meet Doshi, Aashka Trivedi, Vishwajeet Kumar, Parul Awasthy, Yulong Li, Jaydeep Sen, Radu Florian, Sachindra Joshi 📅 2026-01-29 👍 5 2026-07-13 08:35
dense embeddings landmark tokens long-context retrieval pooling

用在序列中插入并聚合 Landmark token 的简单池化策略,显著提升长上下文检索的泛化能力,同时不牺牲短上下文性能。

前置知识

Dense Retrieval Embedding

稠密检索将查询和文档映射为固定维度向量,再用向量相似度(如余弦或内积)排序,取代传统稀疏词袋方法。模型通常以 Transformer 为骨干,通过对隐藏状态做池化生成单一句向量,用于检索、聚类、分类等任务。稠密嵌入的关键在于如何从可变长度的 token 表示中提取出信息充分、区分力强的文档级向量,因此池化策略直接影响检索质量。

本文聚焦于池化环节对稠密嵌入质量的改进,理解稠密检索框架有助于把握研究对象和应用场景。

Pooling Strategies ([CLS], Mean, Latent Attention)

池化策略决定如何把多个 token 表示压缩成单向量。[CLS] 池化使用序列开头的特殊 token 聚合语义,Mean 池化对所有 token 做均匀平均,Latent Attention 则引入可学习潜在向量来加权聚合。不同策略在信息保留、计算效率和位置偏差上各有权衡,传统做法是在训练和推理时选择同一策略。

论文系统分析这些策略的缺陷,并提出新的 Landmark 池化,读者需要熟悉基线才能理解创新点。

Rotary Positional Embeddings (RoPE)

RoPE 通过旋转位置编码,将相对位置信息注入注意力分数。查询和键向量分别施加旋转 R_{\theta,m} q 与 R_{\theta,n} k,使得 \tilde{q}_m^\top \tilde{k}_n = q^\top_m R_{\theta,n-m} k_n。随着相对距离 |n-m| 增大,注意力 logits 会呈衰减趋势(长期衰减),这对 [CLS] 池化在长序列上的注意力分布有直接影响。

论文用 RoPE 解释 CLS 池化的位置偏差,理解该机制对掌握实验动机至关重要。

Contrastive Learning / InfoNCE Loss

对比学习通过 InfoNCE 损失将正样本对拉近、负样本对拉远。公式通常为 \mathcal{L} = -\log \frac{\exp(s(q,d^+)/\tau)}{\exp(s(q,d^+)/\tau) + \sum_i \exp(s(q,d^-_i)/\tau)},温度 \tau 控制分布锐度。检索微调一般采用硬负样本和知识蒸馏分数,以增强嵌入的区分力。

论文实验设置详细描述了训练损失和负样本配置,熟悉 InfoNCE 有助于解读性能差异和训练细节。

Long-Context Evaluation Benchmarks

长上下文评估数据集(如 MLDR、LongEmbed、COIR)覆盖数万 token 的文档,要求模型在推理时处理远超训练序列长度的输入。常用指标包括 NDCG@10、Precision@1 等,用于衡量检索精度是否随上下文长度提升或退化。

论文核心贡献在于改善长上下文泛化,理解这些 benchmark 和指标才能准确比较不同池化策略的表现。

研究动机

现有文本嵌入模型普遍依赖 [CLS] 池化或均值池化来生成向量,但二者在长上下文场景下暴露出明显短板。[CLS] 池化将全部语义压缩到序列首位,RoPE 的长期衰减令其在超过训练长度时注意力快速向早期 token 集中,导致嵌入严重偏向文本开头。论文在 MLDR 英文子集的长文档上观察到,[CLS] 的注意力权重在 8k 之后几乎没有分布,若训练序列长度仅为 512,推理长度扩展到 32k 时性能显著下降(图 1、2)。均值池化虽不受位置约束,却把所有 token 均匀平均,高信号局部特征被大量噪声稀释,短上下文任务上性能通常低于 [CLS]。此外,Latent Attention 等复杂策略引入额外参数与推理开销,但本质仍是均值聚合,无法根本缓解上述问题。面对检索、聚类、分类等需要强泛化的应用,这些瓶颈限制了长文档嵌入的可靠性。

本文的目标是论文希望提出一种既简单又稳健的池化策略,使文本嵌入在长上下文推理时保持高精度,同时不损失短上下文性能,且能够兼容现有训练框架和多种语言模型。目标是提供一种无需显著增加计算成本即可扩展到数万 token 的方案,以便直接替换现有 [CLS] 或均值池化。

与已有工作不同的是,作者从 Landmark Embedding 在 RAG 场景中减轻分块断裂的启发出发,首次将 Landmark token 引入双向稠密嵌入的池化环节,并系统地分析其对长上下文泛化的影响。与以往关注多 CLS 或可学习加权不同,论文强调“少而精”的 Landmark token 与均值池化的组合,既保留局部高信号,又通过多个 Landmark 在不同位置独立评估全文,突破单一 [CLS] 的容量瓶颈。

核心方法

Landmark (LMK) Pooling 的核心思路是:把输入序列按固定或随机粒度切分成多个片段,在片段之间插入特殊的 Landmark token,再对这些 Landmark 的上下文表示做均值池化。直觉上,Landmark 充当“区域锚点”,各自承担汇聚相邻片段信息的职责,从而避免把全部语义压到序列首位或被无关 token 稀释。技术路线分两阶段:首先在 tokenizer 层面执行“Landmark Tokenization”,在 token ID 列表里插入 [SEP] 或 EOS 作为 LMK,并同步调整注意力掩码;随后在编码器输出后仅对 LMK 位置的向量求均值,得到最终句向量。这样保持单一向量输出格式,却引入了更均匀的上下文采样。

与 [CLS] 池化只依赖单个特殊 token 相比,LMK 池化让多个分布在不同位置的 token 分别学习区域语义,再由均值聚合,既能像 Mean 池化一样避免单点瓶颈,又能通过 Landmark 选择性关注高信号片段,防止全局平均导致的稀释。论文证明,这种方法在训练序列长度仅为 512 时就能对 32k 的推理长度保持稳健,而 [CLS] 即使训练长度增加到 8k 仍存在显著位置偏差。Landmark 的数量可通过粒度参数灵活调节,粒度越细(如每 32 token 插入一个)长上下文提升越明显,但计算成本随 token 数增长有限。

方法步骤详情

第一步,Landmark Tokenization(算法 1):给定文本 X,先用 tokenizer 得到普通 token 序列 T;按粒度 g 切分为 z_1, z_2, ..., z_n;在开头插入 [CLS],并在每个片段后追加一个 [SEP](用作 LMK),最终生成 X_{tok} 及对应的注意力掩码 X_{mask}。第二步,编码器前向:输入 X_{tok} 得到隐藏状态 H_{enc}。第三步,Landmark Pooling(算法 2):从 H_{enc} 中选取所有 LMK 位置的向量,计算均值 x_{enc} = (1/|I_L|) \sum_{i \in I_L} H_{enc,i,:};返回 x_{enc} 作为句向量。整个过程仅增加少量特殊 token,推理时无需额外参数。

技术新颖性

LMK 池化的新颖性体现在三个层面:其一,它首次将 Landmark token 从 RAG 的分块缓解手段迁移到双向嵌入池化,赋予其新的语义锚点功能;其二,它以“多点均值”替代“单点选择”或“全序列均值”,形成介于 CLS 与 Mean 之间的稳健中间态;其三,论文提供系统分析,从 RoPE 长期衰减、注意力分布、LMK 局部亲和度等角度解释为何该策略能同时保持短长上下文性能。相比 Latent Attention 等需额外可学习向量和前馈层的方案,LMK 仅改动 tokenization 与池化索引,实现更低成本的跨长度泛化。

MLDR (English) dataset long context retrieval performance for different pooling strategies using modernbert-base fine-tuned on MSMarco Passages.
Figure 1: MLDR (English) dataset long context retrieval performance for different pooling strategies using modernbert-base fine-tuned on MSMarco Passages.
Retrieval Hits@k between LMK token embeddings and left, right, or any (left or right) chunk embeddings for sequences of length 8,192, with LMK granularity 32 (≥248 chunks).
Figure 4: Retrieval Hits@k between LMK token embeddings and left, right, or any (left or right) chunk embeddings for sequences of length 8,192, with LMK granularity 32 (≥248 chunks).

实验结果

实验覆盖英文和多语言、短长上下文多种设定。ModernBERT-base 在 MSMarco Passage 微调后,LMK(Variable, Gran.32)在域内 MSMarco Dev NDCG@10 达 40.3,略优于 CLS 的 39.8;在短上下文 BEIR、MTEBv2、MIRACL 上保持 44–48 的水准,与 CLS 相当;但在长上下文 MLDR Test、COIR、LongEmbed 上分别取得 35.0、47.0、62.4(P@1 | NDCG@10 48.1),显著高于 CLS 的 24.9、43.5、43.3。多语言 mmBERT-base 在 MIRACL-HN 58.0、MLDR 37.2、Multi-EURLEX 31.5、LongEmbed 62.1,均优于 Mean/Latent Attention 15–20 点。增加训练序列长度至 8k 时,CLS 与 LMK 在 MLDR 上趋近,但 LMK 在 Multi-EURLEX 和 LongEmbed 仍保持 30+ 的优势。RetroMAE 预训练后,LMK 在 gte-en-mlm-base 的 LongEmbed 提升约 5 点。总体来看,LMK 以极小的计算开销换取显著的长上下文泛化收益,同时短上下文性能与 CLS 相当甚至略优。

Comparison of pooling strategies across in-domain and out-of-domain retrieval benchmarks for ModernBERT-base fine-tuned on MSMarco passage data.
Table 1: Comparison of pooling strategies across in-domain and out-of-domain retrieval benchmarks for ModernBERT-base fine-tuned on MSMarco passage data.
Comparison of pooling strategies across in-domain and out-of-domain retrieval benchmarks for mmBERT-base when fine-tuned with multilingual BGE-m3 training data.
Table 2: Comparison of pooling strategies across in-domain and out-of-domain retrieval benchmarks for mmBERT-base when fine-tuned with multilingual BGE-m3 training data.
Comparison of pooling strategies across in-domain and out-of-domain retrieval benchmarks for gte-en-mlm-base and ModernBERT-base when fine-tuned with MSMarco document data.
Table 3: Comparison of pooling strategies across in-domain and out-of-domain retrieval benchmarks for gte-en-mlm-base and ModernBERT-base when fine-tuned with MSMarco document data.
Effect of fine-tuning maximum sequence length (MSL) on long-context embedding tasks for mmBERT-base, comparing CLS and LMK pooling.
Table 4: Effect of fine-tuning maximum sequence length (MSL) on long-context embedding tasks for mmBERT-base, comparing CLS and LMK pooling.
Long-context finetuning ablations on gte-multilingual-base with a maximum sequence length of 8192.
Table 5: Long-context finetuning ablations on gte-multilingual-base with a maximum sequence length of 8192.
Effect of RetroMAE pretraining followed by fine-tuning for CLS and LMK pooling across gte-en-mlm-base and ModernBERT-base models.
Table 6: Effect of RetroMAE pretraining followed by fine-tuning for CLS and LMK pooling across gte-en-mlm-base and ModernBERT-base models.
Comparison of pooling strategies across in-domain and out-of-domain retrieval benchmarks for gte-en-mlm-base when fine-tuned with MSMarco passage data.
Table 7: Comparison of pooling strategies across in-domain and out-of-domain retrieval benchmarks for gte-en-mlm-base when fine-tuned with MSMarco passage data.
Comparison of pooling strategies across in-domain and out-of-domain retrieval benchmarks for gte-en-mlm-base when fine-tuned with MSMarco document data.
Table 8: Comparison of pooling strategies across in-domain and out-of-domain retrieval benchmarks for gte-en-mlm-base when fine-tuned with MSMarco document data.
Comparison of pooling strategies on LongEmbed retrieval benchmark for modernbert-base fine-tuned on MSMarco document data.
Table 9: Comparison of pooling strategies on LongEmbed retrieval benchmark for modernbert-base fine-tuned on MSMarco document data.
NDCG@10 retrieval performance on MIRACL-HN (18) dataset across languages under different pooling and granularity settings for mmBERT-base.
Table 10: NDCG@10 retrieval performance on MIRACL-HN (18) dataset across languages under different pooling and granularity settings for mmBERT-base.
NDCG@10 retrieval performance on MLDR (13) dataset across languages under different pooling and granularity settings for mmBERT-base.
Table 11: NDCG@10 retrieval performance on MLDR (13) dataset across languages under different pooling and granularity settings for mmBERT-base.
Zero-shot long-document classification F1 scores on MultiEURLEX across 23 languages using fine-tuned mmBERT-base, evaluated with a maximum sequence length of 8192.
Table 12: Zero-shot long-document classification F1 scores on MultiEURLEX across 23 languages using fine-tuned mmBERT-base, evaluated with a maximum sequence length of 8192.
Comparison of pooling strategies on in-domain and out-of-domain retrieval benchmarks for gte-en-mlm-base, pretrained with CLS or LMK pooling and fine-tuned on MS MARCO passage data.
Table 13: Comparison of pooling strategies on in-domain and out-of-domain retrieval benchmarks for gte-en-mlm-base, pretrained with CLS or LMK pooling and fine-tuned on MS MARCO passage data.
Comparison of pooling strategies on in-domain and out-of-domain retrieval benchmarks for ModernBERT-base, pretrained with CLS or LMK pooling and fine-tuned on MS MARCO passage data.
Table 14: Comparison of pooling strategies on in-domain and out-of-domain retrieval benchmarks for ModernBERT-base, pretrained with CLS or LMK pooling and fine-tuned on MS MARCO passage data.
MTEB-v2 embedding benchmark results. We report task-wise averages across pooling strategies for gte-en-mlm-base and ModernBERT-base, trained on MSMarco Passage data.
Table 15: MTEB-v2 embedding benchmark results. We report task-wise averages across pooling strategies for gte-en-mlm-base and ModernBERT-base, trained on MSMarco Passage data.
Long-context retrieval performance across datasets for different pooling strategies using ModernBERT-base fine-tuned on MSMarco Passages.
Figure 5: Long-context retrieval performance across datasets for different pooling strategies using ModernBERT-base fine-tuned on MSMarco Passages.
查看结构化数据
任务指标本文基线提升
MLDR (English) long-context retrieval NDCG@10 35.0 (LMK Variable Gran.32, ModernBERT-base) 24.9 (CLS Pooling) +10.1 点
COIR long-context code retrieval NDCG@10 47.0 (LMK Variable Gran.32, ModernBERT-base) 43.5 (CLS Pooling) +3.5 点
LongEmbed (English) long-context retrieval P@1 | NDCG@10 62.4 | 48.1 (LMK Variable Gran.32) 43.3 | 37.2 (CLS Pooling) P@1 +19.1 点,NDCG@10 +10.9 点
MLDR multilingual retrieval NDCG@10 37.2 (mmBERT-base, LMK 128) 24.9 (CLS Pooling) +12.3 点
Multi-EURLEX long-document classification Macro-F1 31.5 (mmBERT-base, LMK 128) 27.5 (CLS Pooling) +4.0 点

局限与改进

论文指出,尽管 LMK 在长上下文性能上大幅领先,但其优势主要体现在检索和分类任务,尚未系统验证于生成或摘要等任务。插入 Landmark token 会略微增加序列长度,在极端长上下文(如 65k token)下仍有计算开销,尽管影响有限。Variable Granularity 虽提升鲁棒性,但在不同任务上仍需选择合适的粒度(32/64/128),缺少自动学习机制。作者亦承认,CLS 在训练序列长度达到 8k 时于 MLDR 上表现接近 LMK,说明 LMK 的边际收益可能随训练数据长度增加而缩减。个人观察:论文主要在英语和有限多语言数据上评估,面对更高资源或跨模态场景,LMK 是否仍保持同等优势尚需验证;此外,论文未深入分析 Landmark token 的语义变化,若某些 Landmark 学到冗余表示,可能限制性能上限。

独立分析的弱点

首先,LMK 需要手动设定粒度,不同任务可能需要不同粒度,缺乏自适应机制,易导致超参搜索成本。改进方向可以探索可学习的 Landmark 插入策略,利用强化学习或可微采样自动决定插入位置。其次,Landmark 数量随序列长度线性增长,在极长上下文下仍可能带来内存压力,未来可研究稀疏 Landmark 或基于内容的关键片段选择,进一步压缩 token 数。第三,当前分析集中于检索与分类,对生成任务的验证不足;若要将 LMK 用于 RAG 中的查询-段落匹配或多模态嵌入,需评估其对语义复杂度更高的任务的影响。

未来方向

论文建议将 LMK 池化扩展到多向量嵌入、跨模态检索以及与长上下文训练策略结合的场景。Landmark 表示可用于构建 chunk-level 索引,改善 RAG 中的段落选择。后续研究可探索 Landmark token 在 RAG 解码器中的作用,或将其与对比学习中的 hard negative mining 结合,提升细粒度检索能力。作者还提到,Landmark 训练后的模型可作为“区域锚点”用于多任务迁移,未来可在领域自适应或持续学习中测试其稳定性。

复现评估

论文以开源代码库 FlagEmbedding 为基础,提供训练与评估脚本,便于复现。实验使用 8 块 NVIDIA H100 80GB GPU、DeepSpeed 与 HuggingFace Accelerate,算力需求较高但对中等规模团队仍可实现。数据集(MSMarco、MLDR、LongEmbed、MIRACL 等)均可公开获取,作者亦分享了超参数配置,复现门槛相对适中。若缺少 H100 等高端硬件,可在更小模型或缩短序列长度下验证趋势,但可能影响长上下文收益的完整性。