39 int main(
int argc,
char *argv[]) {
40 using namespace kaldi;
44 "Convert a matrix of log-probabilities (e.g. from nnet-logprob) to posteriors\n" 45 "Usage: logprob-to-post [options] <logprob-matrix-rspecifier> <posteriors-wspecifier>\n" 47 " nnet-logprob [args] | logprob-to-post ark:- ark:1.post\n" 48 "Caution: in this particular example, the output would be posteriors of pdf-ids,\n" 49 "rather than transition-ids (c.f. post-to-pdf-post)\n";
54 bool random_prune =
true;
56 po.
Register(
"min-post", &min_post,
"Minimum posterior we will output (smaller " 57 "ones are pruned). Also see --random-prune");
58 po.
Register(
"random-prune", &random_prune,
"If true, prune posteriors with a " 59 "randomized method that preserves expectations.");
68 std::string logprob_rspecifier = po.
GetArg(1);
69 std::string posteriors_wspecifier = po.
GetArg(2);
75 for (; !logprob_reader.
Done(); logprob_reader.
Next()) {
80 for (int32
i = 0;
i < logprobs.
NumRows();
i++) {
82 for (int32
j = 0;
j < row.
Dim();
j++) {
85 post[
i].push_back(std::make_pair(
j, p));
86 }
else if (random_prune && (p / min_post) >=
RandUniform()) {
87 post[
i].push_back(std::make_pair(
j, min_post));
91 posterior_writer.
Write(logprob_reader.
Key(), post);
93 KALDI_LOG <<
"Converted " << num_done <<
" log-prob matrices to posteriors.";
94 return (num_done != 0 ? 0 : 1);
95 }
catch(
const std::exception &e) {
96 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
float RandUniform(struct RandomState *state=NULL)
Returns a random number strictly between 0 and 1.
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< 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...
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.
int NumArgs() const
Number of positional parameters (c.f. argc-1).
int main(int argc, char *argv[])
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...