25 using namespace kaldi;
30 std::string model = po.
GetArg(1),
31 vector_rspecifier = po.
GetArg(2),
32 log_posteriors_wspecifier = po.
GetArg(3);
37 std::vector<Vector<BaseFloat> > vectors;
40 std::vector<std::string> utt_list;
41 int32 num_utt_done = 0;
43 for (; !vector_reader.
Done(); vector_reader.
Next()) {
44 std::string utt = vector_reader.
Key();
50 posterior_writer.
Write(utt, log_posteriors);
53 KALDI_LOG <<
"Calculated log posteriors for " << num_utt_done <<
" vectors.";
54 return (num_utt_done == 0 ? 1 : 0);
59 std::string model_rspecifier = po.
GetArg(1),
60 trials_rspecifier = po.
GetArg(2),
61 vector_rspecifier = po.
GetArg(3),
68 std::vector<Vector<BaseFloat> > vectors;
69 std::vector<int32> ys;
70 std::vector<std::string> utt_list;
71 int32 num_utt_done = 0, num_utt_err = 0;
74 for (; !class_reader.
Done(); class_reader.
Next()) {
75 std::string utt = class_reader.
Key();
77 if (!vector_reader.
HasKey(utt)) {
78 KALDI_WARN <<
"No vector for utterance " << utt;
81 utt_list.push_back(utt);
82 ys.push_back(class_label);
84 vectors.push_back(vector);
89 if (vectors.empty()) {
95 for (
int i = 0;
i < vectors.size();
i++) {
96 xs.
Row(
i).CopyFromVec(vectors[
i]);
103 Output ko(scores_out.c_str(), binary);
108 for (
int i = 0;
i < ys.size();
i++) {
109 ko.Stream() << utt_list[
i] <<
" " << ys[
i] <<
" " << log_posteriors(
i, ys[
i]) << std::endl;
111 KALDI_LOG <<
"Calculated scores for " << num_utt_done
113 << num_utt_err <<
" missing. ";
114 return (num_utt_done == 0 ? 1 : 0);
117 int main(
int argc,
char *argv[]) {
118 using namespace kaldi;
122 "Evaluates a model on input vectors and outputs either\n" 123 "log posterior probabilities or scores.\n" 124 "Usage1: logistic-regression-eval <model> <input-vectors-rspecifier>\n" 125 " <output-log-posteriors-wspecifier>\n" 126 "Usage2: logistic-regression-eval <model> <trials-file> <input-vectors-rspecifier>\n" 127 " <output-scores-file>\n";
131 bool apply_log =
true;
132 po.
Register(
"apply-log", &apply_log,
133 "If false, apply Exp to the log posteriors output. This is " 134 "helpful when combining posteriors from multiple logistic " 135 "regression models.");
151 }
catch(
const std::exception &e) {
152 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
int32 ComputeScores(ParseOptions &po, const LogisticRegressionConfig &config, bool apply_log)
void ApplyExp()
Apply exponential to each value in vector.
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)
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
Allows random access to a collection of objects in an archive or script file; see The Table concept...
void GetLogPosteriors(const Matrix< BaseFloat > &xs, Matrix< BaseFloat > *log_posteriors)
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
int ComputeLogPosteriors(ParseOptions &po, const LogisticRegressionConfig &config, bool apply_log)
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
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)
void Register(OptionsItf *opts)
int main(int argc, char *argv[])
int NumArgs() const
Number of positional parameters (c.f. argc-1).
A class representing a vector.