FactorEngram: Factorized N-gram Memory with Basis-Level Gating for Language Models
Bowen Yang, Jingbo Zhou, Qinghong Miao, Hua Wu
Baidu Inc. · Nanyang Technological University
Published September 28, 2026 · on the feed September 29, 2026 · ▲ 4 · arXiv 2609.35578
The abstract
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.
The Brief
2:41A short podcast summary of the paper. Written and voiced by AI.
Transcript
FactorEngram. Factorized N-gram Memory with Basis-Level Gating for Language Models. By Bowen Yang and three others, from Baidu and Nanyang Technological University. Published on the twenty-eighth of September. No code repository is linked to it.
Lookup-based memory has been a promising way to scale the parameters of large language models. Instead of rebuilding the representation of a local token pattern, such as an n-gram, through layer after layer of computation, the model simply retrieves a learned representation for it. Existing designs such as Engram, though, treat each retrieved embedding as one monolithic unit. Each embedding lives in its own hashed slot, and a single scalar gate modulates it.
Two limitations follow. A polysemous pattern, one whose meaning depends on context, cannot selectively read out the parts of its memory that are relevant to the context at hand. It gets all of it, scaled up or down as a whole. And parameters are shared between patterns only when hashes happen to collide, which has largely nothing to do with meaning.
FactorEngram replaces the monolithic slot with a factorized memory. There is a dictionary of basis vectors, shared across all patterns. What a pattern retrieves is not a whole embedding but a set of coefficients over that dictionary, regularized to be sparse. Related patterns can therefore reuse common components, so sharing follows the structure of the dictionary rather than the accident of a hash.
The same dictionary is used for gating. The backbone's hidden state is scored against each basis vector, and that score gates the corresponding coefficient before the memory is reconstructed. The context therefore modulates each memory component individually, instead of turning the whole memory up or down with one number. That is exactly what the polysemous case was missing. FactorEngram also covers both individual tokens and multi-token n-grams, and the authors study systematically where in the network the memory branch should be inserted.
On Transformer backbones of three hundred and forty million parameters and of one billion parameters, FactorEngram improves language modeling and downstream task performance. Those are two different kinds of gain. Language modeling measures how well the model predicts text directly, while the downstream tasks check whether that improvement carries over into the work the model is actually used for. Ablation studies then take the design apart, and confirm that each of its components makes a contribution, so the gain is not carried by one piece while the others go along for the ride. On placement, the study identifies insertion before the attention sublayer, in the middle layers, as an effective configuration.
One dictionary, used twice. It is where patterns store what they share, and it is the axis along which context chooses what to read. Both of the old design's weaknesses, the all-or-nothing gate and the meaningless sharing, are addressed by that single change in how memory is laid out.
Paper Quest · 7 chapters · about 39 min
Play this paper
Learn it by doing: make the calls the authors made, guess the result before you see it, and defend it in a viva graded on your own words. Chapter 1 is right here.
Chapter 1 🧩 · The problem
A memory that answers every question with the same whole embedding. That is the wall here.
You are adding a lookup table to a language model: for each short run of tokens, it fetches a learned embedding instead of rebuilding that knowledge layer by layer.
The road ahead
- 1 · The problem ~6 min A lookup memory stores each token pattern as one whole embedding behind one scalar gate, so context cannot pick its parts and sharing follows hashes, not meaning.
- 2 · What came before ~3 min
- 3 · The key idea ~8 min Store each pattern as coefficients over a shared dictionary of basis vectors, and let the context gate every coefficient separately.
- 4 · Choose your own research ~3 min
- 5 · Build the method ~8 min Retrieve sparse coefficients, gate each one by how well the hidden state matches its basis vector, then rebuild the memory and add it to the backbone.
- 6 · The experiment ~6 min You’ll guess: On 340M and 1B Transformer backbones, where did FactorEngram's factorized n-gram memory bring gains?
- 7 · The viva ~5 min Three questions from the examiners, answered in your own words. Win it for the paper’s trophy.
Free, with Google or an email address. Your stars and progress are kept.