Abstract
We present a method for exact optimization and sampling from high order Hidden Markov Models (HMMs), which are generally handled by approximation techniques. Motivated by adaptive rejection sampling and heuristic search, we propose a strategy based on sequentially refining a lower-order language model that is an upper bound on the true model we wish to decode and sample from. This allows us to build tractable variable-order HMMs. The ARPA format for language models is extended to enable an efficient use of the max-backoff quantities required to compute the upper bound. We evaluate our approach on two problems: a SMS-retrieval task and a POS tagging experiment using 5-gram models. Results show that the same approach can be used for exact optimization and sampling, while explicitly constructing only a fraction of the total implicit state-space.
Introduction
High-order Hidden Markov Models (HMMs) are essential for capturing long-range dependencies in natural language, yet they are notoriously difficult to use for exact inference. As the order $n$ of the model increases, the state space grows exponentially ($O(N^n)$), where $N$ is the vocabulary size. For a 5-gram model, this space can exceed $10^{15}$ states, forcing a reliance on approximate methods like Beam Search or MCMC. While these approximations are often effective, they lack the mathematical guarantees of exact decoding and sampling. This paper introduces a method to achieve exact results while exploring only a tiny fraction of the theoretical state space.
Methodology: Sequential Refinement via Adaptive Rejection Sampling
The core of the proposed approach is a unified framework for exact optimization and sampling based on Adaptive Rejection Sampling (ARS). Instead of constructing the full high-order model ($p$), the process begins with an "optimistic" proposal model ($q$)—typically a lower-order model like a unigram—that serves as an upper bound on the true distribution.
The algorithm proceeds through an iterative refinement loop:
- Sample/Optimize: Draw a sample or find the best path from the current proposal model $q$ using standard dynamic programming.
- Acceptance Test: Calculate an acceptance probability. If the sample is accepted, it is guaranteed to be an exact result from the true model $p$.
- Refine: If rejected, the proposal model $q$ is refined. The algorithm identifies the specific "culprit" states responsible for the rejection and increases their n-gram order locally.
This refinement process is represented using a Weighted Finite State Automaton (WFSA). As shown in Figure 2, the automaton grows from a simple structure into a variable-order HMM, expanding only the parts of the state space necessary for the specific input. To facilitate efficient upper-bound calculations, the authors introduced MAX-ARPA, an extension of the standard ARPA format that includes pre-calculated "max-backoff" weights, allowing the system to quickly determine the maximum possible probability an n-gram could have if its context were "forgotten."
Experimental Evaluation
The method was evaluated on two distinct tasks: SMS-retrieval, which involves recovering original sentences from noisy numeric keypad input (Europarl corpus), and Part-of-Speech (POS) tagging using the WSJ Penn Treebank.
Key Results and Efficiency
The primary advantage of this approach is its computational efficiency. In the POS tagging experiment, the algorithm achieved a tagging accuracy of 95.94% with a 5-gram model. Remarkably, for a 10-word sentence, the exact optimum was found by constructing a model with only 9,008 n-grams—a negligible fraction of the theoretical $3.0 \times 10^{15}$ states.
As illustrated in Figure 4, the number of states constructed grows linearly with the input length. Furthermore, the time complexity scales linearly with the n-gram order, whereas standard Viterbi decoding scales exponentially. This efficiency allowed the researchers to test models up to 9-grams, which would be impossible with traditional exact methods due to memory constraints.
Conclusion
By leveraging the sparsity of relevant states in high-order models, this research demonstrates that exact inference is not only possible but practical. The sequential refinement strategy provides a robust alternative to approximate search and sampling, offering independent samples and guaranteed optimality while maintaining a manageable computational footprint. Future work may extend this "optimistic" refinement approach to more complex linguistic structures, such as the intersection of HMMs and Context-Free Grammars.
Summary updated