66 using namespace kaldi;
69 "Compare vectors of integers (e.g. phone alignments)\n" 70 "Prints to stdout fields of the form:\n" 71 "<utterance-id> <num-frames-in-utterance> <num-frames-that-differ>\n" 74 " SWB1_A_31410_32892 420 36\n" 77 "compare-int-vector [options] <vector1-rspecifier> <vector2-rspecifier>\n" 79 "e.g. compare-int-vector scp:foo.scp scp:bar.scp > comparison\n" 80 "E.g. the inputs might come from ali-to-phones.\n" 81 "Warnings are printed if the vector lengths differ for a given utterance-id,\n" 82 "and in those cases, the number of frames printed will be the smaller of the\n" 84 "See also: ali-to-phones, copy-int-vector\n";
89 std::string tot_wxfilename,
91 confusion_matrix_wxfilename;
94 po.Register(
"binary", &binary,
"If true, write in binary mode (only applies " 95 "if --write-tot-counts or --write-diff-counts options are supplied).");
96 po.Register(
"write-tot-counts", &tot_wxfilename,
"Filename to write " 97 "vector of total counts. These may be summed with 'vector-sum'.");
98 po.Register(
"write-diff-counts", &diff_wxfilename,
"Filename to write " 99 "vector of counts of phones (or whatever is in the inputs) " 100 "that differ from one vector to the other. Each time a pair differs, " 101 "0.5 will be added to each one's location.");
102 po.Register(
"write-confusion-matrix", &confusion_matrix_wxfilename,
103 "Filename to write confusion matrix, indexed by [phone1][phone2]." 104 "These may be summed by 'matrix-sum'.");
108 if (po.NumArgs() != 2) {
113 std::string vector1_rspecifier = po.GetArg(1),
114 vector2_rspecifier = po.GetArg(2);
118 num_mismatched_lengths = 0,
119 tot_frames = 0, tot_difference = 0;
121 std::vector<double> diff_counts;
122 std::vector<double> tot_counts;
128 for (; !reader1.Done(); reader1.Next(), num_done++) {
129 const std::string &key = reader1.Key();
130 if (!reader2.HasKey(key)) {
131 KALDI_WARN <<
"No key " << key <<
" found in second input.";
135 const std::vector<int32> &value1 = reader1.Value(),
136 &value2 = reader2.Value(key);
137 size_t len1 = value1.size(), len2 = value2.size();
139 KALDI_WARN <<
"For utterance " << key <<
", lengths differ " 140 << len1 <<
" vs. " << len2;
141 num_mismatched_lengths++;
143 size_t len = std::min(len1, len2),
145 for (
size_t i = 0;
i < len;
i++) {
146 int32 phone1 = value1[
i], phone2 = value2[
i];
147 if (phone1 != phone2) {
149 if (!diff_wxfilename.empty()) {
154 if (!tot_wxfilename.empty())
156 if (!confusion_matrix_wxfilename.empty())
160 std::cout << key <<
" " << len <<
" " << difference <<
"\n";
162 tot_difference += difference;
165 BaseFloat difference_percent = tot_difference * 100.0 / tot_frames;
166 KALDI_LOG <<
"Computed difference for " << num_done <<
" utterances, of which " 167 << num_mismatched_lengths <<
" had mismatched lengths; corresponding " 168 "utterance not found for " << num_not_found;
169 KALDI_LOG <<
"Average p(different) is " << std::setprecision(4) << difference_percent
170 <<
"%, over " << tot_frames <<
" frames.";
172 if (!tot_wxfilename.empty())
174 if (!diff_wxfilename.empty())
176 if (!confusion_matrix_wxfilename.empty())
179 return (num_done != 0 ? 0 : 1);
180 }
catch(
const std::exception &e) {
181 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Allows random access to a collection of objects in an archive or script file; see The Table concept...
void WriteAsKaldiVector(const std::vector< double > &counts, std::string &wxfilename, bool binary)
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...
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
void AddToCount(int32 location_to_add, double value_to_add, std::vector< double > *counts)
void AddToConfusionMatrix(int32 phone1, int32 phone2, Matrix< double > *counts)