39 const fst::SymbolTable *word_syms,
41 double acoustic_scale,
51 if (!decoder.
Decode(&decodable)) {
57 KALDI_WARN <<
"Outputting partial output for utterance " << utt
58 <<
" since no final-state reached\n";
60 KALDI_WARN <<
"Not producing output for utterance " << utt
61 <<
" since no final-state reached and " 62 <<
"--allow-partial=false.\n";
71 VectorFst<LatticeArc> decoded;
73 if (decoded.NumStates() == 0)
75 KALDI_ERR <<
"Failed to get traceback for utterance " << utt;
77 std::vector<int32> alignment;
78 std::vector<int32>
words;
80 num_frames = alignment.size();
81 if (words_writer->
IsOpen())
82 words_writer->
Write(utt, words);
83 if (alignment_writer->
IsOpen())
84 alignment_writer->
Write(utt, alignment);
85 if (word_syms != NULL) {
86 std::cerr << utt <<
' ';
87 for (
size_t i = 0;
i < words.size();
i++) {
88 std::string s = word_syms->Find(words[
i]);
90 KALDI_ERR <<
"Word-id " << words[
i] <<
" not in symbol table.";
91 std::cerr << s <<
' ';
101 if (lat.NumStates() == 0)
102 KALDI_ERR <<
"Unexpected problem getting lattice for utterance " << utt;
112 KALDI_WARN <<
"Determinization finished earlier than the beam for " 113 <<
"utterance " << utt;
115 if (acoustic_scale != 0.0)
117 compact_lattice_writer->
Write(utt, clat);
121 if (fst.NumStates() == 0)
122 KALDI_ERR <<
"Unexpected problem getting lattice for utterance " 126 if (acoustic_scale != 0.0)
128 lattice_writer->
Write(utt, fst);
130 KALDI_LOG <<
"Log-like per frame for utterance " << utt <<
" is " 131 << (likelihood / num_frames) <<
" over " 132 << num_frames <<
" frames.";
133 KALDI_VLOG(2) <<
"Cost for utterance " << utt <<
" is " 135 *like_ptr = likelihood;
143 int main(
int argc,
char *argv[]) {
145 using namespace kaldi;
147 using fst::SymbolTable;
148 using fst::VectorFst;
154 "Generate lattices using GMM-based model.\n" 155 "User supplies LM used to generate decoding graph, and desired LM;\n" 156 "this decoder applies the difference during decoding\n" 157 "Usage: gmm-latgen-biglm-faster [options] model-in (fst-in|fsts-rspecifier) " 158 "oldlm-fst-in newlm-fst-in features-rspecifier" 159 " lattice-wspecifier [ words-wspecifier [alignments-wspecifier] ]\n";
162 bool allow_partial =
false;
166 std::string word_syms_filename;
168 po.
Register(
"acoustic-scale", &acoustic_scale,
"Scaling factor for acoustic likelihoods");
170 po.
Register(
"word-symbol-table", &word_syms_filename,
"Symbol table for words [for debug output]");
171 po.
Register(
"allow-partial", &allow_partial,
"If true, produce output even if end state was not reached.");
180 std::string model_in_filename = po.
GetArg(1),
181 fst_in_str = po.
GetArg(2),
182 old_lm_fst_rxfilename = po.
GetArg(3),
183 new_lm_fst_rxfilename = po.
GetArg(4),
184 feature_rspecifier = po.
GetArg(5),
185 lattice_wspecifier = po.
GetArg(6),
193 Input ki(model_in_filename, &binary);
214 if (! (determinize ? compact_lattice_writer.
Open(lattice_wspecifier)
215 : lattice_writer.
Open(lattice_wspecifier)))
216 KALDI_ERR <<
"Could not open table for writing lattices: " 217 << lattice_wspecifier;
223 fst::SymbolTable *word_syms = NULL;
224 if (word_syms_filename !=
"")
225 if (!(word_syms = fst::SymbolTable::ReadText(word_syms_filename)))
226 KALDI_ERR <<
"Could not read symbol table from file " 227 << word_syms_filename;
229 double tot_like = 0.0;
230 kaldi::int64 frame_count = 0;
231 int num_success = 0, num_fail = 0;
242 for (; !feature_reader.
Done(); feature_reader.
Next()) {
243 std::string utt = feature_reader.
Key();
246 if (features.NumRows() == 0) {
247 KALDI_WARN <<
"Zero-length utterance: " << utt;
258 utt, acoustic_scale, determinize, allow_partial,
259 &alignment_writer, &words_writer,
260 &compact_lattice_writer, &lattice_writer,
263 frame_count += features.NumRows();
272 for (; !fst_reader.
Done(); fst_reader.
Next()) {
273 std::string utt = fst_reader.
Key();
274 if (!feature_reader.
HasKey(utt)) {
275 KALDI_WARN <<
"Not decoding utterance " << utt
276 <<
" because no features available.";
282 KALDI_WARN <<
"Zero-length utterance: " << utt;
291 if (
DecodeUtterance(decoder, gmm_decodable, trans_model, word_syms, utt,
292 acoustic_scale, determinize, allow_partial,
293 &alignment_writer, &words_writer,
294 &compact_lattice_writer, &lattice_writer,
297 frame_count += features.
NumRows();
303 double elapsed = timer.
Elapsed();
305 <<
"s: real-time factor assuming 100 frames/sec is " 306 << (elapsed*100.0/frame_count);
307 KALDI_LOG <<
"Done " << num_success <<
" utterances, failed for " 309 KALDI_LOG <<
"Overall log-likelihood per frame is " << (tot_like/frame_count) <<
" over " 310 << frame_count<<
" frames.";
313 if (num_success != 0)
return 0;
315 }
catch(
const std::exception &e) {
316 std::cerr << e.what();
This class wraps an Fst, representing a language model, using the interface for "BackoffDeterministic...
bool DecodeUtterance(LatticeBiglmFasterDecoder &decoder, DecodableInterface &decodable, const TransitionModel &trans_model, const fst::SymbolTable *word_syms, std::string utt, double acoustic_scale, bool determinize, bool allow_partial, Int32VectorWriter *alignment_writer, Int32VectorWriter *words_writer, CompactLatticeWriter *compact_lattice_writer, LatticeWriter *lattice_writer, double *like_ptr)
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
bool GetBestPath(fst::MutableFst< LatticeArc > *ofst, bool use_final_probs=true) const
bool Open(const std::string &wspecifier)
DecodableInterface provides a link between the (acoustic-modeling and feature-processing) code and th...
Fst< StdArc > * ReadFstKaldiGeneric(std::string rxfilename, bool throw_on_err)
For an extended explanation of the framework of which grammar-fsts are a part, please see Support for...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
A templated class for writing objects to an archive or script file; see The Table concept...
bool Decode(DecodableInterface *decodable)
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.
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
Allows random access to a collection of objects in an archive or script file; see The Table concept...
std::vector< std::vector< double > > AcousticLatticeScale(double acwt)
LatticeBiglmFasterDecoderConfig GetOptions()
int main(int argc, char *argv[])
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
const T & Value(const std::string &key)
void ScaleLattice(const std::vector< std::vector< ScaleFloat > > &scale, MutableFst< ArcTpl< Weight > > *fst)
Scales the pairs of weights in LatticeWeight or CompactLatticeWeight by viewing the pair (a...
void Read(std::istream &is, bool binary)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
fst::VectorFst< LatticeArc > Lattice
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
bool ReachedFinal() const
says whether a final-state was active on the last frame.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
This is as LatticeFasterDecoder, but does online composition between HCLG and the "difference languag...
bool GetRawLattice(fst::MutableFst< LatticeArc > *ofst, bool use_final_probs=true) const
bool HasKey(const std::string &key)
void ApplyProbabilityScale(float scale, MutableFst< Arc > *fst)
ApplyProbabilityScale is applicable to FSTs in the log or tropical semiring.
fst::VectorFst< CompactLatticeArc > CompactLattice
fst::DeterminizeLatticePhonePrunedOptions det_opts
int NumArgs() const
Number of positional parameters (c.f. argc-1).
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void ReadFstKaldi(std::istream &is, bool binary, VectorFst< Arc > *fst)
VectorFst< StdArc > * CastOrConvertToVectorFst(Fst< StdArc > *fst)
void Register(OptionsItf *opts)
double Elapsed() const
Returns time in seconds.
void Read(std::istream &in_stream, bool binary)
bool DeterminizeLatticePhonePrunedWrapper(const kaldi::TransitionModel &trans_model, MutableFst< kaldi::LatticeArc > *ifst, double beam, MutableFst< kaldi::CompactLatticeArc > *ofst, DeterminizeLatticePhonePrunedOptions opts)
This function is a wrapper of DeterminizeLatticePhonePruned() that works for Lattice type FSTs...
std::string GetOptArg(int param) const