Algorithm Search⌘K

Techniqueadvanced

HCLG decoding graph

Also called WFST decoding graph.

Compose HMM, context, lexicon and grammar transducers into one optimized WFST that maps HMM states to words for search.

The HCLG graph is the search network of a WFST speech recognizer. It is one weighted transducer, built offline as the composition H∘C∘L∘GH \circ C \circ L \circ G of four models. GG is the grammar or n-gram language model, an acceptor over words. LL is the pronunciation lexicon, which maps phone sequences to words. CC maps context-dependent phones, such as triphones, to phones. HH maps HMM states to context-dependent phones. The result maps sequences of HMM states to word sequences, with the language model cost and the transition costs on its arcs. Built naively, the composition is far too large and too nondeterministic to search. The construction therefore determinizes and minimizes after each composition, and can push the weights toward the start. Auxiliary symbols #1, #2, ... make the lexicon determinizable. A decoder then runs time-synchronous beam search or token passing on the graph, with acoustic scores from the HMM states.

In plain words

A recognizer needs four kinds of knowledge: which HMM states make up each sound, how sounds change with their neighbors, how each word is pronounced, and which word sequences are likely. Each kind can be written as a machine that reads one kind of symbol and writes another.

If you plug the four machines into each other ahead of time, you get one big machine that reads HMM states and writes words. The decoder then needs only that one machine. To keep it small, words that start with the same sounds share the start of their path, and words that end alike share the end. The language model costs are moved as early as possible, so that the decoder can drop bad paths soon.

When it applies

  • The models can be written as weighted finite-state machines: an n-gram or other finite-state language model, a lexicon with a finite list of pronunciations, a context model of finite width, and HMMs.
  • The graph can be built offline, and memory allows it. For very large language models, a smaller GG is used in the graph and the large one later, by lattice rescoring or by composition on the fly.
  • The costs live in the tropical semiring: the cost of a path is the sum of its arc costs, the costs are negative log probabilities, and the decoder takes the minimum. Determinization and minimization then keep the best cost of every word sequence.

The template

The cost convention is used throughout: a cost is −log⁡p-\log p, and a smaller cost is better.

  1. Build GG. An n-gram model becomes a weighted acceptor with one state per history. The back-off arcs of a Katz or similar model are ε\varepsilon arcs. Kaldi replaces their ε\varepsilon by the symbol #0, so that they are not removed as epsilons during determinization.
  2. Build LL with disambiguation symbols. LL reads phones and writes words, with one path per pronunciation and a loop back to the start after each word. Determinization needs every input string to have one output, and it needs the output to be known after a bounded delay. Two cases break this. Homophones, such as "red" and "read" in the past tense, have the same phone string with two outputs. A pronunciation that is a prefix of another one leaves the decoder unable to tell where the word ends. So each such pronunciation gets a distinct symbol #1, #2, ... at its end. LL also passes #0 through, with a self-loop.
  3. Combine LL and GG: LG=min⁡(det⁡(L∘G))LG = \min(\det(L \circ G)). After determinization, the words that start with the same phones share one path until the phones differ, so the lexicon becomes a prefix tree with the language model costs pushed toward the root. Minimization then shares the common suffixes.
  4. Add the context: CLG=min⁡(det⁡(C∘LG))CLG = \min(\det(C \circ LG)). CC passes the disambiguation symbols through.
  5. Add the HMMs: compose with H′H', which is HH without the self-loops of the HMM states, determinize, replace the disambiguation symbols by ε\varepsilon, minimize, and add the self-loops back. Kaldi writes this as HCLG=asl(min⁡(rds(det⁡(H′∘min⁡(det⁡(C∘min⁡(det⁡(L∘G))))))))HCLG = \mathrm{asl}(\min(\mathrm{rds}(\det(H' \circ \min(\det(C \circ \min(\det(L \circ G)))))))).
  6. Push the weights. Mohri, Pereira and Riley 2002 push the weights of the network so that costs appear as early as possible, which helps pruning. Kaldi does not push. Instead it uses operations that keep the graph stochastic if GG was stochastic, so that the costs are already well placed.

Why it is correct. Composition gives exactly the relation H∘C∘L∘GH \circ C \circ L \circ G: a sequence of HMM states maps to a word sequence with the cost of the best way to explain it. Determinization and minimization in the tropical semiring keep, for every input string, its output and its smallest cost. So the optimized graph gives the same best cost to every pair of an HMM state sequence and a word sequence as the plain composition. The disambiguation symbols change the input alphabet, and removing them in step 5 maps the graph back to the original input. After that step the graph is no longer guaranteed to be deterministic, but it stays small.

Cost. Each composition takes time proportional to the number of states and arcs that it reaches, which is at most the product of the sizes of its arguments. Determinization can make a machine exponentially larger in the worst case (determinization blowup), but on speech models it usually makes the graph smaller, because it removes redundant paths. Minimization runs in O(elog⁡n)O(e \log n) time on a deterministic machine with nn states and ee arcs, as in Hopcroft's algorithm.

Classic examples

