FactorEngram:面向语言模型的基级门控分解式N-gram记忆

·

研究论文 · 2026/09/29

基于查找的记忆是扩展大语言模型参数的一种有前景的方法,它检索局部token模式(如n-gram)的学习表示,而非通过连续层计算重建。然而,现有设计如Engram将每个检索到的嵌入视为单一单元,每个嵌入存储在独立的哈希槽中并由单个标量门控调制。因此,多义模式无法选择性地读取与上下文相关的记忆组件。此外,参数仅通过哈希碰撞共享,这与语义基本无关。我们提出FactorEngram,一种具有基级上下文门控的因子化n-gram记忆。FactorEngram在跨模式共享的基向量字典上检索稀疏正则化系数,使相关模式能重用公共组件。同一字典也用于门控。在重建前,将主干隐藏状态与每个基向量评分以门控相应系数,从而让上下文单独调制每个记忆组件。FactorEngram还覆盖单个token和多token n-gram,并系统研究了记忆分支应插入的位置。在340M和1B参数的Transformer主干上,FactorEngram提升了语言建模和下游任务性能。消融研究证实了每个组件的贡献,并确定在中间层的注意力子层之前插入是一种有效配置。

该研究提出了一种改进的查找式记忆机制,通过因子化和基级门控提升了模型对多义模式的处理能力,并在多个规模上验证了有效性,对扩展大语言模型参数有重要意义。

Lookup-based memory has been a promising way to scale the parameters of large language models (LLMs). It retrieves learned representations of local token patterns, such as n-grams, instead of reconstructing them through successive layers of computation. However, existing designs such as Engram treat each retrieved embedding as a monolithic unit. Each embedding is stored in its own hashed slot and modulated by a single scalar gate. As a result, polysemous patterns cannot selectively read out the components of their memory that are relevant to the context. Moreover, parameters are shared only through hash collisions, which are largely unrelated to semantics. We propose FactorEngram, a factorized n-gram memory with basis-level contextual gating. FactorEngram retrieves sparsity-regularized coefficients over a dictionary of basis vectors shared across patterns, so related patterns can reuse common components. The same dictionary is also used for gating. The backbone hidden state is scored against each basis vector to gate the corresponding coefficient before reconstruction, which lets the context modulate each memory component individually. FactorEngram also covers both individual tokens and multi-token n-grams, and we systematically study where the memory branch should be inserted. On 340M- and 1B-parameter Transformer backbones, FactorEngram improves language modeling and downstream task performance. Ablation studies confirm the contribution of each component and identify insertion before the attention sublayer in the middle layers as an effective configuration.

阅读原文

参与讨论