30 int main(
int argc,
char *argv[]) {
31 using namespace kaldi;
35 "Given input posteriors, e.g. derived from lattice-to-post, and an alignment\n" 36 "typically derived from the best path of a lattice, outputs the probability in\n" 37 "the posterior of the corresponding index in the alignment, or zero if it was\n" 38 "not there. These are output as a vector of weights, one per utterance.\n" 39 "While, by default, lattice-to-post (as a source of posteriors) and sources of\n" 40 "alignments such as lattice-best-path will output transition-ids as the index,\n" 41 "it will generally make sense to either convert these to pdf-ids using\n" 42 "post-to-pdf-post and ali-to-pdf respectively, or to phones using post-to-phone-post\n" 43 "and (ali-to-phones --per-frame=true). Since this program only sees the integer\n" 44 "indexes, it does not care what they represent-- but of course they should match\n" 45 "(e.g. don't input posteriors with transition-ids and alignments with pdf-ids).\n" 46 "See http://kaldi-asr.org/doc/hmm.html#transition_model_identifiers for an\n" 47 "explanation of these types of indexes.\n" 49 "See also: post-to-tacc, weight-post, post-to-weights, reverse-weights\n" 51 "Usage: get-post-on-ali [options] <posteriors-rspecifier> <ali-rspecifier> <weights-wspecifier>\n" 52 "e.g.: get-post-on-ali ark:post.ark ark,s,cs:ali.ark ark:weights.ark\n";
63 std::string posteriors_rspecifier = po.
GetArg(1),
64 alignments_rspecifier = po.
GetArg(2),
65 confidences_wspecifier = po.
GetArg(3);
67 int32 num_done = 0, num_no_alignment = 0;
72 for (; !posterior_reader.
Done(); posterior_reader.
Next()) {
73 std::string key = posterior_reader.
Key();
74 if (!alignments_reader.
HasKey(key)) {
79 int32 num_frames =
static_cast<int32
>(posterior.size());
81 const std::vector<int32> &alignment = alignments_reader.
Value(key);
87 for(int32
i = 0;
i < num_frames;
i++) {
89 for(int32
j = 0;
j < posterior[
i].size();
j++) {
90 if(alignment[
i] == posterior[
i][
j].first) {
91 post_i = posterior[
i][
j].second;
95 confidence(
i) = post_i;
99 confidences_writer.
Write(key,confidence);
103 KALDI_LOG <<
"Done getting the posteriors under the alignment path for " 104 << num_done <<
" utterances. " << num_no_alignment <<
" with missing alignments.";
106 }
catch(
const std::exception &e) {
107 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
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.
bool HasKey(const std::string &key)
int NumArgs() const
Number of positional parameters (c.f. argc-1).
A class representing a vector.
#define KALDI_ASSERT(cond)