Skip to content

Commit 0e284f3

Browse files
committed
Update to ComposeCompactLatticeDeterministic to fix a bug regarding the olabel (which shouldn't matter in our normal use-cases), and make final-probs application more efficient.
1 parent a9937ae commit 0e284f3

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

src/lat/lattice-functions.cc

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -459,13 +459,13 @@ double ComputeLatticeAlphasAndBetas(const LatticeType &lat,
459459
}
460460

461461
// instantiate the template for Lattice and CompactLattice
462-
template
462+
template
463463
double ComputeLatticeAlphasAndBetas(const Lattice &lat,
464464
bool viterbi,
465465
vector<double> *alpha,
466466
vector<double> *beta);
467467

468-
template
468+
template
469469
double ComputeLatticeAlphasAndBetas(const CompactLattice &lat,
470470
bool viterbi,
471471
vector<double> *alpha,
@@ -1517,16 +1517,27 @@ void ComposeCompactLatticeDeterministic(
15171517
StateId s2 = s.second;
15181518
state_queue.pop();
15191519

1520-
// If the product of the final weights of the two states is not zero, then
1521-
// we should create final state in fst_composed. We compute the product
1522-
// manually since this is more efficient.
1523-
Weight2 final_weight(LatticeWeight(clat.Final(s1).Weight().Value1() +
1524-
det_fst->Final(s2).Value(),
1525-
clat.Final(s1).Weight().Value2()),
1526-
clat.Final(s1).String());
1527-
if (final_weight != Weight2::Zero()) {
1528-
KALDI_ASSERT(state_map.find(s) != state_map.end());
1529-
composed_clat->SetFinal(state_map[s], final_weight);
1520+
1521+
Weight2 clat_final = clat.Final(s1);
1522+
if (clat_final.Weight().Value1() !=
1523+
std::numeric_limits<BaseFloat>::infinity()) {
1524+
// Test for whether the final-prob of state s1 was zero.
1525+
Weight1 det_fst_final = det_fst->Final(s2);
1526+
if (det_fst_final.Value() !=
1527+
std::numeric_limits<BaseFloat>::infinity()) {
1528+
// Test for whether the final-prob of state s2 was zero. If neither
1529+
// source-state final prob was zero, then we should create final state
1530+
// in fst_composed. We compute the product manually since this is more
1531+
// efficient.
1532+
Weight2 final_weight(LatticeWeight(clat_final.Weight().Value1() +
1533+
det_fst_final.Value(),
1534+
clat_final.Weight().Value2()),
1535+
clat_final.String());
1536+
// we can assume final_weight is not Zero(), since neither of
1537+
// the sources was zero.
1538+
KALDI_ASSERT(state_map.find(s) != state_map.end());
1539+
composed_clat->SetFinal(state_map[s], final_weight);
1540+
}
15301541
}
15311542

15321543
// Loops over pair of edges at s1 and s2.
@@ -1567,7 +1578,7 @@ void ComposeCompactLatticeDeterministic(
15671578
KALDI_ASSERT(result.second);
15681579
state_queue.push(next_state_pair);
15691580
} else {
1570-
// If the combposed state is already in <state_map>, we can directly
1581+
// If the composed state is already in <state_map>, we can directly
15711582
// use that.
15721583
next_state = siter->second;
15731584
}
@@ -1584,7 +1595,7 @@ void ComposeCompactLatticeDeterministic(
15841595
arc1.weight.Weight().Value2()),
15851596
arc1.weight.String());
15861597
composed_clat->AddArc(state_map[s],
1587-
CompactLatticeArc(arc1.ilabel, arc1.olabel,
1598+
CompactLatticeArc(arc1.ilabel, arc2.olabel,
15881599
composed_weight, next_state));
15891600
}
15901601
}

0 commit comments

Comments
 (0)