面向长上下文语言模型的可合并模型侧聚合状态 Mergeable Model-Side Aggregation States for Long-Context Language Models 预印本

⚠️ 本文为 预印本(arXiv 公开版本),尚未经过正式同行评审。作者自发公开,结论未经期刊审稿验证,阅读时请知悉。
发布时间:2026-07-29
👁️ 预览文献
💡 AI 中文简介
长上下文语言模型在处理集合类聚合任务(如去重计数、集合关系、分组统计)时,随着上下文变长会越来越不可靠。本文提出一种模型侧聚合接口:在冻结的语言模型旁维护紧凑的基于哈希的HyperLogLog(HLL)草图状态,模型处理上下文时由抽取器把每条相关记录映射为规范身份并哈希更新状态。该状态可跨上下文片段合并,也可直接读出用于下游推理,无需额外的生成-执行-返回循环。状态固定为2 KiB(2048个寄存器),不随上下文长度或集合基数增长。在百万条记录的去重计数实验中平均相对误差为1.6%;256个片段合并结果与单次遍历完全一致;在3969个聚合后推理任务上达到99.2%准确率,比直接全上下文推理提升63.2个百分点(Qwen)和56.3个百分点(Gemma)。
领域自然语言处理 / 长上下文语言模型与集合聚合
适合谁读需要一定专业背景(了解语言模型推理与概率数据结构)
核心贡献1. 提出模型侧聚合接口,用固定预算的HLL草图状态伴随冻结语言模型,支持去重计数、集合合并、重叠估计与分组聚合,无需额外生成-执行-返回循环;2. 状态可跨片段合并且与单次遍历结果完全一致,资源占用有界、误差可控,在多项聚合推理任务上大幅优于全上下文与CoT推理。
关键数据HLL状态固定2 KiB(2048寄存器),不随上下文长度或集合基数增长;百万条记录去重计数平均相对误差1.6%;256个片段合并读出与单次遍历完全一致;3969个聚合后推理任务上Gemma 4(31B, BF16)达99.2%准确率(精确聚合为100.0%,差距0.8个百分点,95% CI 0.5–1.3);相比直接全上下文推理提升63.2个百分点(Qwen)和56.3个百分点(Gemma),相比CoT提升60.9和63.2个百分点;Oolong-Synth 1200任务子集上Qwen 91.1%、Gemma 99.3%。
推荐理由如果你关心长上下文模型为什么一遇到“数有多少个不同项”就翻车,这篇用2 KiB的HLL草图把聚合状态外挂到模型上,效果提升几十个百分点,还开源了代码,值得一读。
关键词["长上下文语言模型", "集合聚合", "HyperLogLog草图", "可合并状态", "去重计数", "模型侧接口"]

原文摘要

查看英文原文摘要

A known limitation of long-context language models is their increasingly unreliable performance in non-additive, set-based aggregation as context length grows. Examples include cardinality estimation, set relationships, and grouped statistics, which widely exist in logs, program outputs, tables, and multi-turn conversations. To provide the aggregation state required by these tasks, we introduce a model-side aggregation interface that maintains compact Hash-based HyperLogLog (HLL) sketch states alongside a frozen language model. While the model processes the context, an extractor maps each relevant record to a canonical identity. The identity is then hashed and updates the HLL state. These states can be merged across context segments and/or read out directly for downstream reasoning, avoiding an additional generate-execute-return cycle. We validate the proposed approach by setting the HLL state size as 2 KiB (2,048 registers), which does not increase with context length or set cardinality. In a distinct-count experiment involving one million records, the mean relative error was 1.6%. In a separate merge test, states built from as many as 256 segments produced exactly the same readout as a single pass over the same stream. On 3,969 aggregate-then-reason tasks from 174 source windows, the fixed-budget interface reached 99.2% accuracy on Gemma 4 (31B, BF16), compared with 100.0% under exact aggregation; the paired gap was 0.8 percentage points (95% window-cluster CI: 0.5-1.3 points). On a matched set of 174 items, our method improved over direct full-context reasoning by 63.2 points on Qwen and 56.3 points on Gemma. The corresponding gains over chain-of-thought (CoT) reasoning were 60.9 and 63.2 points, respectively. On a fixed 1,200-task Oolong-Synth subset, our method reached 91.1% on Qwen and 99.3% on Gemma. Code is available at https://github.com/songdc98/sketchops.