compute-eer.cc File Reference
Include dependency graph for compute-eer.cc:

Go to the source code of this file.

Namespaces

 kaldi
 This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for mispronunciations detection tasks, the reference:
 

Functions

BaseFloat ComputeEer (std::vector< BaseFloat > *target_scores, std::vector< BaseFloat > *nontarget_scores, BaseFloat *threshold)
 ComputeEer computes the Equal Error Rate (EER) for the given scores and returns it as a proportion beween 0 and 1. More...
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 77 of file compute-eer.cc.

References kaldi::ComputeEer(), kaldi::ConvertStringToReal(), ParseOptions::GetArg(), KALDI_ERR, KALDI_LOG, ParseOptions::NumArgs(), ParseOptions::PrintUsage(), ParseOptions::Read(), kaldi::SplitStringToVector(), and Input::Stream().

77  {
78  using namespace kaldi;
79  typedef kaldi::int32 int32;
80  try {
81  const char *usage =
82  "Computes Equal Error Rate\n"
83  "Input is a series of lines, each with two fields.\n"
84  "The first field must be a numeric score, and the second\n"
85  "either the string 'target' or 'nontarget'. \n"
86  "The EER will be printed to the standard output.\n"
87  "\n"
88  "Usage: compute-eer <scores-in>\n"
89  "e.g.: compute-eer -\n";
90 
91  ParseOptions po(usage);
92  po.Read(argc, argv);
93 
94  if (po.NumArgs() != 1) {
95  po.PrintUsage();
96  exit(1);
97  }
98 
99  std::string scores_rxfilename = po.GetArg(1);
100 
101  std::vector<BaseFloat> target_scores, nontarget_scores;
102  Input ki(scores_rxfilename);
103 
104  std::string line;
105  while (std::getline(ki.Stream(), line)) {
106  std::vector<std::string> split_line;
107  SplitStringToVector(line, " \t", true, &split_line);
108  BaseFloat score;
109  if (split_line.size() != 2) {
110  KALDI_ERR << "Invalid input line (must have two fields): "
111  << line;
112  }
113  if (!ConvertStringToReal(split_line[0], &score)) {
114  KALDI_ERR << "Invalid input line (first field must be float): "
115  << line;
116  }
117  if (split_line[1] == "target")
118  target_scores.push_back(score);
119  else if (split_line[1] == "nontarget")
120  nontarget_scores.push_back(score);
121  else {
122  KALDI_ERR << "Invalid input line (second field must be "
123  << "'target' or 'nontarget')";
124  }
125  }
126  if (target_scores.empty() && nontarget_scores.empty())
127  KALDI_ERR << "Empty input.";
128  if (target_scores.empty())
129  KALDI_ERR << "No target scores seen.";
130  if (nontarget_scores.empty())
131  KALDI_ERR << "No non-target scores seen.";
132 
133  BaseFloat threshold;
134  BaseFloat eer = ComputeEer(&target_scores, &nontarget_scores, &threshold);
135 
136  KALDI_LOG << "Equal error rate is " << (100.0 * eer)
137  << "%, at threshold " << threshold;
138 
139  std::cout.precision(4);
140  std::cout << (100.0 * eer);
141 
142  return 0;
143  } catch(const std::exception &e) {
144  std::cerr << e.what();
145  return -1;
146  }
147 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
kaldi::int32 int32
float BaseFloat
Definition: kaldi-types.h:29
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
Definition: parse-options.h:36
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.
Definition: text-utils.cc:63
#define KALDI_ERR
Definition: kaldi-error.h:147
bool ConvertStringToReal(const std::string &str, T *out)
ConvertStringToReal converts a string into either float or double and returns false if there was any ...
Definition: text-utils.cc:238
BaseFloat ComputeEer(std::vector< BaseFloat > *target_scores, std::vector< BaseFloat > *nontarget_scores, BaseFloat *threshold)
ComputeEer computes the Equal Error Rate (EER) for the given scores and returns it as a proportion be...
Definition: compute-eer.cc:48
#define KALDI_LOG
Definition: kaldi-error.h:153