46 genFst->SetInputSymbols(pst);
47 genFst->SetOutputSymbols(pst);
53 genFst->SetStart(initId);
54 genFst->SetFinal(finalId, fst::StdArc::Weight::One());
58 genFst->SetStart(midId);
59 genFst->SetFinal(midId, fst::StdArc::Weight::One());
63 fst::SymbolTableIterator si(*pst);
64 for (si.Reset(); !si.Done(); si.Next()) {
65 if (si.Value() ==
kBos || si.Value() ==
kEos ||
68 genFst->AddArc(midId,
fst::StdArc(si.Value(), si.Value(),
69 fst::StdArc::Weight::One(), midId));
77 fst::SymbolTable symbols;
79 symbols.AddSymbol(
" <eps>",
kEps);
104 fst->AddArc(last_state,
fst::StdArc(symbol, symbol, 0, next_state));
110 for (fst::StateIterator<fst::StdMutableFst> siter(*fst);
111 !siter.Done(); siter.Next()) {
112 fst->AddArc(siter.Value(),
128 int num_successes = 0;
132 RandGen(*genFst, &sentence);
136 fst::ArcSort(lm_compiler->
MutableFst(), fst::StdOLabelCompare());
140 Compose(sentence, lm_compiler->
Fst(), &composition);
141 if (composition.Start() != fst::kNoStateId)
150 KALDI_WARN <<
"Coverage test failed on " << infile <<
": composed " 156 bool ScoringTest(
bool seps,
const std::string &infile,
const std::string& sentence,
159 const fst::SymbolTable* symbols = lm_compiler->
Fst().InputSymbols();
164 sentFst.SetStart(state);
168 std::stringstream ss(sentence);
171 int64 word_sym = symbols->Find(word);
181 sentFst.SetFinal(state, 0);
182 sentFst.SetOutputSymbols(symbols);
186 fst::Compose(sentFst, lm_compiler->
Fst(), &composed);
189 if (composed.Start() == fst::kNoStateId) {
190 KALDI_WARN <<
"Test sentence " << sentence <<
" did not compose " 191 <<
"with the language model FST\n";
195 std::vector<fst::StdArc::Weight> shortest;
196 fst::ShortestDistance(composed, &shortest,
true);
197 float actual = shortest[composed.Start()].Value();
201 KALDI_WARN <<
"Scored " << sentence <<
" in " << infile
202 <<
": Expected=" << expected <<
" actual=" << actual;
210 std::unique_ptr<ArpaLmCompiler> compiler(
Compile(seps, infile));
231 KALDI_WARN <<
"Tests " << (seps ?
"with" :
"without")
232 <<
" epsilon substitution FAILED";
237 int main(
int argc,
char *argv[]) {
fst::StdArc::StateId StateId
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
ArpaLmCompiler * Compile(bool seps, const std::string &infile)
fst::StdArc::StateId AddToChainFsa(fst::StdMutableFst *fst, fst::StdArc::StateId last_state, int64 symbol)
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
Options that control ArpaFileParser.
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().
const fst::StdVectorFst & Fst() const
bool ThrowsExceptionTest(bool seps, const std::string &infile)
bool RunAllTests(bool seps)
static fst::StdVectorFst * CreateGenFst(bool seps, const fst::SymbolTable *pst)
fst::StdVectorFst * MutableFst()
fst::StdVectorFst StdVectorFst
Add novel words to the symbol table.
Kaldi fatal runtime error exception.
int32 eos_symbol
Symbol for </s>, Required non-epsilon.
bool CoverageTest(bool seps, const std::string &infile)
void Read(std::istream &is)
Read ARPA LM file from a stream.
int32 bos_symbol
Symbol for <s>, Required non-epsilon.
#define KALDI_ASSERT(cond)
int main(int argc, char *argv[])
bool ScoringTest(bool seps, const std::string &infile, const std::string &sentence, float expected)
OovHandling oov_handling
How to handle OOV words in the file.
static const int kRandomSentences
static bool ApproxEqual(float a, float b, float relative_tolerance=0.001)
return abs(a - b) <= relative_tolerance * (abs(a)+abs(b)).