29 using namespace kaldi;
31 typedef kaldi::int64 int64;
34 "Computes dot-products between iVectors; useful in application of an\n" 35 "iVector-based system. The 'trials-file' has lines of the form\n" 37 "and the output will have the form\n" 38 "<key1> <key2> [<dot-product>]\n" 39 "(if either key could not be found, the dot-product field in the output\n" 40 "will be absent, and this program will print a warning)\n" 42 "Usage: ivector-compute-dot-products [options] <trials-in> " 43 "<ivector1-rspecifier> <ivector2-rspecifier> <scores-out>\n" 45 " ivector-compute-dot-products trials ark:train_ivectors.scp ark:test_ivectors.scp trials.scored\n" 46 "See also: ivector-plda-scoring\n";
52 if (po.NumArgs() != 4) {
57 std::string trials_rxfilename = po.GetArg(1),
58 ivector1_rspecifier = po.GetArg(2),
59 ivector2_rspecifier = po.GetArg(3),
60 scores_wxfilename = po.GetArg(4);
63 int64 num_done = 0, num_err = 0;
68 Input ki(trials_rxfilename);
71 Output ko(scores_wxfilename, binary);
72 double sum = 0.0, sumsq = 0.0;
75 while (std::getline(ki.Stream(), line)) {
76 std::vector<std::string> fields;
78 if (fields.size() != 2) {
79 KALDI_ERR <<
"Bad line " << (num_done + num_err) <<
" in input " 80 <<
"(expected two fields: key1 key2): " << line;
82 std::string key1 = fields[0], key2 = fields[1];
83 if (!ivector1_reader.HasKey(key1)) {
84 KALDI_WARN <<
"Key " << key1 <<
" not present in 1st table of ivectors.";
88 if (!ivector2_reader.HasKey(key2)) {
89 KALDI_WARN <<
"Key " << key2 <<
" not present in 2nd table of ivectors.";
94 &ivector2 = ivector2_reader.Value(key2);
100 sumsq += dot_prod * dot_prod;
102 ko.Stream() << key1 <<
' ' << key2 <<
' ' << dot_prod << std::endl;
106 BaseFloat mean = sum / num_done, scatter = sumsq / num_done,
107 variance = scatter - mean * mean, stddev = sqrt(variance);
108 KALDI_LOG <<
"Mean dot-product was " << mean <<
", standard deviation was " 111 KALDI_LOG <<
"Processed " << num_done <<
" trials " << num_err
113 return (num_done != 0 ? 0 : 1);
114 }
catch(
const std::exception &e) {
115 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...
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
void SplitStringToVector(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< std::string > *out)
Split a string using any of the single character delimiters.
A class representing a vector.
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.