KenLM: Faster and Smaller Language Model Queries
Written for the Research library (claude-opus-5-5) from the paper text, in our own words: the license "CC BY-NC-SA 3.0 (ACL Anthology, before 2016)" does not allow redistributing the text itself. Original — aclanthology.org/W11-2123.pdf
Summary
Decoders for statistical machine translation look up N-gram language model scores extremely often, so how a backoff-smoothed model is stored largely determines both runtime and RAM usage. Heafield presents KenLM, an open-source (LGPL) C++ library with two query structures for ARPA models built by other toolkits. PROBING places all n-grams of one order into a single linear-probing hash table keyed by 64-bit hashes, so any n-gram can be reached in one lookup. TRIE is a reverse trie built on sorted arrays. It packs fields at the bit level, uses interpolation search in place of binary search, and can optionally quantize values. The author benchmarks both against SRILM, IRSTLM, MITLM, RandLM and BerkeleyLM in perplexity runs and inside the Moses decoder. PROBING was the fastest option tested. TRIE needed less memory than any other lossless package and still ran faster than SRILM. KenLM is thread-safe and already integrated into Moses, cdec and Joshua, so these savings carry over to practical translation systems.
Key points
- Compared with SRILM, PROBING answers queries about 2.4× faster while needing roughly 57% of its memory.
- TRIE lowers search cost from O(log |A|) to O(log log |A|) through interpolation search. Using the known range of vocabulary IDs alone gave a 24% speedup. Quantization can use any width from 2 to 25 bits, compared with fixed widths in IRSTLM (8 bits) and BerkeleyLM (17–20 bits).
- About 1.2% of higher-order n-grams in SRILM-pruned models lacked their suffix. KenLM fills these gaps with placeholder entries so it still returns correct results, which BerkeleyLM's hash and compressed variants do not.
- In single-threaded Moses, unquantized TRIE took 82.9 min, used 12.16 GB resident memory and scored 27.24 BLEU. The 4-bit TRIE used 7.74 GB and scored 27.09 BLEU. RandLM stupid backoff used only 5.07 GB but took 218.7 min and scored 25.54 BLEU.
- Code: kheafield.com/code/kenlm. It has minimal dependencies (POSIX, g++) and offers C++ and Java interfaces.
Cited by
- Towards a Cleaner Document-Oriented Multilingual Crawled Corpus
- Fanar: An Arabic-Centric Multimodal Generative AI Platform
- Farasa: A Fast and Furious Segmenter for Arabic
- Unsupervised Domain Clusters in Pretrained Language Models
- Tower: An Open Multilingual Large Language Model for Translation-Related Tasks
- Good-Enough Compositional Data Augmentation
- Findings of the 2015 Workshop on Statistical Machine Translation
- Findings of the 2016 Conference on Machine Translation
- Findings of the 2017 Conference on Machine Translation (WMT17)
- Findings of the 2018 Conference on Machine Translation (WMT18)
- Evaluating the Evaluation Metrics for Style Transfer: A Case Study in Multilingual Formality Transfer
- Evaluating prose style transfer with the Bible
- Style Transformer: Unpaired Text Style Transfer without Disentangled Latent Representation
- Colorless Green Recurrent Networks Dream Hierarchically
- Scalable Modified Kneser-Ney Language Model Estimation
- Semantics-Based Machine Translation with Hyperedge Replacement Grammars
- On the Impact of Various Types of Noise on Neural Machine Translation
- Probabilistic Modelling of Morphologically Rich Languages
- OBELICS: An Open Web-Scale Filtered Dataset of Interleaved Image-Text Documents
- Few-shot Learning with Multilingual Language Models
- Predicting and Using a Pragmatic Component of Lexical Aspect of Simple Past Verbal Tenses for Improving English-to-French Machine Translation
- What is it? Disambiguating the different readings of the pronoun 'it'
- Facebook FAIR's WMT19 News Translation Task Submission
- CulturaX: A Cleaned, Enormous, and Multilingual Dataset for Large Language Models in 167 Languages
- OpenWebMath: An Open Dataset of High-Quality Mathematical Web Text
- MLS: A Large-Scale Multilingual Dataset for Speech Research
- Scaling Speech Technology to 1,000+ Languages
- Enhancing function word translation with syntax-based statistical post-editing
- VoxPopuli: A Large-Scale Multilingual Speech Corpus for Representation Learning, Semi-Supervised Learning and Interpretation
- CCNet: Extracting High Quality Monolingual Datasets from Web Crawl Data
- Creating a Translation Matrix of the Bible's Names Across 591 Languages
Cite
@inproceedings{heafield2011kenlm,
title = {{KenLM: Faster and Smaller Language Model Queries}},
author = {Heafield, Kenneth},
booktitle = {Proceedings of the Sixth Workshop on Statistical Machine Translation},
year = {2011},
url = {https://aclanthology.org/W11-2123/}
}References
- Philip Clarkson and Ronald Rosenfeld. 1997. Statistical language modeling using the CMU-Cambridge toolkit. In Proceedings of Eurospeech. find
- Chris Dyer, Adam Lopez, Juri Ganitkevitch, Johnathan Weese, Ferhan Ture, Phil Blunsom, Hendra Setiawan, Vladimir Eidelman, and Philip Resnik. 2010. cdec: A decoder, alignment, and learning framework for finite-state and context-free translation models. In Proceedings of the ACL 2010 System Demonstra… find
- Marcello Federico and Nicola Bertoldi. 2006. How many bits are needed to store probabilities for phrase-based translation? In Proceedings of the Workshop on Statistical Machine Translation, pages 94–101, New York City, June. find
- Marcello Federico, Nicola Bertoldi, and Mauro Cettolo. 2008. IRSTLM: an open source toolkit for handling large scale language models. In Proceedings of Interspeech, Brisbane, Australia. find
- Ulrich Germann, Eric Joanis, and Samuel Larkin. 2009. Tightly packed tries: How to fit large models into memory, and make them load fast, too. In Proceedings of the NAACL HLT Workshop on Software Engineering, Testing, and Quality Assurance for Natural Language Processing, pages 31–39, Boulder, Color… find
- David Guthrie and Mark Hepple. 2010. Storing the web in memory: Space efficient language models with constant time retrieval. In Proceedings of EMNLP 2010, Los Angeles, CA. find
- Bo-June Hsu and James Glass. 2008. Iterative language model estimation: Efficient data structure & algorithms. In Proceedings of Interspeech, Brisbane, Australia. find
- Philipp Koehn, Hieu Hoang, Alexandra Birch, Chris Callison-Burch, Marcello Federico, Nicola Bertoldi, Brooke Cowan, Wade Shen, Christine Moran, Richard Zens, Chris Dyer, Ondrej Bojar, Alexandra Constantin, and Evan Herbst. 2007. Moses: Open source toolkit for statistical machine translation. In Annu… find
- Philipp Koehn. 2005. Europarl: A parallel corpus for statistical machine translation. In Proceedings of MT Summit. find
- Zhifei Li, Chris Callison-Burch, Chris Dyer, Sanjeev Khudanpur, Lane Schwartz, Wren Thornton, Jonathan Weese, and Omar Zaidan. 2009. Joshua: An open source toolkit for parsing-based machine translation. In Proceedings of the Fourth Workshop on Statistical Machine Translation, pages 135–139, Athens,… find
- Kishore Papineni, Salim Roukos, Todd Ward, and Wei-Jing Zhu. 2002. BLEU: A method for automatic evalution of machine translation. In Proceedings 40th Annual Meeting of the Association for Computational Linguistics, pages 311–318, Philadelphia, PA, July. find
- Robert Parker, David Graff, Junbo Kong, Ke Chen, and Kazuaki Maeda. 2009. English gigaword fourth edition. LDC2009T13. find
- Adam Pauls and Dan Klein. 2011. Faster and smaller ngram language models. In Proceedings of ACL, Portland, Oregon. find
- Yehoshua Perl, Alon Itai, and Haim Avni. 1978. Interpolation search—a log log N search. Commun. ACM, 21:550–553, July. find
- Bhiksha Raj and Ed Whittaker. 2003. Lossless compression of language model structure and word identifiers. In Proceedings of IEEE International Conference on Acoustics, Speech and Signal Processing, pages 388– 391. find
- Andreas Stolcke. 2002. SRILM - an extensible language modeling toolkit. In Proceedings of the Seventh International Conference on Spoken Language Processing, pages 901–904. find
- David Talbot and Miles Osborne. 2007. Randomised language modelling for statistical machine translation. In Proceedings of ACL, pages 512–519, Prague, Czech Republic. find