Elamur Research

KenLM: Faster and Smaller Language Model Queries

Paper · 2011 · Kenneth Heafield

Summary

Statistical machine translation decoders ask a backoff-smoothed N-gram language model for probabilities extremely often. The cost of storing a huge, sparse set of n-grams with their probabilities and backoff weights therefore drives both decoder speed and RAM use. Heafield presents KenLM, an open-source (LGPL) C++ library that answers such queries from a model already estimated by other toolkits and stored as an ARPA file. It offers two data structures. PROBING keeps all n-grams of one order in a single linear-probing hash table keyed by 64-bit hashes, and is built for speed. TRIE is a reverse trie built from sorted arrays, with bit-level packing, interpolation search and optional quantization, and is built for small size. Against SRILM, PROBING runs 2.4 times as fast with 57% of the memory. TRIE uses less memory than the smallest lossless competitor and less CPU than the fastest one. These gains carry over to full decoding in Moses, cdec and Joshua, where KenLM is integrated. This made KenLM a practical default for large MT systems.

Key points

  • Baselines compared: SRILM 1.5.12, IRSTLM 5.60.02, MITLM 0.4, RandLM 0.2 and BerkeleyLM revision 152.
  • PROBING design:
    • Keys longer than 64 bits are replaced by their 64-bit hash.
    • A false hit happens about once in 266 billion queries on the baseline model.
    • The special hash 0 marks empty buckets.
    • Any n-gram can be reached with one lookup.
  • TRIE search: interpolation search lowers lookup cost from O(log |A|) to O(log log |A|). Using the known range of vocabulary IDs, instead of reading the array ends, alone gave a 24% speedup.
  • Pruned-model repair: in an SRILM-built model, 1.2% of n+1-grams lacked their n-gram suffix. KenLM inserts placeholder entries with probability −∞ so these n+1-grams stay reachable. BerkeleyLM's hash and compressed variants instead return wrong results in this case.
  • Quantization: values can use any width from 2 to 25 bits, versus IRSTLM's 8 and BerkeleyLM's 17–20.
  • Moses BLEU with TRIE: 27.24 exact, 27.22 at 8 bits, 27.09 at 4 bits.
  • RandLM comparison: RandLM needs the least RAM but scores lower (25.54 stupid backoff, 25.45 backoff) and runs slower.

Interesting ideas

  • I1. Long keys can be stored as fixed-width 64-bit hashes, with any real collisions detected once at build time, so lookup never compares full strings yet stays practically exact
  • I2. Hashed vocabulary IDs give keys a near-uniform spread, which makes interpolation search much faster than binary search, especially when the key range is known ahead of time
  • I3. When a pruned model leaves an entry without its parent, KenLM adds a marked placeholder that can be walked through but is never used as an answer, rather than silently falling back to a wrong value
  • I4. Each field is packed into exactly the number of bits its count requires, so shrinking the vocabulary directly shrinks the whole structure
  • I5. Lossy variants are judged by the end-task metric (BLEU), and weights are tuned both with the exact model and with the lossy one, rather than reporting memory savings alone

For Mova

How these ideas could serve Mova, our small open language model — its files, stages and tests:

  • I1 (world): the compiled ontology and knowledge graph (WordNet/FrameNet/Wikidata IDs, verb classes) could be keyed this way to cut memory and speed up lookups during world building.
  • I2 (tokens): lemma and morphology lexicon tables in crate en could sort hashed keys and use interpolation search for fast, compact lookups.
  • I3 (world): compiled knowledge with missing intermediate nodes (e.g., a gap in a class hierarchy) could get flagged stub nodes, keeping chains connected while explanations show the gap honestly.
  • I4 (tokens): tagger and lexicon tables could use minimal bit widths, with per-domain vocabulary filtering to keep the models small.
  • I5 (learn): any compressed or approximate component (e.g., a quantized gparse) should be scored on downstream answer accuracy, with re-tuned and non-re-tuned settings shown side by side.

Our summary of the paper, in our own words — not its text. The work belongs to its authors; read it at the links above.

 Institutions

 Fields, topics and concepts

 Shelves 4The field of science this work belongs to (OpenAlex fields).Computer Science · 19,503 worksArtificial Intelligence · 18,805 worksArts and Humanities · 17,959 worksLanguage and Linguistics · 17,789 works

 Topics 1Research subjects and languages the work is about.Language models & pretraining · 4,145 works

Cite

Cite as Kenneth Heafield. 2011. KenLM: Faster and Smaller Language Model Queries. Proceedings of the Sixth Workshop on Statistical Machine Translation.

The paper itself, not this page. BibTeX from the library's record of the work.

@inproceedings{heafield2011kenlm,
  title = {{KenLM: Faster and Smaller Language Model Queries}},
  author = {Kenneth Heafield},
  booktitle = {Proceedings of the Sixth Workshop on Statistical Machine Translation},
  year = {2011},
  url = {https://aclanthology.org/W11-2123/}
}

References

17 references, 2 of them with a card of ours. Each entry links to our card when we hold the work, else to OpenAlex and Google Scholar searches for it.

  1. Philip Clarkson and Ronald Rosenfeld. 1997. Statistical language modeling using the CMU-Cambridge toolkit. In Proceedings of Eurospeech. OpenAlex ↗ · Scholar ↗
  2. 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…
  3. 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. OpenAlex ↗ · Scholar ↗
  4. 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. OpenAlex ↗ · Scholar ↗
  5. 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… OpenAlex ↗ · Scholar ↗
  6. 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. OpenAlex ↗ · Scholar ↗
  7. Bo-June Hsu and James Glass. 2008. Iterative language model estimation: Efficient data structure & algorithms. In Proceedings of Interspeech, Brisbane, Australia. OpenAlex ↗ · Scholar ↗
  8. 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… OpenAlex ↗ · Scholar ↗
  9. Philipp Koehn. 2005. Europarl: A parallel corpus for statistical machine translation. In Proceedings of MT Summit. OpenAlex ↗ · Scholar ↗
  10. 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,…
  11. 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. OpenAlex ↗ · Scholar ↗
  12. Robert Parker, David Graff, Junbo Kong, Ke Chen, and Kazuaki Maeda. 2009. English gigaword fourth edition. LDC2009T13. OpenAlex ↗ · Scholar ↗
  13. Adam Pauls and Dan Klein. 2011. Faster and smaller ngram language models. In Proceedings of ACL, Portland, Oregon. OpenAlex ↗ · Scholar ↗
  14. Yehoshua Perl, Alon Itai, and Haim Avni. 1978. Interpolation search—a log log N search. Commun. ACM, 21:550–553, July. OpenAlex ↗ · Scholar ↗
  15. 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. OpenAlex ↗ · Scholar ↗
  16. Andreas Stolcke. 2002. SRILM - an extensible language modeling toolkit. In Proceedings of the Seventh International Conference on Spoken Language Processing, pages 901–904. OpenAlex ↗ · Scholar ↗
  17. David Talbot and Miles Osborne. 2007. Randomised language modelling for statistical machine translation. In Proceedings of ACL, pages 512–519, Prague, Czech Republic. OpenAlex ↗ · Scholar ↗

↑ back to top

This page in Markdown https://md.research.elamur.ai/free/en/papers/heafield-2011-kenlm-faster-smaller-language-model/