An Efficient Language Model Using Double-Array Structures

Makoto Yasuhara, Toru Tanaka, Jun-ya Norimatsu, Mikio YamamotoEMNLP 2013

Introduction

N-gram language models remain a cornerstone of modern natural language processing, powering critical systems in machine translation and speech recognition. However, as training corpora expand into the billions of words, the resulting models often balloon to hundreds of gigabytes, creating a significant bottleneck for memory-constrained environments. The primary challenge lies in the classic trade-off between compactness and query speed. While tools like SRILM prioritize speed at the cost of memory, and KenLM offers compact trie variants that can be slower to query, there is a clear need for a data structure that optimizes both dimensions simultaneously. This paper introduces DALM (Double-Array Language Model), which leverages double-array structures and clever space-filling optimizations to achieve state-of-the-art efficiency.

The Double-Array Language Model (DALM)

Core Structure: Double-Arrays

The fundamental innovation of DALM is the adaptation of the double-array structure for language modeling. Traditionally used for fast dictionary lookups, a double-array represents a trie using two parallel arrays: BASE and CHECK.

The transition mechanism in a double-array structure, mapping trie nodes to array indices.

As illustrated in the figure above, a transition from node $n_s$ to $n_{next}$ via word $w$ is calculated as $next = BASE[s] + WORDID(w)$. The CHECK array ensures the validity of the transition by verifying that $CHECK[next] = s$. This structure allows for $O(1)$ or $O(L)$ lookup time (where $L$ is the N-gram length), providing the speed of a hash table with the structural benefits of a trie.

Backwards Suffix Trees

Instead of a standard forward-looking trie, DALM utilizes a "backwards suffix tree." In this configuration, N-grams are stored in reverse order (e.g., "I eat fish" is stored as "fish" $\leftarrow$ "eat" $\leftarrow$ "I"). This is particularly advantageous for N-gram models because of the "backoff" mechanism. When a specific N-gram is not found, the model must back off to a shorter context (e.g., from a 4-gram to a 3-gram). In a backwards tree, backing off simply involves moving one step up the current branch toward the root, making these frequent calculations extremely efficient.

Space Optimization via Embedding

Double-arrays are notoriously sparse, often containing "vacant" slots due to the constraints of the transition function. DALM turns this inefficiency into an advantage through "embedding." The researchers propose hiding N-gram probabilities and backoff weights (BOW) directly within these unused spaces in the BASE and CHECK arrays.

Mapping of N-gram components (probabilities and backoff weights) to the double-array structure.

By treating these "holes" as free storage for model parameters, the authors reduced the overall model size by nearly 40% without introducing any additional query overhead. As shown in the figure above, the values for $BOW(w_2)$ and $P(w_3|w_1 w_2)$ are logically mapped to the indices corresponding to their respective N-gram nodes.

Frequency-Based Ordering and the Division Method

To further optimize the structure, DALM assigns word IDs based on unigram frequency. By giving the most frequent words smaller IDs, the "active" parts of the trie are clustered together, increasing the density of the double-array and improving cache locality during queries.

Additionally, because building a massive double-array is computationally expensive ($O(MN^2)$), the authors implemented the Division Method. This approach divides a large trie into several smaller, independent tries that can be constructed in parallel and queried as a single logical unit, significantly reducing the time required to build models from massive datasets.

Evaluation and Results

The researchers evaluated DALM against industry standards, including SRILM and KenLM, using Japanese patent data (up to 5 billion words).

  • Query Speed: On the 5-billion-word model, DALM achieved approximately 953,186 queries/sec, outperforming both the "Probing" (913k) and "Trie" (635k) variants of KenLM.
  • Memory Footprint: For a 100-million-word model, DALM (498 MB) was significantly more compact than SRILM (1,194 MB) and KenLM Probing (665 MB). While the KenLM Trie remained slightly smaller (340 MB), DALM provided a superior balance of size and speed.
  • Synergy: The results indicated that the combination of Embedding and Ordering optimizations yielded the most efficient model, maximizing query throughput while minimizing memory usage.

Conclusion

DALM demonstrates that the inherent sparseness of double-array structures can be effectively harnessed to create high-performance language models. By combining backwards suffix trees with clever data embedding and frequency-based clustering, the authors produced a model that is both faster and more memory-efficient than many existing solutions. While construction time remains a challenge for the largest models, the query performance and compact footprint make DALM a compelling choice for high-volume NLP applications.

Summary updated

BibTeX
@inproceedings{yasuhara2013efficient,
  author = {Makoto Yasuhara and Toru Tanaka and Jun-ya Norimatsu and Mikio Yamamoto},
  title = {{An Efficient Language Model Using Double-Array Structures}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2013},
  doi = {10.18653/v1/d13-1023},
}
Figure