34 using namespace kaldi;
36 using fst::SymbolTable;
42 "Creates HCLG decoding graph. Similar to mkgraph.sh but done in code.\n" 44 "Usage: compile-graph [options] <tree-in> <model-in> <lexicon-fst-in> " 45 " <gammar-rspecifier> <hclg-wspecifier>\n" 47 " compile-train-graphs-fsts tree 1.mdl L_disambig.fst G.fst HCLG.fst\n";
53 int32 nonterm_phones_offset = -1;
54 std::string disambig_rxfilename;
57 po.Register(
"read-disambig-syms", &disambig_rxfilename,
"File containing " 58 "list of disambiguation symbols in phone symbol table");
59 po.Register(
"transition-scale", &transition_scale,
"Scale of transition " 60 "probabilities (excluding self-loops).");
61 po.Register(
"self-loop-scale", &self_loop_scale,
"Scale of self-loop vs. " 62 "non-self-loop probability mass. Caution: the default of " 63 "mkgraph.sh is 0.1, but this defaults to 1.0.");
64 po.Register(
"nonterm-phones-offset", &nonterm_phones_offset,
"Integer " 65 "value of symbol #nonterm_bos in phones.txt, if present. " 66 "(Only relevant for grammar decoding).");
70 if (po.NumArgs() != 5) {
75 std::string tree_rxfilename = po.GetArg(1),
76 model_rxfilename = po.GetArg(2),
77 lex_rxfilename = po.GetArg(3),
78 grammar_rxfilename = po.GetArg(4),
79 hclg_wxfilename = po.GetArg(5);
90 std::vector<int32> disambig_syms;
91 if (disambig_rxfilename !=
"")
93 KALDI_ERR <<
"Could not read disambiguation symbols from " 94 << disambig_rxfilename;
95 if (disambig_syms.empty())
96 KALDI_WARN <<
"You supplied no disambiguation symbols; note, these are " 97 <<
"typically necessary when compiling graphs from FSTs (i.e. " 98 <<
"supply L_disambig.fst and the list of disambig syms with\n" 99 <<
"--read-disambig-syms)";
101 const std::vector<int32> &phone_syms = trans_model.
GetPhones();
103 for (int32
i = 0;
i < disambig_syms.size();
i++)
104 if (std::binary_search(phone_syms.begin(), phone_syms.end(),
106 KALDI_ERR <<
"Disambiguation symbol " << disambig_syms[
i]
107 <<
" is also a phone.";
109 VectorFst<StdArc> lg_fst;
121 VectorFst<StdArc> clg_fst;
123 std::vector<std::vector<int32> > ilabels;
128 if (nonterm_phones_offset < 0) {
131 &lg_fst, &clg_fst, &ilabels);
134 if (context_width != 2 || central_position != 1) {
135 KALDI_ERR <<
"Grammar-fst graph creation only supports models with left-" 136 "biphone context. (--nonterm-phones-offset option was supplied).";
139 lg_fst, &clg_fst, &ilabels);
141 lg_fst.DeleteStates();
146 std::vector<int32> disambig_syms_h;
154 VectorFst<StdArc> hclg_fst;
156 clg_fst.DeleteStates();
164 if (!disambig_syms_h.empty()) {
172 std::vector<int32> disambig;
173 bool check_no_self_loops =
true,
182 if (nonterm_phones_offset >= 0)
186 fst::ConstFst<StdArc> const_hclg(hclg_fst);
187 bool binary =
true, write_binary_header =
false;
188 Output ko(hclg_wxfilename, binary, write_binary_header);
190 const_hclg.Write(ko.Stream(), wopts);
193 KALDI_LOG <<
"Wrote graph with " << hclg_fst.NumStates()
194 <<
" states to " << hclg_wxfilename;
196 }
catch(
const std::exception &e) {
197 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
virtual int32 ContextWidth() const
ContextWidth() returns the value N (e.g.
void TableCompose(const Fst< Arc > &ifst1, const Fst< Arc > &ifst2, MutableFst< Arc > *ofst, const TableComposeOptions &opts=TableComposeOptions())
const std::vector< int32 > & GetPhones() const
Returns a sorted, unique list of phones.
void RemoveEpsLocal(MutableFst< Arc > *fst)
RemoveEpsLocal remove some (but not necessarily all) epsilons in an FST, using an algorithm that is g...
void AddSelfLoops(const TransitionModel &trans_model, const std::vector< int32 > &disambig_syms, BaseFloat self_loop_scale, bool reorder, bool check_no_self_loops, fst::VectorFst< fst::StdArc > *fst)
For context, see AddSelfLoops().
void MinimizeEncoded(VectorFst< Arc > *fst, float delta=kDelta)
int32 nonterm_phones_offset
void SortAndUniq(std::vector< T > *vec)
Sorts and uniq's (removes duplicates) from a vector.
void PrepareForGrammarFst(int32 nonterm_phones_offset, VectorFst< StdArc > *fst)
This function prepares 'ifst' for use in GrammarFst: it ensures that it has the expected properties...
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
void DeterminizeStarInLog(VectorFst< StdArc > *fst, float delta, bool *debug_ptr, int max_states)
Configuration class for the GetHTransducer() function; see The HTransducerConfig configuration class ...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void ComposeContextLeftBiphone(int32 nonterm_phones_offset, const vector< int32 > &disambig_syms_in, const VectorFst< StdArc > &ifst, VectorFst< StdArc > *ofst, std::vector< std::vector< int32 > > *ilabels)
This is a variant of the function ComposeContext() which is to be used with our "grammar FST" framewo...
virtual int32 CentralPosition() const
Central position P of the phone context, in 0-based numbering, e.g.
fst::VectorFst< fst::StdArc > * GetHTransducer(const std::vector< std::vector< int32 > > &ilabel_info, const ContextDependencyInterface &ctx_dep, const TransitionModel &trans_model, const HTransducerConfig &config, std::vector< int32 > *disambig_syms_left)
Returns the H tranducer; result owned by caller.
BaseFloat transition_scale
Transition log-prob scale, see Scaling of transition and acoustic probabilities.
void ComposeContext(const vector< int32 > &disambig_syms_in, int32 context_width, int32 central_position, VectorFst< StdArc > *ifst, VectorFst< StdArc > *ofst, vector< vector< int32 > > *ilabels_out, bool project_ifst)
Used in the command-line tool fstcomposecontext.
#define KALDI_ASSERT(cond)
void PushSpecial(VectorFst< StdArc > *fst, float delta)
void ReadFstKaldi(std::istream &is, bool binary, VectorFst< Arc > *fst)
std::string PrintableWxfilename(const std::string &wxfilename)
PrintableWxfilename turns the wxfilename into a more human-readable form for error reporting...
bool ReadIntegerVectorSimple(const std::string &rxfilename, std::vector< int32 > *list)
ReadFromList attempts to read this list of integers, one per line, from the given file...
void RemoveSomeInputSymbols(const std::vector< I > &to_remove, MutableFst< Arc > *fst)
RemoveSomeInputSymbols removes any symbol that appears in "to_remove", from the input side of the FST...