Infini-gram: Scaling Unbounded n-gram Language Models to a Trillion Tokens

Are $n$-gram language models still relevant in this era of neural large language models (LLMs)? Our answer is yes, and we showcase their values in both text analysis and improving neural LLMs. This was done by modernizing $n$-gram LMs in two aspects. First, we train them at the same data scale as neural LLMs -- 5 trillion tokens. This is the largest $n$-gram LM ever built. Second, existing $n$-gram LMs use small $n$ which hinders their performance; we instead allow $n$ to be arbitrarily large, by introducing a new $\infty$-gram LM with backoff. Instead of pre-computing $n$-gram count tables (which would be very expensive), we develop an engine named infini-gram -- powered by suffix arrays -- that can compute $\infty$-gram (as well as $n$-gram with arbitrary $n$) probabilities with millisecond-level latency. The $\infty$-gram framework and infini-gram engine enable us to conduct many novel and interesting analyses of human-written and machine-generated text: we find that the $\infty$-gram LM has fairly high accuracy for next-token prediction (47%), and can complement neural LLMs to greatly reduce their perplexity. When analyzing machine-generated text, we also observe irregularities in the machine--$\infty$-gram agreement level with respect to the suffix length, which indicates deficiencies in neural LLM pretraining and the positional embeddings of Transformers.

Paper

References (51)

Scroll for more · 38 remaining

Similar papers

Reviewer DJ1F7/10 · confidence 3/52024-05-09

Summary

This paper primarily proposes improvements to the ngram language model, enhancing its capabilities through engineering optimizations that support grams of unlimited length, while also utilizing a larger-scale corpus. The ngram language model serves as an excellent complement to Large Language Models (LLMs).

Rating

7

Confidence

3

Ethics flag

1

Reasons to accept

1. This paper studies the Infinity-ngram model, which is an interesting issue and can also be helpful for the research on Large Language Models (LLMs). 2. This paper, through engineering optimizations, supports a large corpus and "infinity" ngram length. It also provides inspiration for subsequent related research.

Reasons to reject

1. The model proposed in the paper lacks practical experiments, making it difficult to see its future prospects.

Questions to authors

1. Compared to LLMs, besides calculating PPL, in what scenarios can the infinity ngram model apply? 2. How can the Ngram model complement LLMs? 3. Is it possible to directly generate text like auto regressive model? 4. How does the generalization of the Ngram model?

Reviewer fyaK7/10 · confidence 5/52024-05-09

Summary

This paper presents infini-gram, an n-gram model with unbounded n-gram order trained on very sized corpora containing 5T tokens. The paper shows that infini-gram can substantially outperform vanilla 5-gram models in terms of next token prediction (62% relative improvement) and can yield improvement in perplexity upon interpolating with neural lms. The paper shows that infini-gram can be implemented efficiently using suffix arrays, a technique that has been proposed in the past but not used for scaling the LM to trillions of tokens. Strengths: * Shows that an n-gram model can be scaled to substantially large corpora with trillions of tokens. * Shows that an n-gram model can yield perplexity improvements when combined with neural LMs * Demonstrates how the infini-gram can be used to conduct analysis of effective n (length of longest suffix with non-zero count) in neural LMs. Weaknesses: * There are some critical metrics which are not reported in the paper e.g. next token prediction for neural LM, perplexity of the infini-gram by itself * Though the infini-gram outperforms a 5-gram LM, it is still substantially weaker than a neural LM. While it is good to see that the infini-gram improves the perplexity of the neural LM, this result has been reported in prior literature https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/rnn_ctxt.pdf * The paper does not report comparison with other non-parametric approaches such as kNN LMs (Khandelwal et al. 2020)

Rating

7

Confidence

5

Ethics flag

1

Reasons to accept

* Shows that an n-gram models can be scaled to very large corpora with trillions of tokens - which are used currently for training neural LMs * Shows that the n-gram model can be used to perform interesting text analysis of neural LMs using metrics such as 'effective n' - which is the length of the longest suffix with non-zero count in training data * Demonstrates that the infini-gram model can be implemented efficiently using suffix arrays. Although this technique has been used in the past, this paper may further popularize its application in the research community

