76 using namespace kaldi;
78 typedef kaldi::int64 int64;
79 using fst::SymbolTable;
84 "Replace the acoustic scores on a lattice using log-likelihoods read in\n" 85 "as a matrix for each utterance, indexed (frame, pdf-id). This does the same\n" 86 "as (e.g.) gmm-rescore-lattice, but from a matrix. The \"mapped\" means that\n" 87 "the transition-model is used to map transition-ids to pdf-ids. (c.f.\n" 88 "latgen-faster-mapped). Note: <transition-model-in> can be any type of\n" 89 "model file, e.g. GMM-based or neural-net based; only the transition model is read.\n" 91 "Usage: lattice-rescore-mapped [options] <transition-model-in> <lattice-rspecifier> " 92 "<loglikes-rspecifier> <lattice-wspecifier>\n" 93 " e.g.: nnet-logprob [args] .. | lattice-rescore-mapped final.mdl ark:1.lats ark:- ark:2.lats\n";
97 po.Register(
"old-acoustic-scale", &old_acoustic_scale,
98 "Add in the scores in the input lattices with this scale, rather " 99 "than discarding them.");
102 if (po.NumArgs() != 4) {
107 std::string model_filename = po.GetArg(1),
108 lats_rspecifier = po.GetArg(2),
109 loglike_rspecifier = po.GetArg(3),
110 lats_wspecifier = po.GetArg(4);
115 Input ki(model_filename, &binary);
116 trans_model.
Read(ki.Stream(), binary);
126 int32 num_done = 0, num_err = 0;
127 int64 num_frames = 0;
128 for (; !lattice_reader.Done(); lattice_reader.Next()) {
129 std::string key = lattice_reader.Key();
130 if (!loglike_reader.HasKey(key)) {
131 KALDI_WARN <<
"No log-likes found for utterance " << key <<
". Skipping";
136 Lattice lat = lattice_reader.Value();
137 lattice_reader.FreeCurrent();
138 if (old_acoustic_scale != 1.0)
141 kaldi::uint64 props = lat.Properties(fst::kFstProperties,
false);
142 if (!(props & fst::kTopSorted)) {
143 if (fst::TopSort(&lat) ==
false)
144 KALDI_ERR <<
"Cycles detected in lattice.";
147 std::vector<int32> state_times;
150 if (log_likes.
NumRows() != max_time) {
151 KALDI_WARN <<
"Skipping utterance " << key <<
" since number of time " 152 <<
"frames in lattice ("<< max_time <<
") differ from " 153 <<
"number of frames in log-likelihoods (" << log_likes.
NumRows() <<
").";
162 compact_lattice_writer.Write(key, clat_out);
164 num_frames += log_likes.
NumRows();
167 KALDI_LOG <<
"Done " << num_done <<
" lattices, " << num_err
168 <<
" with errors, #frames is " << num_frames;
169 return (num_done != 0 ? 0 : 1);
170 }
catch(
const std::exception &e) {
171 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
int32 LatticeStateTimes(const Lattice &lat, vector< int32 > *times)
This function iterates over the states of a topologically sorted lattice and counts the time instance...
A templated class for writing objects to an archive or script file; see The Table concept...
void LatticeAcousticRescore(const TransitionModel &trans_model, const Matrix< BaseFloat > &log_likes, const std::vector< int32 > &state_times, Lattice *lat)
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)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
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)
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
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).