29 using namespace kaldi;
34 "Convert lattices so that the arcs in the CompactLattice format correspond with\n" 35 "words (i.e. aligned with word boundaries). This is the newest form, that\n" 36 "reads in a lexicon in integer format, where each line is (integer id of)\n" 37 " word-in word-out phone1 phone2 ... phoneN\n" 38 "(note: word-in is word before alignment, word-out is after, e.g. for replacing\n" 39 "<eps> with SIL or vice versa)\n" 40 "This may be more efficient if you first apply 'lattice-push'.\n" 41 "Usage: lattice-align-words-lexicon [options] <lexicon-file> <model> <lattice-rspecifier> <lattice-wspecifier>\n" 42 " e.g.: lattice-align-words-lexicon --partial-word-label=4324 --max-expand 10.0 --test true \\\n" 43 " data/lang/phones/align_lexicon.int final.mdl ark:1.lats ark:aligned.lats\n" 44 "See also: lattice-align-words, which is only applicable if your phones have word-position\n" 45 "markers, i.e. each phone comes in 5 versions like AA_B, AA_I, AA_W, AA_S, AA.\n";
48 bool output_if_error =
true;
49 bool output_if_empty =
false;
51 po.Register(
"output-error-lats", &output_if_error,
"Output lattices that aligned " 52 "with errors (e.g. due to force-out");
53 po.Register(
"output-if-empty", &output_if_empty,
"If true: if algorithm gives " 54 "error and produces empty output, pass the input through.");
61 if (po.NumArgs() != 4) {
67 align_lexicon_rxfilename = po.GetArg(1),
68 model_rxfilename = po.GetArg(2),
69 lats_rspecifier = po.GetArg(3),
70 lats_wspecifier = po.GetArg(4);
72 std::vector<std::vector<int32> > lexicon;
75 Input ki(align_lexicon_rxfilename, &binary_in);
76 KALDI_ASSERT(!binary_in &&
"Not expecting binary file for lexicon");
78 KALDI_ERR <<
"Error reading alignment lexicon from " 79 << align_lexicon_rxfilename;
90 { std::vector<std::vector<int32> > temp; lexicon.swap(temp); }
93 int32 num_done = 0, num_err = 0;
95 for (; !clat_reader.Done(); clat_reader.Next()) {
96 std::string key = clat_reader.Key();
106 if (output_if_empty && aligned_clat.NumStates() == 0 &&
107 clat.NumStates() != 0) {
108 KALDI_WARN <<
"Algorithm produced no output (due to --max-expand?), " 109 <<
"so passing input through as output, for key " << key;
111 clat_writer.Write(key, clat);
114 if (!output_if_error)
115 KALDI_WARN <<
"Lattice for " << key <<
" did not align correctly";
117 if (aligned_clat.Start() != fst::kNoStateId) {
118 KALDI_WARN <<
"Outputting partial lattice for " << key;
120 clat_writer.Write(key, aligned_clat);
122 KALDI_WARN <<
"Empty aligned lattice for " << key
123 <<
", producing no output.";
127 if (aligned_clat.Start() == fst::kNoStateId) {
129 KALDI_WARN <<
"Lattice was empty for key " << key;
132 KALDI_VLOG(2) <<
"Aligned lattice for " << key;
134 clat_writer.Write(key, aligned_clat);
138 KALDI_LOG <<
"Successfully aligned " << num_done <<
" lattices; " 139 << num_err <<
" had errors.";
140 return (num_done > num_err ? 0 : 1);
143 }
catch(
const std::exception &e) {
144 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
bool ReadLexiconForWordAlign(std::istream &is, std::vector< std::vector< int32 > > *lexicon)
Read the lexicon in the special format required for word alignment.
A templated class for writing objects to an archive or script file; see The Table concept...
bool WordAlignLatticeLexicon(const CompactLattice &lat, const TransitionModel &tmodel, const WordAlignLatticeLexiconInfo &lexicon_info, const WordAlignLatticeLexiconOpts &opts, CompactLattice *lat_out)
Align lattice so that each arc has the transition-ids on it that correspond to the word that is on th...
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void Register(OptionsItf *opts)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
fst::VectorFst< CompactLatticeArc > CompactLattice
#define KALDI_ASSERT(cond)
This class extracts some information from the lexicon and stores it in a suitable form for the word-a...
void TopSortCompactLatticeIfNeeded(CompactLattice *clat)
Topologically sort the compact lattice if not already topologically sorted.