28 int main(
int argc,
char *argv[]) {
30 using namespace kaldi;
32 typedef kaldi::int64 int64;
39 "Limit the number of arcs crossing any frame, to a specified maximum.\n" 40 "Requires an acoustic scale, because forward-backward Viterbi probs are\n" 41 "needed, which will be affected by this.\n" 43 "Usage: lattice-limit-depth [options] <lattice-rspecifier> <lattice-wspecifier>\n" 44 "E.g.: lattice-limit-depth --max-arcs-per-frame=1000 --acoustic-scale=0.1 ark:- ark:-\n";
48 int32 max_arcs_per_frame = 1000;
51 po.
Register(
"max-arcs-per-frame", &max_arcs_per_frame,
52 "Maximum number of arcs that are allowed to cross any given " 54 po.
Register(
"acoustic-scale", &acoustic_scale,
55 "Scaling factor for acoustic likelihoods");
66 std::string lats_rspecifier = po.
GetArg(1),
67 lats_wspecifier = po.
GetArg(2);
72 double sum_depth_in = 0.0, sum_depth_out = 0.0, total_t = 0.0;
73 for (; !clat_reader.
Done(); clat_reader.
Next()) {
75 std::string key = clat_reader.
Key();
91 KALDI_VLOG(2) <<
"For key " << key <<
", depth changed from " 92 << depth_in <<
" to " << depth_out <<
" over " 96 sum_depth_in += t * depth_in;
97 sum_depth_out += t * depth_out;
99 clat_writer.
Write(key, clat);
103 KALDI_LOG <<
"Done " << num_done <<
" lattices.";
104 KALDI_LOG <<
"Overall density changed from " << (sum_depth_in / total_t)
105 <<
" to " << (sum_depth_out / total_t);
106 if (num_done != 0)
return 0;
108 }
catch (
const std::exception &e) {
109 std::cerr << e.what();
fst::StdArc::StateId StateId
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature 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...
void Write(const std::string &key, const T &value) const
void Register(const std::string &name, bool *ptr, const std::string &doc)
std::vector< std::vector< double > > AcousticLatticeScale(double acwt)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
BaseFloat CompactLatticeDepth(const CompactLattice &clat, int32 *num_frames)
Returns the depth of the lattice, defined as the average number of arcs crossing any given frame...
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...
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
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
int main(int argc, char *argv[])
int NumArgs() const
Number of positional parameters (c.f. argc-1).
#define KALDI_ASSERT(cond)
void CompactLatticeLimitDepth(int32 max_depth_per_frame, CompactLattice *clat)
This function limits the depth of the lattice, per frame: that means, it does not allow more than a s...
void TopSortCompactLatticeIfNeeded(CompactLattice *clat)
Topologically sort the compact lattice if not already topologically sorted.