Reasons to reject

* The paper does not report key metrics such as next-token prediction accuracy of neural LM, the perplexity of infini-gram LM by itself. * The paper does not compare the proposed approach to other non-parametric LM approaches such as the kNN LM (Khandelwal et al) * The paper does not present an error analysis showing where the infini-gram either outperforms/underperforms a neural LM. e.g. is a neural LM better at generalization?

Questions to authors

* "When plotting the agreement level with respect to the suffix length, text generated by neural LMs with nucleus sampling is most similar to human-written text, among other decoding methods like greedy decoding and temperature sampling. For greedy decoding, the agreement plot suffers from significant fluctuation, which may be rooted in deficiencies in neural LM pretraining and the positional embeddings of Transformer" It is unclear how this finding is related to infini-gram. * Figure 3: what is the next token prediction accuracy for neural LM?

Reviewer fyaK2024-06-03

Thanks to the authors for providing additional details on metrics and answering my questions. I have increased my scores.

Reviewer CssV7/10 · confidence 4/52024-05-10

Summary

The paper presents an approach and method to train n-gram language models with arbitrarily large n, as well as training of n-gram models on trillion-scale datasets that match in size the datasets used for training neural language models. The approach to training infini-gram models is novel and allows training of models that perform significantly better than traditional n-gram models in next token prediction task. The authors also show that combining neural language model with an infini-gram model improves model perplexity significantly. All in all this is a good paper. It is well structured, the approach to extending n-gram context length is to my understanding novel and the results are promising. This is also the first paper to train n-gram models with a 5 trillion token dataset.

Rating

7

Confidence

4

Ethics flag

1

Reasons to accept

The approach and method is novel, the results are good and the paper is well written.

Reasons to reject

It could be argued that given the availability of compute resources and the performance of large neural language models, there is no need for n-gram models, especially as they cannot match neural language models in their capabilities. However, given the huge burden on environment that training large neural language models has, researching and developing alternative and less resource intensive methods is a welcome direction.

Reviewer Quuz9/10 · confidence 5/52024-05-13

Summary

Authors present a non-parameteric language model based on suffix trees, they extend the ngram tables in the following ways: (1) The consider the longest prefix that has non-zero count in the training corpus (n is variable and tend to be large) (2) The probability estimate is an interpolation between the neural LM and count based LM (3) Training corpus is in the scale of LLMs (trillion of tokens) The authors combine parameteric models NeuralLM with their count based \inf-gram method. The authors propose new metrics to analyze the performance of their \inf-gram method by studying the agreement between the neural method probability and the count based method. They use this agreement metric to analyze models of different sizes and try to distinguish human writing from machine one.

Rating

9

Confidence

5

Ethics flag

1

Reasons to accept

(1) I think the community will find this paper thought provoking: most of the recent work is on parameteric LM. Combining non-parameteric models shows improvement in our ability to maximize the likelihood of the evaluation corpus. Reviving this old approach might lead to the following interesting applications: (a) Possible ways to improve generation with a large predefined factual corpus. (b) Possible ways to identify (fingerprint) human-generated corpus vs machine one. (2) The paper is well written and easy to follow with honest description of what works (improving likelihood) and what does not work yet (generation). I really enjoyed the balanced tone of the work and the focus on the analysis.

Reasons to reject

(1) I found the sections describing the suffix trees and how the tokenizer interact with the suffix trees not as clear as the rest of text. (2) Lack of scaling law analysis with the impact of the training corpus (data) on perplexity.

Questions to authors

(1) Can you comment or possibility of extending the agreement analysis as a basis for machine detection of human writing? (2) Would extending the training corpus of the ngrams follow a scaling law trend? (3) I got confused by byte-pair and tokenized text representation used to fill the suffix tree, Would you count this a byte-level model? Maybe in the camera ready version try to walk the reader slowly with how the suffix tree being built using a toy example.

Reviewer CssV2024-06-04

Thank you for your response. I agree that the research direction is very relevant and that there could be use cases with the need for such models. I don’t see a reason to change the score.

Program Chairsdecision2024-07-10

Decision

Accept

© 2026 NYSGPT2525 LLC