27 int main(
int argc,
char *argv[]) {
29 using namespace kaldi;
33 "From posteriors, compute transition-accumulators\n" 34 "The output is a vector of counts/soft-counts, indexed by transition-id)\n" 35 "Note: the model is only read in order to get the size of the vector\n" 37 "Usage: post-to-tacc [options] <model> <post-rspecifier> <accs>\n" 38 " e.g.: post-to-tacc --binary=false 1.mdl \"ark:ali-to-post 1.ali|\" 1.tacc\n" 39 "See also: get-post-on-ali\n";
44 po.
Register(
"binary", &binary,
"Write output in binary mode.");
45 po.
Register(
"per-pdf", &per_pdf,
"if ture, accumulate counts per pdf-id" 46 " rather than transition-id. (default: false)");
54 std::string model_rxfilename = po.
GetArg(1),
55 post_rspecifier = po.
GetArg(2),
56 accs_wxfilename = po.
GetArg(3);
60 int32 num_transition_ids;
63 Input ki(model_rxfilename, &binary_in);
72 for (; !posterior_reader.
Done(); posterior_reader.
Next()) {
74 int32 num_frames =
static_cast<int32
>(posterior.size());
75 for (int32
i = 0;
i < num_frames;
i++) {
76 for (int32
j = 0; j < static_cast<int32>(posterior[
i].size());
j++) {
77 int32 tid = posterior[
i][
j].first;
78 if (tid <= 0 || tid > num_transition_ids)
79 KALDI_ERR <<
"Invalid transition-id " << tid
80 <<
" encountered for utterance " 81 << posterior_reader.
Key();
82 transition_accs(tid) += posterior[
i][
j].second;
89 KALDI_LOG <<
"accumulate counts per pdf-id";
90 int32 num_pdf_ids = trans_model.
NumPdfs();
92 for (int32
i = 1;
i < num_transition_ids;
i++) {
94 pdf_accs(pid) += transition_accs(
i);
97 Output ko(accs_wxfilename, binary);
101 Output ko(accs_wxfilename, binary);
104 KALDI_LOG <<
"Done computing transition stats over " 105 << num_done <<
" utterances; wrote stats to " 107 return (num_done != 0 ? 0 : 1);
108 }
catch(
const std::exception &e) {
109 std::cerr << e.what();
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].
void Write(std::ostream &Out, bool binary) const
Writes to C++ stream (option to write in binary).
int32 TransitionIdToPdf(int32 trans_id) const
int main(int argc, char *argv[])
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...
int32 NumTransitionIds() const
Returns the total number of transition-ids (note, these are one-based).
void Read(std::istream &is, bool binary)
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.
int NumArgs() const
Number of positional parameters (c.f. argc-1).