Causal N-gram encoder
Average pretrained embeddings over trailing windows. The default 2-gram and 3-gram windows expose local patterns at different scales.
The memory is already there.
Reuse pretrained token embeddings as local N-gram memory.
1 Nanjing University · 2 Tsinghua University * Equal contribution · † Corresponding author
Can a pretrained embedding space serve as local memory without retraining or a separate memory table?
NGM builds causal, multi-scale N-gram representations directly from the backbone’s token embeddings. A cosine gate then selects positively aligned signals and writes them into the decoder’s residual stream.
The result is a two-stage memory mechanism that leaves the model’s weights frozen and introduces no learned memory representations.
Two parameter-free components.
One pretrained representation space.
Average pretrained embeddings over trailing windows. The default 2-gram and 3-gram windows expose local patterns at different scales.
Measure compatibility with the decoder state. ReLU suppresses negative alignment; a fixed scale controls the residual write.
In Qwen3-8B, actual N-gram representations align more strongly with decoder hidden states than position-shuffled and random-token controls. This motivates a geometric gate without a learned projection.
Explore the analysis in the paper ↗Six backbones. Ten benchmarks.
Two language-model families.
Qwen3-1.7B · pass@1
Qwen3-1.7B · accuracy
+0.98 to +1.72 percentage points
| Benchmark | Baseline | NGM mean ± SD | Δ (pp) |
|---|
Source: manuscript Table 1. Scores are percentages; NGM reports mean ± sample standard deviation over three runs. Δ is the paper’s reported difference in percentage points. Average is unweighted across all ten tasks, calculated before rounding. TruthfulQA here uses the main table’s generative evaluation protocol.
Preliminary Qwen3-VL-2B-Instruct experiments apply NGM to the language decoder while retaining the visual encoder. On MMStar, the score rises from 54.67 to 56.20.
54.67 → 56.20
Read the updated manuscript for the full methodology, evaluation setup, ablations, and implementation details.
This page presents the updated manuscript. The arXiv record currently hosts the earlier release.
@article{qu2026ngm,
title = {NGM: A Plug-and-Play Training-Free
Memory Module for LLMs},
author = {Qu, Yuwen and Dong, Wenhui and Hamami, Camil and
Zhao, Ming and Si, Chenyang and Shan, Caifeng},
journal = {arXiv preprint arXiv:2605.16893},
year = {2026},
doi = {10.48550/arXiv.2605.16893}
}