124 using namespace kaldi;
128 "Combine lattices generated by different systems by removing the total\n" 129 "cost of all paths (backward cost) from individual lattices and doing\n" 130 "a union of the reweighted lattices. Note: the acoustic and LM scales\n" 131 "that this program applies are not removed before outputting the lattices.\n" 132 "Intended for use in system combination prior to MBR decoding, see comments\n" 134 "Usage: lattice-combine [options] <lattice-rspecifier1> <lattice-rspecifier2>" 135 " [<lattice-rspecifier3> ... ] <lattice-wspecifier>\n" 136 "E.g.: lattice-combine 'ark:gunzip -c foo/lat.1.gz|' 'ark:gunzip -c bar/lat.1.gz|' ark:- | ...\n";
139 BaseFloat acoustic_scale = 1.0, inv_acoustic_scale = 1.0, lm_scale = 1.0;
141 po.Register(
"acoustic-scale", &acoustic_scale,
"Scaling factor for " 142 "acoustic likelihoods");
143 po.Register(
"inv-acoustic-scale", &inv_acoustic_scale,
"An alternative way " 144 "of setting the acoustic scale: you can set its inverse.");
145 po.Register(
"lm-scale", &lm_scale,
"Scaling factor for language model " 147 po.Register(
"lat-weights", &weight_str,
"Colon-separated list of weights " 148 "for each rspecifier (which should sum to 1), e.g. '0.2:0.8'");
152 KALDI_ASSERT(acoustic_scale == 1.0 || inv_acoustic_scale == 1.0);
153 if (inv_acoustic_scale != 1.0)
154 acoustic_scale = 1.0 / inv_acoustic_scale;
157 int32 num_args = po.NumArgs();
163 string lats_rspecifier1 = po.GetArg(1),
164 lats_wspecifier = po.GetArg(num_args);
171 vector<RandomAccessCompactLatticeReader*> clat_reader_vec(
172 num_args-2, static_cast<RandomAccessCompactLatticeReader*>(NULL));
173 vector<string> clat_rspec_vec(num_args-2);
174 for (int32
i = 2;
i < num_args; ++
i) {
176 clat_rspec_vec[
i-2] = po.GetArg(
i);
179 vector<BaseFloat> lat_weights(num_args-1, 1.0/(num_args-1));
180 if (!weight_str.empty())
183 int32 n_utts = 0, n_total_lats = 0, n_success = 0, n_missing = 0,
188 for (; !clat_reader1.Done(); clat_reader1.Next()) {
189 std::string key = clat_reader1.Key();
191 clat_reader1.FreeCurrent();
197 KALDI_WARN <<
"Could not normalize lattice for system 1, utterance: " 203 for (int32
i = 0;
i < num_args-2; ++
i) {
204 if (clat_reader_vec[
i]->HasKey(key)) {
210 KALDI_WARN <<
"Could not normalize lattice for system "<< (
i + 2)
211 <<
", utterance: " << key;
215 fst::Union(&clat1, clat2);
217 KALDI_WARN <<
"No lattice found for utterance " << key <<
" for " 218 <<
"system " << (
i + 2) <<
", rspecifier: " 219 << clat_rspec_vec[
i];
224 clat_writer.Write(key, clat1);
228 KALDI_LOG <<
"Processed " << n_utts <<
" utterances: with a total of " 229 << n_total_lats <<
" lattices across " << (num_args-1)
230 <<
" different systems";
231 KALDI_LOG <<
"Produced output for " << n_success <<
" utterances; " 232 << n_missing <<
" total missing lattices and " << n_other_errors
233 <<
" total lattices had errors in processing.";
237 return (n_success != 0 && n_missing < (n_success - n_missing) ? 0 : 1);
238 }
catch(
const std::exception &e) {
239 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void DeletePointers(std::vector< A *> *v)
Deletes any non-NULL pointers in the vector v, and sets the corresponding entries of v to NULL...
A templated class for writing objects to an archive or script file; see The Table concept...
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...
bool CompactLatticeNormalize(CompactLattice *clat, BaseFloat weight)
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
std::vector< std::vector< double > > LatticeScale(double lmwt, double acwt)
fst::VectorFst< CompactLatticeArc > CompactLattice
RandomAccessTableReader< CompactLatticeHolder > RandomAccessCompactLatticeReader
#define KALDI_ASSERT(cond)
void SplitStringToWeights(const string &full, const char *delim, vector< BaseFloat > *out)