34 using namespace kaldi;
36 typedef kaldi::int64 int64;
37 using fst::SymbolTable;
42 "Replace the acoustic scores on a lattice using a new model.\n" 43 "Usage: sgmm2-rescore-lattice [options] <model-in> <lattice-rspecifier> " 44 "<feature-rspecifier> <lattice-wspecifier>\n" 45 " e.g.: sgmm2-rescore-lattice 1.mdl ark:1.lats scp:trn.scp ark:2.lats\n";
50 std::string gselect_rspecifier, spkvecs_rspecifier, utt2spk_rspecifier;
53 po.Register(
"old-acoustic-scale", &old_acoustic_scale,
54 "Add the current acoustic scores with some scale.");
55 po.Register(
"log-prune", &log_prune,
56 "Pruning beam used to reduce number of exp() evaluations.");
57 po.Register(
"spk-vecs", &spkvecs_rspecifier,
"Speaker vectors (rspecifier)");
58 po.Register(
"utt2spk", &utt2spk_rspecifier,
59 "rspecifier for utterance to speaker map");
60 po.Register(
"gselect", &gselect_rspecifier,
61 "Precomputed Gaussian indices (rspecifier)");
62 po.Register(
"speedup", &speedup,
63 "If true, enable a faster version of the computation that " 64 "saves times when there is only one pdf-id on a single frame " 65 "by only sometimes (randomly) computing the probabilities, and " 66 "then scaling them up to preserve corpus-level diagnostics.");
71 if (po.NumArgs() != 4) {
75 if (gselect_rspecifier ==
"")
76 KALDI_ERR <<
"--gselect-rspecifier option is required.";
78 std::string model_filename = po.GetArg(1),
79 lats_rspecifier = po.GetArg(2),
80 feature_rspecifier = po.GetArg(3),
81 lats_wspecifier = po.GetArg(4);
87 Input ki(model_filename, &binary);
88 trans_model.
Read(ki.Stream(), binary);
89 am_sgmm.
Read(ki.Stream(), binary);
101 int32 num_done = 0, num_err = 0;
102 for (; !compact_lattice_reader.Done(); compact_lattice_reader.Next()) {
103 std::string utt = compact_lattice_reader.Key();
104 if (!feature_reader.HasKey(utt)) {
105 KALDI_WARN <<
"No feature found for utterance " << utt;
111 compact_lattice_reader.FreeCurrent();
112 if (old_acoustic_scale != 1.0)
119 if (spkvecs_reader.IsOpen()) {
120 if (spkvecs_reader.HasKey(utt)) {
124 KALDI_WARN <<
"Cannot find speaker vector for " << utt;
130 if (!gselect_reader.HasKey(utt) ||
131 gselect_reader.Value(utt).size() != feats.
NumRows()) {
132 KALDI_WARN <<
"No Gaussian-selection info available for utterance " 133 << utt <<
" (or wrong size)";
137 const std::vector<std::vector<int32> > &gselect =
138 gselect_reader.Value(utt);
141 gselect, log_prune, &spk_vars);
145 compact_lattice_writer.Write(utt, clat);
153 compact_lattice_writer.Write(utt, clat);
159 KALDI_LOG <<
"Done " << num_done <<
" lattices, errors on " 161 return (num_done != 0 ? 0 : 1);
162 }
catch(
const std::exception &e) {
163 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Class for definition of the subspace Gmm acoustic model.
This class is for when you are reading something in random access, but it may actually be stored per-...
void Read(std::istream &is, bool binary)
A templated class for writing objects to an archive or script file; see The Table concept...
bool RescoreCompactLatticeSpeedup(const TransitionModel &tmodel, BaseFloat speedup_factor, DecodableInterface *decodable, CompactLattice *clat)
This function is like RescoreCompactLattice, but it is modified to avoid computing probabilities on m...
void ComputePerSpkDerivedVars(Sgmm2PerSpkDerivedVars *vars) const
Computes the per-speaker derived vars; assumes vars->v_s is already set up.
bool RescoreCompactLattice(DecodableInterface *decodable, CompactLattice *clat)
This function *adds* the negated scores obtained from the Decodable object, to the acoustic scores on...
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)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
fst::VectorFst< CompactLatticeArc > CompactLattice
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
void SetSpeakerVector(const Vector< BaseFloat > &v_s_in)