Abstract
Efficient processing of tera-scale text data is an important research topic. This paper proposes lossless compression of N-gram language models based on LOUDS, a succinct data structure. LOUDS succinctly represents a trie with M nodes as a 2M + 1 bit string. We compress it further for the N-gram language model structure. We also use 'variable length coding' and 'block-wise compression' to compress values associated with nodes. Experimental results for three large-scale N-gram compression tasks achieved a significant compression rate without any loss.
Introduction
N-gram language models are fundamental components in various natural language processing tasks, including statistical machine translation and speech recognition. As training corpora grow to "tera-scale" (such as the Google Web 1T corpus), the resulting models become massive, often requiring hundreds of gigabytes of memory. This scale presents a significant hurdle for deployment on standard hardware.
The Challenge of Scale
Traditional approaches to managing these gargantuan models often involve a trade-off between size and accuracy. Researchers typically employ pruning, which deletes less frequent N-grams, or lossy compression, such as randomized hash tables that may return slightly incorrect probabilities. Both methods can degrade the performance of downstream applications.
The standard representation of an N-gram model uses a trie (prefix tree) structure. In a typical implementation, each node in the trie requires multiple pointers to navigate between 1-gram, 2-gram, and higher-order tables.
As shown in Figure 1, these pointers consume a significant portion of the total memory footprint. The goal of this research is to find a lossless way to represent both the model structure and its associated values, aiming for the information-theoretic lower bound of space efficiency while maintaining fast query capabilities.
Methodology: Succinct Representations
The core innovation of this paper is the application and optimization of Succinct Data Structures, specifically LOUDS (Level-Order Unary Degree Sequence).
LOUDS and N-gram Optimization
A standard trie with $M$ nodes typically requires $M$ pointers. In a 64-bit system, this is prohibitively expensive. LOUDS represents the same trie as a bit string of only $2M + 1$ bits. Navigation through the tree is achieved using efficient bitwise operations: rank (counting bits) and select (finding the position of the $i$-th bit).
The authors further optimized LOUDS specifically for N-gram models. Since N-gram tries have a fixed maximum depth $N$, the structure is predictable. By removing redundant bits for the root and leaf nodes (the highest-order N-grams), the bit string is shrunk even further.
Figure 4 illustrates how a standard trie (a) and its LOUDS bit string (b) can be transformed into an optimized N-gram trie (c) with a more compact bit string (d).
Value Compression
Beyond the structure, the authors addressed the storage of word IDs, probabilities, and counts:
- Variable Length Coding (VLC): Instead of fixed-width integers, they used the minimum number of bytes required for each value, with an additional bit vector to mark boundaries.
- Block-wise Compression: To maintain random access, the data is divided into 8KB blocks and compressed using
zlib. An index of block offsets allows the system to decompress only the necessary chunk for a specific query.
Experimental Results
The approach was evaluated on two massive datasets: the English Web 1T 5-gram (LDC) and the Japanese Web 1T 7-gram (GSK).
The results were striking. For the English Web 1T model, which originally occupied 25GB as gzipped text, the optimized LOUDS + block compression reduced the "pointer" overhead to just 1.76 bits per N-gram. The entire model was compressed into a 9.83 GB footprint using 8-bit quantization for probabilities. This size is comparable to state-of-the-art lossy randomized representations, but it provides a deterministic, lossless structure for the N-gram entries themselves.
Conclusion and Future Work
This paper demonstrates that succinct data structures can dramatically reduce the memory requirements of large-scale language models without resorting to pruning or probabilistic approximations. While the "lossless" claim is slightly nuanced due to the use of 8-bit quantization for floating-point values, the structural representation is truly lossless.
Future work could address the computational overhead associated with bit-counting operations and zlib decompression to further improve query latency. Additionally, exploring how succinct structures might handle higher-precision probabilities without significant size increases remains an open area for research.
Summary updated