@@ -126,7 +126,7 @@ class PrunedCompactLatticeComposer {
126126
127127 // 'arc_delta_costs' is an array, one for each arc (and the final-prob, if
128128 // present), showing how much the cost to the final-state for the best path
129- // starting in this state and exiting through each arc (or final-state ),
129+ // starting in this state and exiting through each arc (or final-prob ),
130130 // differs from 'backward_cost'. Specifically, it contains pairs
131131 // (delta_cost, arc_index), where delta_cost >= 0 and arc_index is
132132 // either the index into this state's array of arcs (for arcs), or -1
@@ -201,8 +201,8 @@ class PrunedCompactLatticeComposer {
201201 // - If backward_cost is finite (this state in the composed result can
202202 // reach the final state via currently expanded states), then
203203 // delta_backward_cost is this->backward_cost minus
204- // lat_state_info_[lat_state].backward_cost. (It will mostly,
205- // not always, be > = 0, reflecting that the new LM is better than
204+ // lat_state_info_[lat_state].backward_cost. (It will mostly, but
205+ // not always, be < = 0, reflecting that the new LM is better than
206206 // the old LM).
207207 // - On the other hand, if backward_cost is infinite: delta_backward_cost
208208 // is set to the delta_backward_cost of the previous state on the best
@@ -216,7 +216,10 @@ class PrunedCompactLatticeComposer {
216216 // - For other states, delta_backward_cost will be unchanged since
217217 // RecomputePruningInfo() was last called.
218218 // The above rules may make the delta_backward_cost a less accurate, but
219- // still probably reasonable, heuristic.
219+ // still probably reasonable, heuristic. What it is a heuristic for,
220+ // is: if we were to successfully reach an end-state of the composed output
221+ // from this state, what would be the resulting backward_cost
222+ // minus lat_state_info_[lat_state].backward_cost.
220223 BaseFloat delta_backward_cost;
221224
222225 // 'prev_composed_state' is the previous state on the best path from
@@ -226,21 +229,26 @@ class PrunedCompactLatticeComposer {
226229 // used.
227230 int32 prev_composed_state;
228231
229- // 'sorted_arc_index' is an index into the 'arc_delta_costs' array of the
230- // LatticeStateInfo corresponding to 'lat_state'. It corresponds to the
231- // next arc (or final-prob) out of the input lattice that we have yet to
232- // expand in the composition; or -1 if we have expanded all of them. When
233- // we first reach a composed state, 'sorted_arc_index' will be zero; then it
234- // will increase one at a time as we expand arcs until either the
235- // composition terminates or we have expanded all the arcs and it becomes
236- // -1.
232+ // 'sorted_arc_index' is an index into the 'arc_delta_costs' array which is
233+ // a member of the LatticeStateInfo object corresponding to the lattice
234+ // state 'lat_state'. It corresponds to the next arc (or final-prob) out of
235+ // the input lattice that we have yet to expand in the composition; or -1 if
236+ // we have expanded all of them. When we first reach a composed state,
237+ // 'sorted_arc_index' will be zero; then it will increase one at a time as
238+ // we expand arcs until either the composition terminates or we have
239+ // expanded all the arcs and it becomes -1.
237240 int32 sorted_arc_index;
238241
239242 // 'arc_delta_cost' is a derived quantity that we store here for easier
240243 // access. Suppose this_lat_info is lat_state_info_[lat_state]; then
241244 // if sorted_arc_index >= 0, then:
242245 // arc_delta_cost == this_lat_info.arc_delta_costs[sorted_arc_index].first
243246 // else: arc_delta_cost == +infinity.
247+ //
248+ // what 'arc_delta_cost' represents (or is a heuristic for), is the expected
249+ // cost of a path to the final-state leaving through the arc we're about to
250+ // expand, minus the expected cost of any path to the final-state starting
251+ // from this state.
244252 BaseFloat arc_delta_cost;
245253
246254 // view 'expected_cost_offset' a phantom field of this struct, that has
@@ -249,16 +257,20 @@ class PrunedCompactLatticeComposer {
249257 //
250258 // 'expected_cost_offset' is a derived quantity that reflects the expected
251259 // cost (according to our heuristic) of the best path we might encounter
252- // when expanding the next previously unseen arc (or final-prob), corresponding
253- // to 'sorted_arc_index'.
260+ // when expanding the next previously unseen arc (or final-prob),
261+ // corresponding to 'sorted_arc_index'. (This is the expected cost of a
262+ // successful path, from the beginning to the end of the lattice, but
263+ // constrained to be a path that contains the arc we're about to expand).
264+ //
254265 // The 'offset' part is about subtracting the best cost of the lattice, so we
255266 // can cast to float without too much loss of accuracy:
256267 // expected_cost_offset = expected_cost - lat_best_cost_.
257268 //
258269 // We define expected_cost_offset by defining the 'expected_cost' part;
259270 // for clarity:
260271 // First, let lat_backward_cost equal the backward_cost of the LatticeStateInfo
261- // corresponding to 'lat_state'. Then:
272+ // corresponding to 'lat_state', i.e.
273+ // lat_backward_cost = lat_state_info_[lat_state].backward_cost. Then:
262274 // expected_cost = forward_cost + lat_backward_cost +
263275 // delta_backward_cost + arc_delta_cost.
264276 // expected_cost_offset will always equal the above minus lat_best_cost_.
@@ -298,7 +310,7 @@ class PrunedCompactLatticeComposer {
298310
299311 // current_cutoff_ is a value used in deciding which composed states
300312 // need to be included in the queue. Each time RecomputePruningInfo()
301- // called, it is set to
313+ // called, current_cutoff_ is set to
302314 // (output_best_cost_ - lat_best_cost_ + opts_.lattice_compose_beam).
303315 // It will be +infinity if the output lattice doesn't yet have any
304316 // successful paths. It decreases with time. You can compare the
@@ -755,8 +767,9 @@ void PrunedCompactLatticeComposer::ProcessTransition(int32 src_composed_state,
755767 std::pair<MapType::iterator, bool > ret =
756768 pair_to_state_.insert (value);
757769 if (ret.second ) {
758- // Successfully inserted. Most of the rest of this block deals with the
759- // consequences of adding a new state.
770+ // Successfully inserted: this dest-state did not already exist. Most of
771+ // the rest of this block deals with the consequences of adding a new
772+ // state.
760773 int32 ans = clat_out_->AddState ();
761774 KALDI_ASSERT (ans == new_composed_state);
762775 dest_composed_state = new_composed_state;
@@ -777,7 +790,8 @@ void PrunedCompactLatticeComposer::ProcessTransition(int32 src_composed_state,
777790 dest_info->delta_backward_cost =
778791 src_info->delta_backward_cost ;
779792 // The 'prev_composed_state' field will not be read again until after it's
780- // overwritten; we set it as below only for debugging purposes.
793+ // overwritten; we set it as below only for debugging purposes (the
794+ // negation is also for debugging purposes).
781795 dest_info->prev_composed_state = -src_composed_state;
782796 dest_info->sorted_arc_index = 0 ;
783797 dest_info->arc_delta_cost = 0.0 ;
@@ -791,8 +805,11 @@ void PrunedCompactLatticeComposer::ProcessTransition(int32 src_composed_state,
791805 dest_info->delta_backward_cost -
792806 lat_best_cost_);
793807 if (expected_cost_offset < current_cutoff_) {
794- composed_state_queue_.push (std::pair<BaseFloat, int32>(
795- expected_cost_offset, dest_composed_state));
808+ // the following call should be equivalent to
809+ // composed_state_queue_.push(std::pair<BaseFloat,int32>(...)) with
810+ // the same pair of args.
811+ composed_state_queue_.emplace (expected_cost_offset,
812+ dest_composed_state);
796813 }
797814 } else { // the destination composed state already existed.
798815 dest_composed_state = ret.first ->second ;
0 commit comments