29 using namespace kaldi;
33 "Scale posteriors with either a global scale, or a different scale for " 35 "Usage: scale-post <post-rspecifier> (<scale-rspecifier>|<scale>) <post-wspecifier>\n";
40 if (po.NumArgs() != 3) {
45 std::string post_rspecifier = po.GetArg(1),
46 scale_or_scale_rspecifier = po.GetArg(2),
47 post_wspecifier = po.GetArg(3);
49 double global_scale = 0.0;
53 KALDI_ERR <<
"Bad second argument " << scale_or_scale_rspecifier
54 <<
" (expected scale or scale rspecifier)";
55 scale_or_scale_rspecifier =
"";
63 int32 num_scaled = 0, num_no_scale = 0;
65 for (; !posterior_reader.Done(); posterior_reader.Next()) {
66 std::string key = posterior_reader.Key();
67 Posterior posterior = posterior_reader.Value();
68 posterior_reader.FreeCurrent();
69 if (scale_or_scale_rspecifier !=
"" && !scale_reader.HasKey(key)) {
72 BaseFloat post_scale = (scale_or_scale_rspecifier ==
"" ? global_scale
73 : scale_reader.Value(key));
76 posterior_writer.Write(key, posterior);
79 KALDI_LOG <<
"Done " << num_scaled <<
" posteriors; " << num_no_scale
81 return (num_scaled != 0 ? 0 : 1);
82 }
catch(
const std::exception &e) {
83 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
A templated class for writing objects to an archive or script file; see The Table concept...
RspecifierType ClassifyRspecifier(const std::string &rspecifier, std::string *rxfilename, RspecifierOptions *opts)
Allows random access to a collection of objects in an archive or script file; see The Table concept...
std::vector< std::vector< std::pair< int32, BaseFloat > > > Posterior
Posterior is a typedef for storing acoustic-state (actually, transition-id) posteriors over an uttera...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
bool ConvertStringToReal(const std::string &str, T *out)
ConvertStringToReal converts a string into either float or double and returns false if there was any ...
void ScalePosterior(BaseFloat scale, Posterior *post)
Scales the BaseFloat (weight) element in the posterior entries.