37 i1.
End() < i2.
End() ?
true:
false);
41 const std::vector<int32> &state_times) {
46 unordered_map<StateId, std::vector<Interval> > head;
50 for (StateIterator<CompactLattice> siter(*clat); !siter.Done();
52 StateId state_id = siter.Value();
53 for (ArcIterator<CompactLattice> aiter(*clat, state_id); !aiter.Done();
56 if (state_id >= state_times.size() || arc.nextstate >= state_times.size())
58 if (state_id > max_id)
60 if (arc.nextstate > max_id)
61 max_id = arc.nextstate;
62 head[arc.ilabel].push_back(
Interval(state_times[state_id],
63 state_times[arc.nextstate]));
67 if (state_times.size() != max_id+1)
75 unordered_map<StateId, std::vector<Interval> >::iterator iter;
76 for (iter = head.begin(); iter != head.end(); ++iter) {
79 std::vector<Interval> tmp;
80 tmp.push_back(iter->second[0]);
81 for (
int32 i = 1;
i < iter->second.size();
i++) {
82 if (tmp.back().End() <= iter->second[
i].Start())
83 tmp.push_back(iter->second[
i]);
91 for (StateIterator<CompactLattice> siter(*clat); !siter.Done();
94 for (MutableArcIterator<CompactLattice> aiter(clat, state_id);
95 !aiter.Done(); aiter.Next()) {
101 Interval interval(state_times[state_id], state_times[arc.nextstate]);
102 int32 max_overlap = 0;
104 for (
int32 i = 0;
i < head[arc.ilabel].size();
i++) {
106 if (overlap > max_overlap) {
107 max_overlap = overlap;
130 return ToArc(arc.ilabel,
132 (arc.weight == FromWeight::Zero() ?
134 ToWeight(arc.weight.Weight().Value1()
135 +arc.weight.Weight().Value2(),
137 StdXStdprimeWeight::Zero() :
138 StdXStdprimeWeight::One()))),
143 return fst::MAP_NO_SUPERFINAL;
147 return fst::MAP_COPY_SYMBOLS;
151 return fst::MAP_COPY_SYMBOLS;
161 const std::vector<int32> &state_times,
168 bool success =
false;
169 std::vector<double> alpha;
170 std::vector<double> beta;
187 for (StateIterator<KwsProductFst>
188 siter(*factor_transducer); !siter.Done(); siter.Next()) {
190 for (MutableArcIterator<KwsProductFst>
191 aiter(factor_transducer, state_id); !aiter.Done(); aiter.Next()) {
193 BaseFloat w = arc.weight.Value1().Value();
194 w += beta[state_id] - beta[arc.nextstate];
200 if (factor_transducer->Final(state_id) != KwsProductWeight::Zero()) {
201 BaseFloat w = factor_transducer->Final(state_id).Value1().Value();
204 factor_transducer->SetFinal(state_id, weight);
211 for (
int32 s = 0; s < alpha.size(); s++) {
212 alpha[s] += beta[s] - beta[0];
214 if (alpha[s] > 0.1) {
224 std::vector<char> state_properties;
226 bool has_epsilon_property =
true;
227 for (
size_t i = 0;
i < state_properties.size();
i++) {
228 char c = state_properties[
i];
231 has_epsilon_property =
false;
234 has_epsilon_property =
false;
236 if (!has_epsilon_property) {
237 KALDI_WARN <<
"Epsilon property does not hold, reverting to old behavior.";
242 StateId ns = factor_transducer->NumStates();
243 StateId ss = factor_transducer->AddState();
244 StateId fs = factor_transducer->AddState();
245 factor_transducer->SetStart(ss);
246 factor_transducer->SetFinal(fs, KwsProductWeight::One());
248 for (StateId s = 0; s < ns; s++) {
250 if (!has_epsilon_property ||
254 if (!has_epsilon_property ||
258 if (factor_transducer->Final(s) != KwsProductWeight::Zero())
259 factor_transducer->SetFinal(s, KwsProductWeight::Zero());
266 const std::vector<int32> &state_times,
271 StateId ns = factor_transducer->NumStates();
272 StateId ss = factor_transducer->Start();
273 StateId bad_state = factor_transducer->AddState();
274 for (StateId s = 0; s < ns; s++) {
278 for (MutableArcIterator<KwsProductFst>
279 aiter(factor_transducer, s); !aiter.Done(); aiter.Next()) {
282 if (factor_transducer->Final(arc.nextstate) != KwsProductWeight::Zero())
288 if (state_times[arc.nextstate]-state_times[s] <= max_silence_frames)
292 arc.nextstate = bad_state;
298 Connect(factor_transducer);
304 const fst::VectorFst<Arc> &fst2,
305 fst::VectorFst<Arc> *difference) {
307 if (!fst2.Properties(kAcceptor,
true)) {
309 EncodeMapper<Arc> encoder(kEncodeLabels, ENCODE);
310 VectorFst<Arc> fst1_copy(fst1);
311 VectorFst<Arc> fst2_copy(fst2);
312 Encode(&fst1_copy, &encoder);
313 Encode(&fst2_copy, &encoder);
315 Decode(difference, encoder);
317 VectorFst<Arc> fst2_copy(fst2);
318 RmEpsilon(&fst2_copy);
320 Difference(fst1, fst2_copy, difference);
329 ShortestPath(index_transducer, &temp_transducer);
330 std::vector<Label> isymbols, osymbols;
333 std::ostringstream os;
334 for (
size_t i = 0;
i < isymbols.size();
i++)
335 os << isymbols[
i] <<
' ';
336 BaseFloat best_cost = weight.Value1().Value();
337 KALDI_VLOG(3) <<
"Best path: " << isymbols.size() <<
" isymbols " <<
", " 338 << osymbols.size() <<
" osymbols, isymbols are " << os.str()
339 <<
", best cost is " << best_cost;
348 ShortestPath(difference_transducer, &temp_transducer);
351 std::ostringstream os2;
352 for (
size_t i = 0;
i < isymbols.size();
i++)
353 os2 << isymbols[
i] <<
' ';
354 BaseFloat second_best_cost = weight.Value1().Value();
355 KALDI_VLOG(3) <<
"Second-best path: " << isymbols.size()
356 <<
" isymbols " <<
", " 357 << osymbols.size() <<
" osymbols, isymbols are " << os2.str()
358 <<
", second-best cost is " << second_best_cost;
359 if (second_best_cost < -0.01) {
360 KALDI_WARN <<
"Negative second-best cost found " << second_best_cost;
369 Map(product_transducer,
fst::StdArc::StateId StateId
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
fst::VectorFst< KwsProductArc > KwsProductFst
bool CompareInterval(const Interval &i1, const Interval &i2)
ToArc operator()(const FromArc &arc) const
fst::MapFinalAction FinalAction() const
bool ClusterLattice(CompactLattice *clat, const std::vector< int32 > &state_times)
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
int32 GetVerboseLevel()
Get verbosity level, usually set via command line '–verbose=' switch.
static void DifferenceWrapper(const fst::VectorFst< Arc > &fst1, const fst::VectorFst< Arc > &fst2, fst::VectorFst< Arc > *difference)
LogXStdXStdprimeWeight KwsProductWeight
uint64 Properties(uint64 props) const
fst::MapSymbolsAction OutputSymbolsAction() const
bool GetLinearSymbolSequence(const Fst< Arc > &fst, std::vector< I > *isymbols_out, std::vector< I > *osymbols_out, typename Arc::Weight *tot_weight_out)
GetLinearSymbolSequence gets the symbol sequence from a linear FST.
CompactLatticeArc FromArc
void ComputeStateInfo(const VectorFst< Arc > &fst, std::vector< char > *epsilon_info)
This function will set epsilon_info to have size equal to the NumStates() of the FST, containing a logical-or of the enum values kStateHasEpsilonArcsEntering, kStateHasNonEpsilonArcsEntering, kStateHasEpsilonArcsLeaving, and kStateHasNonEpsilonArcsLeaving.
int32 Overlap(Interval interval)
fst::VectorFst< KwsLexicographicArc > KwsLexicographicFst
fst::ProductWeight< TropicalWeight, ArcticWeight > StdXStdprimeWeight
static const ArcticWeightTpl< T > One()
bool ComputeCompactLatticeBetas(const CompactLattice &clat, vector< double > *beta)
static const LatticeWeightTpl Zero()
bool CreateFactorTransducer(const CompactLattice &clat, const std::vector< int32 > &state_times, int32 utterance_id, KwsProductFst *factor_transducer)
KwsProductWeight ToWeight
fst::VectorFst< CompactLatticeArc > CompactLattice
void MaybeDoSanityCheck(const KwsLexicographicFst &index_transducer)
void RemoveLongSilences(int32 max_silence_frames, const std::vector< int32 > &state_times, KwsProductFst *factor_transducer)
CompactLatticeToKwsProductFstMapper()
StdLStdLStdWeight KwsLexicographicWeight
void RemoveWeights(MutableFst< Arc > *ifst)
CompactLatticeWeight FromWeight
LogXStdXStdprimeArc KwsProductArc
fst::ArcTpl< CompactLatticeWeight > CompactLatticeArc
bool ComputeCompactLatticeAlphas(const CompactLattice &clat, vector< double > *alpha)
fst::MapSymbolsAction InputSymbolsAction() const