56 KALDI_WARN <<
"Weights must be positive; found: " << weight;
60 if (clat->Properties(fst::kTopSorted,
false) == 0) {
61 if (fst::TopSort(clat) ==
false) {
62 KALDI_WARN <<
"Cycles detected in lattice: cannot normalize.";
69 KALDI_WARN <<
"Failed to compute backward probabilities on lattice.";
74 StateId start = clat->Start();
75 BaseFloat total_backward_cost = beta[start];
77 total_backward_cost -=
Log(weight);
79 for (fst::StateIterator<CompactLattice> sit(*clat); !sit.Done(); sit.Next()) {
84 clat->SetFinal(sit.Value(), f);
92 vector<BaseFloat> *out) {
93 vector<BaseFloat> tmp;
95 if (tmp.size() != out->size()) {
96 KALDI_WARN <<
"Expecting " << out->size() <<
" weights, found " << tmp.size()
97 <<
": using uniform weights.";
101 for (vector<BaseFloat>::const_iterator itr = tmp.begin();
102 itr != tmp.end(); ++itr) {
104 KALDI_WARN <<
"Cannot use negative weight: " << *itr <<
"; input string: " 105 << full <<
"\n\tUsing uniform weights.";
111 KALDI_WARN <<
"Weights sum to " << sum <<
" instead of 1: renormalizing";
112 for (vector<BaseFloat>::iterator itr = tmp.begin();
113 itr != tmp.end(); ++itr)
122 int main(
int argc,
char *argv[]) {
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;
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) {
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();
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();
fst::StdArc::StateId StateId
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...
bool SplitStringToFloats(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< F > *out)
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...
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
int main(int argc, char *argv[])
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 ComputeCompactLatticeBetas(const CompactLattice &clat, vector< double > *beta)
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)
int Read(int argc, const char *const *argv)
Parses the command line options and fills the ParseOptions-registered variables.
std::string GetArg(int param) const
Returns one of the positional parameters; 1-based indexing for argc/argv compatibility.
fst::VectorFst< CompactLatticeArc > CompactLattice
RandomAccessTableReader< CompactLatticeHolder > RandomAccessCompactLatticeReader
int NumArgs() const
Number of positional parameters (c.f. argc-1).
#define KALDI_ASSERT(cond)
void SplitStringToWeights(const string &full, const char *delim, vector< BaseFloat > *out)
void SetWeight(const W &w)