Lune

AAAI2026Top-tier venue

Intermediate N-Gramming: Deterministic and Fast N-Grams for Large N and Large Datasets

Ryan R. Curtin, Fred Lu, Edward Raff, Priyanka Ranade

Abstract

The number of n-gram features grows exponentially in n, making it computationally demanding to compute the most frequent n-grams even for n as small as 3. Motivated by our production machine learning system built on n-gram features, we ask: is it possible to accurately, deterministically, and quickly recover the top-k most frequent n-grams? We devise a multi-pass algorithm called Intergrams that constructs candidate n-grams from the preceding (n -1)-grams. By designing this algorithm with hardware in mind, our approach yields more than an order of magnitude speedup (up to 33×!) over the next known fastest algorithm, even when similar optimization are applied to the other algorithm. Using the empirical power-law distribution over n-grams, we also provide theory to inform the efficacy of our multi-pass approach. Our code is available at https://github.com/rcurtin/Intergrams .

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

Questions to start from

Lune can draw on

the full paper · related work

Get the answer

Free to start. No credit card required.

Lineage

Builds onCited byLeft to right by year; the more cited, the higher.

Builds on1

  1. High-Dimensional Distributed Sparse Classification with Scalable Communication-Efficient Global UpdatesFred Lu, Ryan R. Curtin, Edward Raff, Francis Ferraro et al.KDD 2024 · 2 citations

Related papers

  1. Superposed Decoding: Multiple Generations from a Single Autoregressive Inference PassEthan Shen, Alan Fan, Sarah M. Pratt, Jae Sung Park et al.NeurIPS 2024 · 6 citations
  2. FR-Spec: Accelerating Large-Vocabulary Language Models via Frequency-Ranked Speculative SamplingWeilin Zhao, Tengyu Pan, Xu Han, Yudi Zhang et al.ACL 2025 · 14 citations
  3. Scaling Embedding Layers in Language ModelsDa Yu, Edith Cohen, Badih Ghazi, Yangsibo Huang et al.NeurIPS 2025 · 21 citations
  4. An Efficient Streaming Algorithm for Approximating Graphlet DistributionsMarco Bressan, T.-H. Hubert Chan, Qipeng Kuang, Mauro SozioSIGMOD 2026
  5. Efficient Training of Language Models with Compact and Consistent Next Token DistributionsAshutosh Sathe, Sunita SarawagiACL Findings 2024
Dusk over the sea between two cliffs drawn in fine vertical lines