Compressing Trigram Language Models With Golomb Coding

Kenneth Church, Ted Hart, Jianfeng GaoEMNLP 2007

Abstract

Trigram language models are compressed using a Golomb coding method inspired by the original Unix spell program. Compression methods trade off space, time and accuracy (loss). The proposed HashTBO method optimizes space at the expense of time and accuracy. Trigram language models are normally considered memory hogs, but with HashTBO, it is possible to squeeze a trigram language model into a few megabytes or less. HashTBO made it possible to ship a trigram contextual speller in Microsoft Office 2007.

Introduction

In the mid-2000s, trigram language models were highly effective for natural language processing tasks but were notorious "memory hogs." While standard in speech recognition and machine translation, their massive footprints—often hundreds of megabytes—made them impractical for consumer desktop applications. This paper introduces HashTBO, a compression technique that enabled Microsoft to deploy the first contextual speller (the "blue squiggles") in Office 2007 by squeezing a model trained on 6 billion words into just a few megabytes.

The Challenge of Contextual Spelling

Contextual spelling involves catching errors where a word is spelled correctly but used incorrectly (e.g., "their" vs. "they're"). Catching these requires understanding the surrounding context, which trigram models provide. However, the memory budget for a background process in a standard word processor is extremely tight. The goal was to find a representation that traded a small amount of runtime speed and accuracy for a massive reduction in storage space.

Compression Methodologies

The authors evaluated two primary approaches to model compression, both built upon Stolcke Pruning, a technique that removes n-grams that do not significantly alter the model's probability estimates.

  1. ZipTBO (The Baseline): This uses a standard tree-based representation. Unigrams point to blocks of bigrams, which in turn point to trigrams. It employs quantization to reduce the precision of probability values and uses 2-byte word IDs to save space. This results in a footprint of approximately 4 bytes per n-gram.
  2. HashTBO (The Innovation): Inspired by Doug McIlroy’s 1982 Unix spell program, this method uses a "heroic" hashing trick. Instead of a tree structure, it maps each trigram to a single large integer hash code. These codes are sorted, and the system stores only the differences (interarrivals) between consecutive codes. Because these gaps follow an exponential distribution, they are encoded optimally using Golomb coding.
Memory usage vs. number of n-grams. The slope represents the average bytes per n-gram, with HashTBO showing superior efficiency over ZipTBO.

Key Results and Trade-offs

HashTBO achieves a footprint of roughly 3 bytes per n-gram, compared to 4 bytes for ZipTBO. While this difference seems small, it is critical when operating under extreme memory constraints.

Recall at 80% precision vs. memory footprint. HashTBO (blue diamonds) maintains performance at significantly lower memory levels than ZipTBO or standard models.

As shown in the evaluation, HashTBO significantly outperforms other methods when memory is limited to under 10MB. Even at a mere 1MB of memory, the model maintained roughly 27% recall. The primary trade-off for this efficiency is latency; HashTBO is approximately an order of magnitude slower than ZipTBO because looking up an n-gram requires processing interarrivals. However, for a background task like spell-checking, this latency was deemed acceptable.

Conclusion

The success of HashTBO demonstrates that mathematical insights into data distributions—specifically the use of Golomb coding for interarrival gaps—can overcome hardware limitations. This technology served as the "secret sauce" for Microsoft Office 2007, proving that high-quality linguistic context could be delivered within the resource constraints of a standard desktop PC.

Summary updated

BibTeX
@inproceedings{church2007compressing,
  author = {Kenneth Church and Ted Hart and Jianfeng Gao},
  title = {{Compressing Trigram Language Models With Golomb Coding}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2007},
  url = {https://openreview.net/forum?id=rJZKMGzOZr},
}
Figure