26 int main(
int argc,
char *argv[]) {
28 using namespace kaldi;
31 int32 length_tolerance = 2;
34 "Takes archives (typically per-utterance) of posteriors and per-frame weights,\n" 35 "and weights the posteriors by the per-frame weights\n" 37 "Usage: weight-post <post-rspecifier> <weights-rspecifier> <post-wspecifier>\n";
41 po.
Register(
"length-tolerance", &length_tolerance,
42 "Tolerate this many frames of length mismatch between " 43 "posteriors and weights");
52 std::string post_rspecifier = po.
GetArg(1),
53 weights_rspecifier = po.
GetArg(2),
54 post_wspecifier = po.
GetArg(3);
60 int32 num_done = 0, num_err = 0;
62 for (; !posterior_reader.
Done(); posterior_reader.
Next()) {
63 std::string key = posterior_reader.
Key();
65 if (!weights_reader.
HasKey(key)) {
66 KALDI_WARN <<
"No weights for utterance " << key;
71 if (std::abs(weights.
Dim() -
static_cast<int32
>(post.size())) >
74 <<
" have wrong size, " << weights.
Dim()
75 <<
" vs. " << post.size();
79 for (
size_t i = 0;
i < post.size();
i++) {
80 if (weights(
i) == 0.0) post[
i].clear();
81 for (
size_t j = 0;
j < post[
i].size();
j++)
82 post[
i][
j].second *=
i < weights.
Dim() ? weights(
i) : 0.0;
84 post_writer.
Write(key, post);
87 KALDI_LOG <<
"Scaled " << num_done <<
" posteriors; errors on " << num_err;
88 return (num_done != 0 ? 0 : 1);
89 }
catch(
const std::exception &e) {
90 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
int main(int argc, char *argv[])
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)
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...
const T & Value(const std::string &key)
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.
MatrixIndexT Dim() const
Returns the dimension of the vector.
bool HasKey(const std::string &key)
int NumArgs() const
Number of positional parameters (c.f. argc-1).
A class representing a vector.