52 using namespace kaldi;
54 typedef kaldi::int64 int64;
55 using fst::SymbolTable;
60 "This does the opposite of nbest-to-linear. It takes 4 archives,\n" 61 "containing alignments, word-sequences, and acoustic and LM costs,\n" 62 "and turns it into a single archive containing FSTs with a linear\n" 63 "structure. The program is called linear-to-nbest because very often\n" 64 "the archives concerned will represent N-best lists\n" 65 "Usage: linear-to-nbest [options] <alignments-rspecifier> " 66 "<transcriptions-rspecifier> (<lm-cost-rspecifier>|'') (<ac-cost-rspecifier>|'') " 67 "<nbest-wspecifier>\n" 68 "Note: if the rspecifiers for lm-cost or ac-cost are the empty string,\n" 69 "these value will default to zero.\n" 70 " e.g.: linear-to-nbest ark:1.ali 'ark:sym2int.pl -f 2- words.txt text|' " 71 "ark:1.lmscore ark:1.acscore " 78 if (po.NumArgs() != 5) {
83 std::string ali_rspecifier = po.GetArg(1),
84 trans_rspecifier = po.GetArg(2),
85 lm_cost_rspecifier = po.GetArg(3),
86 ac_cost_rspecifier = po.GetArg(4),
87 lats_wspecifier = po.GetArg(5);
98 int32 n_done = 0, n_err = 0;
100 for (; !ali_reader.Done(); ali_reader.Next()) {
101 std::string key = ali_reader.Key();
102 if (!trans_reader.HasKey(key)) {
103 KALDI_ERR <<
"No transcription for key " << key;
107 if (lm_cost_rspecifier !=
"" && !lm_cost_reader.HasKey(key)) {
108 KALDI_ERR <<
"No LM cost for key " << key;
112 if (ac_cost_rspecifier !=
"" && !ac_cost_reader.HasKey(key)) {
113 KALDI_ERR <<
"No acoustic cost for key " << key;
117 const std::vector<int32> &ali = ali_reader.Value();
118 const std::vector<int32> &
words = trans_reader.Value(key);
120 ac_cost = (ac_cost_rspecifier ==
"") ? 0.0 : ac_cost_reader.Value(key),
121 lm_cost = (lm_cost_rspecifier ==
"") ? 0.0 : lm_cost_reader.Value(key);
127 compact_lattice_writer.Write(key, clat);
130 KALDI_LOG <<
"Done " << n_done <<
" n-best entries ," 131 << n_err <<
" had errors.";
132 return (n_done != 0 ? 0 : 1);
133 }
catch(
const std::exception &e) {
134 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
A templated class for writing objects to an archive or script file; see The Table concept...
Allows random access to a collection of objects in an archive or script file; see The Table concept...
void MakeLatticeFromLinear(const std::vector< int32 > &ali, const std::vector< int32 > &words, BaseFloat lm_cost, BaseFloat ac_cost, Lattice *lat_out)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void ConvertLattice(const ExpandedFst< ArcTpl< Weight > > &ifst, MutableFst< ArcTpl< CompactLatticeWeightTpl< Weight, Int > > > *ofst, bool invert)
Convert lattice from a normal FST to a CompactLattice FST.
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
fst::VectorFst< LatticeArc > Lattice
fst::VectorFst< CompactLatticeArc > CompactLattice