A tiny L∘GL \circ G. The lexicon has four words: "red" (r eh d), "read" (r eh d), "rat" (r ae t) and "at" (ae t). The grammar GG is a word loop with the unigram costs 1.2, 1.6, 0.9 and 2.3. In L∘GL \circ G each word is a path from the start back to the start, with the word and its cost on the first arc.

  • Without disambiguation symbols, L∘GL \circ G has 8 states and 11 arcs. The phone string "r eh d" has two outputs, so the transducer is not functional and has no deterministic equivalent. Determinization never ends: in a run of the subset construction, the queue passed 200 states and kept growing, because the pending output "red" or "read" can never be written.
  • With #1 after "red" and #2 after "read", L∘GL \circ G has 10 states and 13 arcs. Determinization gives 6 states and 9 arcs:
arc input : output / cost
start to A r : ε / 0.9
A to B eh : ε / 0.3
B to C d : ε / 0
C to start #1 : red / 0
C to start #2 : read / 0.4
A to D ae : rat / 0
D to start t : ε / 0
start to E ae : at / 2.3
E to start t : ε / 0

The three words that start with "r" share one arc, and its cost is the smallest of their costs, 0.9. After "r eh", the cost min⁡(1.2,1.6)−0.9=0.3\min(1.2, 1.6) - 0.9 = 0.3 is paid, and "read" pays the last 0.4 at #2. Every word keeps its cost: "red" is 0.9+0.3+0+0=1.20.9 + 0.3 + 0 + 0 = 1.2 and "read" is 0.9+0.3+0.4=1.60.9 + 0.3 + 0.4 = 1.6. The output "rat" moves to the arc "ae" from A, the first point where the word is certain. Minimization then merges the states D and E, which both have one arc "t : ε / 0" back to the start, and the graph has 5 states and 8 arcs.

Large-vocabulary graphs. In a full system, GG is a pruned trigram or 4-gram model and CC uses triphones whose HMM states are tied by a decision tree. The determinized lexicon gives the same sharing as the prefix tree of a dynamic decoder, but here it is built once, together with the language model costs.

Variations

  • Order of the steps. Mohri, Pereira and Riley 2002 determinize after each composition, so that every intermediate machine stays small. Composing all four models first and then determinizing is correct but uses much more memory.
  • Dynamic composition. Some decoders keep HCLHCL and GG apart and compose them during the search. This allows a large GG and a change of language model without a rebuild.
  • Weight pushing or stochasticity. Pushing in the log semiring makes the graph stochastic, which helps beam pruning. Kaldi aims for the same property by keeping each step stochastic.
  • Graphs for end-to-end models. CTC models use a token topology TT in place of HH and CC, and the graph is T∘L∘GT \circ L \circ G or T∘GT \circ G with word pieces.
  • Lattice generation. Decoders that run on HCLG write state-level lattices that are then determinized to word lattices (word lattice).

Pitfalls

  • Missing disambiguation symbols. Without them, determinization of L∘GL \circ G does not terminate, or it runs out of memory, as in the example.
  • Back-off arcs as true epsilons. A determinization that removes epsilons would remove the back-off arcs of GG too, and GG would then no longer be determinizable in a useful size. Use #0.
  • Forgetting to remove the symbols. The graph that the decoder uses must have no #k on its input, or the decoder must treat them as ε\varepsilon.
  • The log semiring in determinization. Determinization in the log semiring adds the probabilities of paths with the same input and output. That is a different model from the Viterbi decoder, which takes the best path. Use the tropical semiring for the graph, unless you want sums.
  • Size. The graph grows with the number of n-grams in GG times the number of context-dependent variants of each phone. Prune GG first, or compose on the fly.
  • Scales. The acoustic scale and the language model weight are applied in the decoder. If the graph is built with scaled costs, they must not be applied a second time.

Exercises

  1. Show that without #1 and #2, the transducer L∘GL \circ G of the example maps the input "r eh d" to two outputs, and explain why the subset construction for transducers then creates a new state each time "r eh d" is read again.
  2. Add the word "re" (r eh) to the example lexicon. Which pronunciations now need a disambiguation symbol, and why?
  3. Check that every word in the determinized table keeps its cost from GG. Then compute, for each state, the smallest cost of a path back to the start, and show that it is 0 for every state except the start, where it is 0.9. What does weight pushing change in the table?
  4. Explain why the self-loops of the HMM states are left out of HH during the construction and added at the end.
  5. Show that replacing the disambiguation symbols by ε\varepsilon does not change the relation between HMM state sequences and word sequences, and give a small case where the result is no longer deterministic.

References

  1. Mehryar Mohri, Fernando Pereira and Michael Riley, Weighted finite-state transducers in speech recognition, Computer Speech and Language 16(1), 2002, pages 69 to 88, the construction of the recognition transducer from the HMM, context, lexicon and grammar transducers by composition, determinization, minimization and weight pushing, with auxiliary symbols
  2. Kaldi documentation, Decoding graph construction in Kaldi, the formula HCLG = asl(min(rds(det(H' o min(det(C o min(det(L o G)))))))), the disambiguation symbols
  3. Daniel Povey, Arnab Ghoshal, Gilles Boulianne and others, The Kaldi speech recognition toolkit, IEEE Workshop on Automatic Speech Recognition and Understanding (ASRU), 2011, the overview of the toolkit and its decoding with weighted finite-state transducers built with OpenFst
  4. Mehryar Mohri, Finite-state transducers in language and speech processing, Computational Linguistics 23(2), 1997, pages 269 to 311, the determinization of transducers and weighted automata, and the condition under which it terminates

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • three classic examples