PrunedCompactLatticeComposer implements an algorithm for pruned composition. More...
Classes | |
struct | ComposedStateInfo |
struct | LatticeStateInfo |
Public Member Functions | |
PrunedCompactLatticeComposer (const ComposeLatticePrunedOptions &opts, const CompactLattice &clat, fst::DeterministicOnDemandFst< fst::StdArc > *det_fst, CompactLattice *composed_clat) | |
void | Compose () |
Private Types | |
typedef std::priority_queue< std::pair< BaseFloat, int32 >, std::vector< std::pair< BaseFloat, int32 > >, std::greater< std::pair< BaseFloat, int32 > > > | QueueType |
Private Member Functions | |
int32 | GetCurrentArcLimit () const |
void | ComputeLatticeStateInfo () |
void | AddFirstState () |
void | ProcessQueueElement (int32 composed_state_to_expand) |
void | ProcessTransition (int32 composed_src_state, int32 arc_index) |
void | RecomputePruningInfo () |
void | GetTopsortedStateList (std::vector< int32 > *composed_states) const |
void | ComputeForwardCosts (const std::vector< int32 > &composed_states) |
void | ComputeBackwardCosts (const std::vector< int32 > &composed_states) |
void | ComputeDeltaBackwardCosts (const std::vector< int32 > &composed_states) |
Private Attributes | |
bool | output_reached_final_ |
float | depth_penalty_ |
const ComposeLatticePrunedOptions & | opts_ |
const CompactLattice & | clat_in_ |
fst::DeterministicOnDemandFst< fst::StdArc > * | det_fst_ |
CompactLattice * | clat_out_ |
int32 | num_arcs_out_ |
std::vector< LatticeStateInfo > | lat_state_info_ |
double | lat_best_cost_ |
double | output_best_cost_ |
BaseFloat | current_cutoff_ |
QueueType | composed_state_queue_ |
std::vector< ComposedStateInfo > | composed_state_info_ |
unordered_map< std::pair< int32, int32 >, int32, PairHasher< int32 > > | pair_to_state_ |
std::set< int32 > | accessed_lat_states_ |
PrunedCompactLatticeComposer implements an algorithm for pruned composition.
It uses a heuristic (like the heuristics used in A*) to estimate the cost to the end of a graph, of the best path that we might get if we expand a particular transition out of a particular state. This enables us to use a priority queue to expand arcs in the composed result in an order roughly from most promising to least promising.
Because some of the quantities used in the heuristic are hard to efficiently keep updated as the composed output is incrementally added to, we periodically recompute these quantities (c.f. RecomputePruningInfo()). In order to prevent this periodic recomputation from dominating the time taken to produce the lattice, we recompute these things on a schedule where, between each computation, we allow the size of the output to grow by a constant factor (default: 1.5). Since the time taken to do the recomputation of quantities used in the heuristic takes time linear in the size of the so-far existing composed output, doing so on this type of schedule will add no more than a constant factor to the runtime.
Definition at line 47 of file compose-lattice-pruned.cc.
|
private |
Definition at line 347 of file compose-lattice-pruned.cc.
PrunedCompactLatticeComposer | ( | const ComposeLatticePrunedOptions & | opts, |
const CompactLattice & | clat, | ||
fst::DeterministicOnDemandFst< fst::StdArc > * | det_fst, | ||
CompactLattice * | composed_clat | ||
) |
Definition at line 621 of file compose-lattice-pruned.cc.
References PrunedCompactLatticeComposer::clat_out_, and PrunedCompactLatticeComposer::depth_penalty_.
|
private |
Definition at line 636 of file compose-lattice-pruned.cc.
References PrunedCompactLatticeComposer::accessed_lat_states_, PrunedCompactLatticeComposer::ComposedStateInfo::arc_delta_cost, PrunedCompactLatticeComposer::ComposedStateInfo::backward_cost, PrunedCompactLatticeComposer::clat_out_, PrunedCompactLatticeComposer::composed_state_info_, PrunedCompactLatticeComposer::composed_state_queue_, PrunedCompactLatticeComposer::ComposedStateInfo::delta_backward_cost, PrunedCompactLatticeComposer::ComposedStateInfo::depth, PrunedCompactLatticeComposer::det_fst_, PrunedCompactLatticeComposer::ComposedStateInfo::forward_cost, KALDI_ASSERT, PrunedCompactLatticeComposer::ComposedStateInfo::lat_state, PrunedCompactLatticeComposer::lat_state_info_, PrunedCompactLatticeComposer::ComposedStateInfo::lm_state, PrunedCompactLatticeComposer::pair_to_state_, PrunedCompactLatticeComposer::ComposedStateInfo::prev_composed_state, PrunedCompactLatticeComposer::ComposedStateInfo::sorted_arc_index, and DeterministicOnDemandFst< Arc >::Start().
Referenced by PrunedCompactLatticeComposer::Compose().
void Compose | ( | ) |
Definition at line 887 of file compose-lattice-pruned.cc.
References PrunedCompactLatticeComposer::AddFirstState(), PrunedCompactLatticeComposer::clat_in_, PrunedCompactLatticeComposer::clat_out_, PrunedCompactLatticeComposer::composed_state_info_, PrunedCompactLatticeComposer::composed_state_queue_, PrunedCompactLatticeComposer::ComputeLatticeStateInfo(), PrunedCompactLatticeComposer::GetCurrentArcLimit(), kaldi::GetVerboseLevel(), KALDI_VLOG, KALDI_WARN, PrunedCompactLatticeComposer::lat_best_cost_, ComposeLatticePrunedOptions::max_arcs, PrunedCompactLatticeComposer::num_arcs_out_, PrunedCompactLatticeComposer::opts_, PrunedCompactLatticeComposer::output_best_cost_, PrunedCompactLatticeComposer::ProcessQueueElement(), PrunedCompactLatticeComposer::RecomputePruningInfo(), kaldi::TopSortCompactLatticeIfNeeded(), and kaldi::TotalNumArcs().
Referenced by kaldi::ComposeCompactLatticePruned().
|
private |
Definition at line 475 of file compose-lattice-pruned.cc.
References PrunedCompactLatticeComposer::LatticeStateInfo::backward_cost, PrunedCompactLatticeComposer::ComposedStateInfo::backward_cost, PrunedCompactLatticeComposer::clat_out_, PrunedCompactLatticeComposer::composed_state_info_, fst::ConvertToCost(), PrunedCompactLatticeComposer::current_cutoff_, PrunedCompactLatticeComposer::lat_best_cost_, ComposeLatticePrunedOptions::lattice_compose_beam, PrunedCompactLatticeComposer::opts_, and PrunedCompactLatticeComposer::output_best_cost_.
Referenced by PrunedCompactLatticeComposer::RecomputePruningInfo().
|
private |
Definition at line 510 of file compose-lattice-pruned.cc.
References PrunedCompactLatticeComposer::ComposedStateInfo::arc_delta_cost, PrunedCompactLatticeComposer::ComposedStateInfo::backward_cost, PrunedCompactLatticeComposer::clat_out_, PrunedCompactLatticeComposer::composed_state_info_, PrunedCompactLatticeComposer::composed_state_queue_, PrunedCompactLatticeComposer::current_cutoff_, PrunedCompactLatticeComposer::ComposedStateInfo::delta_backward_cost, PrunedCompactLatticeComposer::ComposedStateInfo::depth, PrunedCompactLatticeComposer::depth_penalty_, PrunedCompactLatticeComposer::ComposedStateInfo::forward_cost, KALDI_ASSERT, PrunedCompactLatticeComposer::lat_best_cost_, PrunedCompactLatticeComposer::ComposedStateInfo::lat_state, PrunedCompactLatticeComposer::lat_state_info_, and PrunedCompactLatticeComposer::ComposedStateInfo::prev_composed_state.
Referenced by PrunedCompactLatticeComposer::RecomputePruningInfo().
|
private |
Definition at line 428 of file compose-lattice-pruned.cc.
References PrunedCompactLatticeComposer::clat_out_, PrunedCompactLatticeComposer::composed_state_info_, fst::ConvertToCost(), PrunedCompactLatticeComposer::ComposedStateInfo::depth, PrunedCompactLatticeComposer::ComposedStateInfo::forward_cost, KALDI_ASSERT, and PrunedCompactLatticeComposer::ComposedStateInfo::prev_composed_state.
Referenced by PrunedCompactLatticeComposer::RecomputePruningInfo().
|
private |
Definition at line 578 of file compose-lattice-pruned.cc.
References PrunedCompactLatticeComposer::LatticeStateInfo::arc_delta_costs, PrunedCompactLatticeComposer::LatticeStateInfo::backward_cost, PrunedCompactLatticeComposer::clat_in_, fst::ConvertToCost(), KALDI_ASSERT, PrunedCompactLatticeComposer::lat_best_cost_, and PrunedCompactLatticeComposer::lat_state_info_.
Referenced by PrunedCompactLatticeComposer::Compose().
|
private |
Definition at line 399 of file compose-lattice-pruned.cc.
References ComposeLatticePrunedOptions::growth_ratio, ComposeLatticePrunedOptions::initial_num_arcs, KALDI_ASSERT, ComposeLatticePrunedOptions::max_arcs, PrunedCompactLatticeComposer::num_arcs_out_, PrunedCompactLatticeComposer::opts_, and PrunedCompactLatticeComposer::output_best_cost_.
Referenced by PrunedCompactLatticeComposer::Compose().
|
private |
Definition at line 381 of file compose-lattice-pruned.cc.
References PrunedCompactLatticeComposer::accessed_lat_states_, PrunedCompactLatticeComposer::clat_out_, PrunedCompactLatticeComposer::LatticeStateInfo::composed_states, KALDI_ASSERT, and PrunedCompactLatticeComposer::lat_state_info_.
Referenced by PrunedCompactLatticeComposer::RecomputePruningInfo().
|
private |
Definition at line 665 of file compose-lattice-pruned.cc.
References PrunedCompactLatticeComposer::LatticeStateInfo::arc_delta_costs, PrunedCompactLatticeComposer::LatticeStateInfo::backward_cost, PrunedCompactLatticeComposer::clat_in_, PrunedCompactLatticeComposer::clat_out_, PrunedCompactLatticeComposer::composed_state_info_, PrunedCompactLatticeComposer::composed_state_queue_, fst::ConvertToCost(), PrunedCompactLatticeComposer::current_cutoff_, PrunedCompactLatticeComposer::depth_penalty_, PrunedCompactLatticeComposer::det_fst_, DeterministicOnDemandFst< Arc >::Final(), KALDI_ASSERT, PrunedCompactLatticeComposer::lat_best_cost_, PrunedCompactLatticeComposer::lat_state_info_, PrunedCompactLatticeComposer::output_reached_final_, PrunedCompactLatticeComposer::ProcessTransition(), and PrunedCompactLatticeComposer::RecomputePruningInfo().
Referenced by PrunedCompactLatticeComposer::Compose().
Definition at line 754 of file compose-lattice-pruned.cc.
References PrunedCompactLatticeComposer::accessed_lat_states_, PrunedCompactLatticeComposer::ComposedStateInfo::arc_delta_cost, PrunedCompactLatticeComposer::LatticeStateInfo::backward_cost, PrunedCompactLatticeComposer::ComposedStateInfo::backward_cost, PrunedCompactLatticeComposer::clat_in_, PrunedCompactLatticeComposer::clat_out_, PrunedCompactLatticeComposer::composed_state_info_, PrunedCompactLatticeComposer::composed_state_queue_, PrunedCompactLatticeComposer::LatticeStateInfo::composed_states, fst::ConvertToCost(), PrunedCompactLatticeComposer::current_cutoff_, PrunedCompactLatticeComposer::ComposedStateInfo::delta_backward_cost, PrunedCompactLatticeComposer::ComposedStateInfo::depth, PrunedCompactLatticeComposer::depth_penalty_, PrunedCompactLatticeComposer::det_fst_, PrunedCompactLatticeComposer::ComposedStateInfo::forward_cost, DeterministicOnDemandFst< Arc >::GetArc(), KALDI_ASSERT, PrunedCompactLatticeComposer::lat_best_cost_, PrunedCompactLatticeComposer::ComposedStateInfo::lat_state, PrunedCompactLatticeComposer::lat_state_info_, PrunedCompactLatticeComposer::ComposedStateInfo::lm_state, PrunedCompactLatticeComposer::num_arcs_out_, PrunedCompactLatticeComposer::pair_to_state_, PrunedCompactLatticeComposer::ComposedStateInfo::prev_composed_state, PrunedCompactLatticeComposer::ComposedStateInfo::sorted_arc_index, and fst::Times().
Referenced by PrunedCompactLatticeComposer::ProcessQueueElement().
|
private |
Definition at line 420 of file compose-lattice-pruned.cc.
References PrunedCompactLatticeComposer::ComputeBackwardCosts(), PrunedCompactLatticeComposer::ComputeDeltaBackwardCosts(), PrunedCompactLatticeComposer::ComputeForwardCosts(), and PrunedCompactLatticeComposer::GetTopsortedStateList().
Referenced by PrunedCompactLatticeComposer::Compose(), and PrunedCompactLatticeComposer::ProcessQueueElement().
|
private |
Definition at line 377 of file compose-lattice-pruned.cc.
Referenced by PrunedCompactLatticeComposer::AddFirstState(), PrunedCompactLatticeComposer::GetTopsortedStateList(), and PrunedCompactLatticeComposer::ProcessTransition().
|
private |
|
private |
Definition at line 314 of file compose-lattice-pruned.cc.
Referenced by PrunedCompactLatticeComposer::AddFirstState(), PrunedCompactLatticeComposer::Compose(), PrunedCompactLatticeComposer::ComputeBackwardCosts(), PrunedCompactLatticeComposer::ComputeDeltaBackwardCosts(), PrunedCompactLatticeComposer::ComputeForwardCosts(), PrunedCompactLatticeComposer::GetTopsortedStateList(), PrunedCompactLatticeComposer::ProcessQueueElement(), PrunedCompactLatticeComposer::ProcessTransition(), and PrunedCompactLatticeComposer::PrunedCompactLatticeComposer().
|
private |
Definition at line 362 of file compose-lattice-pruned.cc.
Referenced by PrunedCompactLatticeComposer::AddFirstState(), PrunedCompactLatticeComposer::Compose(), PrunedCompactLatticeComposer::ComputeBackwardCosts(), PrunedCompactLatticeComposer::ComputeDeltaBackwardCosts(), PrunedCompactLatticeComposer::ComputeForwardCosts(), PrunedCompactLatticeComposer::ProcessQueueElement(), and PrunedCompactLatticeComposer::ProcessTransition().
|
private |
Definition at line 359 of file compose-lattice-pruned.cc.
Referenced by PrunedCompactLatticeComposer::AddFirstState(), PrunedCompactLatticeComposer::Compose(), PrunedCompactLatticeComposer::ComputeDeltaBackwardCosts(), PrunedCompactLatticeComposer::ProcessQueueElement(), and PrunedCompactLatticeComposer::ProcessTransition().
|
private |
|
private |
Definition at line 310 of file compose-lattice-pruned.cc.
Referenced by PrunedCompactLatticeComposer::ComputeDeltaBackwardCosts(), PrunedCompactLatticeComposer::ProcessQueueElement(), PrunedCompactLatticeComposer::ProcessTransition(), and PrunedCompactLatticeComposer::PrunedCompactLatticeComposer().
|
private |
Definition at line 313 of file compose-lattice-pruned.cc.
Referenced by PrunedCompactLatticeComposer::AddFirstState(), PrunedCompactLatticeComposer::ProcessQueueElement(), and PrunedCompactLatticeComposer::ProcessTransition().
|
private |
Definition at line 325 of file compose-lattice-pruned.cc.
Referenced by PrunedCompactLatticeComposer::Compose(), PrunedCompactLatticeComposer::ComputeBackwardCosts(), PrunedCompactLatticeComposer::ComputeDeltaBackwardCosts(), PrunedCompactLatticeComposer::ComputeLatticeStateInfo(), PrunedCompactLatticeComposer::ProcessQueueElement(), and PrunedCompactLatticeComposer::ProcessTransition().
|
private |
Definition at line 320 of file compose-lattice-pruned.cc.
Referenced by PrunedCompactLatticeComposer::AddFirstState(), PrunedCompactLatticeComposer::ComputeDeltaBackwardCosts(), PrunedCompactLatticeComposer::ComputeLatticeStateInfo(), PrunedCompactLatticeComposer::GetTopsortedStateList(), PrunedCompactLatticeComposer::ProcessQueueElement(), and PrunedCompactLatticeComposer::ProcessTransition().
|
private |
Definition at line 318 of file compose-lattice-pruned.cc.
Referenced by PrunedCompactLatticeComposer::Compose(), PrunedCompactLatticeComposer::GetCurrentArcLimit(), and PrunedCompactLatticeComposer::ProcessTransition().
|
private |
Definition at line 311 of file compose-lattice-pruned.cc.
Referenced by PrunedCompactLatticeComposer::Compose(), PrunedCompactLatticeComposer::ComputeBackwardCosts(), and PrunedCompactLatticeComposer::GetCurrentArcLimit().
|
private |
Definition at line 331 of file compose-lattice-pruned.cc.
Referenced by PrunedCompactLatticeComposer::Compose(), PrunedCompactLatticeComposer::ComputeBackwardCosts(), and PrunedCompactLatticeComposer::GetCurrentArcLimit().
|
private |
Definition at line 298 of file compose-lattice-pruned.cc.
Referenced by PrunedCompactLatticeComposer::ProcessQueueElement().
|
private |
Definition at line 368 of file compose-lattice-pruned.cc.
Referenced by PrunedCompactLatticeComposer::AddFirstState(), and PrunedCompactLatticeComposer::ProcessTransition().