Package sphinx :: Module lattice :: Class Dag
[hide private]
[frames] | no frames]

Class Dag

source code

object --+    
         |    
      list --+
             |
            Dag

Directed acyclic graph representation of a phone/word lattice.

Nested Classes [hide private]
  Node
Node in a DAG representation of a phone/word lattice.
Instance Methods [hide private]
 
__init__(self, sphinx_file=None, htk_file=None, frate=100)
Construct a DAG, optionally loading contents from a file.
source code
 
htk2dag(self, htkfile)
Read an HTK-format lattice file to populate a DAG.
source code
 
sphinx2dag(self, s3file)
Read a Sphinx-III format lattice file to populate a DAG.
source code
(Dag.Node, int, int, int)
edges(self, node, lm=None)
Return a generator for the set of edges exiting node.
source code
int
n_nodes(self)
Return the number of nodes in the DAG
source code
int
n_edges(self)
Return the number of edges in the DAG
source code
generator(Dag.Node)
nodes(self)
Return a generator over all the nodes in the DAG, in time order
source code
generator(Dag.Node)
reverse_nodes(self)
Return a generator over all the nodes in the DAG, in reverse time order
source code
generator((int,object,Dag.Node))
all_edges(self)
Return a generator over all the edges in the DAG, in time order
source code
Dag.Node
bestpath(self, lm=None, lw=7.5, ip=0.7, start=None, end=None)
Find best path through lattice using Dijkstra's algorithm.
source code
 
bypass_fillers(self)
Bypass filler nodes in the lattice.
source code
(int, list(string, string))
minimum_error(self, hyp, start=None)
Find the minimum word error rate path through lattice, returning the number of errors and an alignment.
source code
list of Dag.Node
backtrace(self, end=None)
Return a backtrace from an optional end node after bestpath.
source code
 
find_preds(self)
Find predecessor nodes for each node in the lattice and store them in its 'prev' field.
source code
 
traverse_depth(self, start=None)
Depth-first traversal of DAG nodes
source code
 
traverse_breadth(self, start=None)
Breadth-first traversal of DAG nodes
source code
 
reverse_breadth(self, end=None)
Breadth-first reverse traversal of DAG nodes
source code
 
remove_unreachable(self)
Remove unreachable nodes and dangling edges.
source code
 
forward(self, lm=None, lw=7.5, ip=0.7)
Compute forward variable for all arcs in the lattice.
source code
 
backward(self, lm=None, lw=7.5, ip=0.7)
Compute backward variable for all arcs in the lattice.
source code
 
posterior(self, lm=None, lw=7.5, ip=0.7)
Compute arc posterior probabilities.
source code

Inherited from list: __add__, __contains__, __delitem__, __delslice__, __eq__, __ge__, __getattribute__, __getitem__, __getslice__, __gt__, __hash__, __iadd__, __imul__, __iter__, __le__, __len__, __lt__, __mul__, __ne__, __new__, __repr__, __reversed__, __rmul__, __setitem__, __setslice__, append, count, extend, index, insert, pop, remove, reverse, sort

Inherited from object: __delattr__, __reduce__, __reduce_ex__, __setattr__, __str__

Class Variables [hide private]
  fieldre = re.compile(r'(\S+)=(?:"((?:[^\\"]+|\\.)*)"|(\S+))')
  headre = re.compile(r'# (-\S+) (\S+)')
Properties [hide private]
  end
  frate
  header
  start

Inherited from object: __class__

Method Details [hide private]

__init__(self, sphinx_file=None, htk_file=None, frate=100)
(Constructor)

source code 
Construct a DAG, optionally loading contents from a file.
Parameters:
  • frate (int) - Number of frames per second. This is important when loading HTK word graphs since times in them are specified in decimal. The default is probably okay.
  • sphinx_file (string) - Sphinx-III format word lattice file to load (optionally).
  • htk_file (string) - HTK SLF format word lattice file to load (optionally).
Returns:
new list

Overrides: list.__init__

edges(self, node, lm=None)

source code 
Return a generator for the set of edges exiting node.
Parameters:
  • node (Dag.Node) - Node whose edges to iterate over.
  • lm (sphinx.arpalm.ArpaLM (or equivalent)) - Language model to use for scoring edges.
Returns: (Dag.Node, int, int, int)
Tuple of (successor, exit-frame, acoustic-score, language-score)

n_nodes(self)

source code 
Return the number of nodes in the DAG
Returns: int
Number of nodes in the DAG

n_edges(self)

source code 
Return the number of edges in the DAG
Returns: int
Number of edges in the DAG

nodes(self)

source code 
Return a generator over all the nodes in the DAG, in time order
Returns: generator(Dag.Node)
Generator over all nodes in the DAG, in time order

reverse_nodes(self)

source code 
Return a generator over all the nodes in the DAG, in reverse time order
Returns: generator(Dag.Node)
Generator over all nodes in the DAG, in reverse time order

all_edges(self)

source code 
Return a generator over all the edges in the DAG, in time order
Returns: generator((int,object,Dag.Node))
Generator over all edges in the DAG, in time order

bestpath(self, lm=None, lw=7.5, ip=0.7, start=None, end=None)

source code 
Find best path through lattice using Dijkstra's algorithm.
Parameters:
  • lm (sphinx.arpalm.ArpaLM (or equivalent)) - Language model to use in search
  • lw (float) - Language model weight
  • ip (float) - Word insertion penalty
  • start (Dag.Node) - Node to start search from
  • end (Dag.Node) - Node to end search at
Returns: Dag.Node
Final node in search (same as end)

minimum_error(self, hyp, start=None)

source code 
Find the minimum word error rate path through lattice, returning the number of errors and an alignment.
Returns: (int, list(string, string))
Tuple of (error-count, alignment of (hyp, ref) pairs)

backtrace(self, end=None)

source code 
Return a backtrace from an optional end node after bestpath.
Parameters:
  • end (Dag.Node) - End node to backtrace from (default is final node in DAG)
Returns: list of Dag.Node
Best path through lattice from start to end.

forward(self, lm=None, lw=7.5, ip=0.7)

source code 
Compute forward variable for all arcs in the lattice.
Parameters:
  • lm (sphinx.arpalm.ArpaLM (or equivalent)) - Language model to use in computation
  • lw (float) - Language model weight
  • ip (float) - Word insertion penalty

backward(self, lm=None, lw=7.5, ip=0.7)

source code 
Compute backward variable for all arcs in the lattice.
Parameters:
  • lm (sphinx.arpalm.ArpaLM (or equivalent)) - Language model to use in computation
  • lw (float) - Language model weight
  • ip (float) - Word insertion penalty

posterior(self, lm=None, lw=7.5, ip=0.7)

source code 
Compute arc posterior probabilities.
Parameters:
  • lm (sphinx.arpalm.ArpaLM (or equivalent)) - Language model to use in computation
  • lw (float) - Language model weight
  • ip (float) - Word insertion penalty