28 int main(
int argc,
char *argv[]) {
29 using namespace kaldi;
34 "Compute WER by comparing different transcriptions\n" 35 "Takes two transcription files, in integer or text format,\n" 36 "and outputs overall WER statistics to standard output.\n" 38 "Usage: compute-wer [options] <ref-rspecifier> <hyp-rspecifier>\n" 39 "E.g.: compute-wer --text --mode=present ark:data/train/text ark:hyp_text\n" 40 "See also: align-text,\n" 41 "Example scoring script: egs/wsj/s5/steps/score_kaldi.sh\n";
45 std::string mode =
"strict";
47 "Scoring mode: \"present\"|\"all\"|\"strict\":\n" 48 " \"present\" means score those we have transcriptions for\n" 49 " \"all\" means treat absent transcriptions as empty\n" 50 " \"strict\" means die if all in ref not also in hyp");
53 po.
Register(
"text", &dummy,
"Deprecated option! Keeping for compatibility reasons.");
62 std::string ref_rspecifier = po.
GetArg(1);
63 std::string hyp_rspecifier = po.
GetArg(2);
65 if (mode !=
"strict" && mode !=
"present" && mode !=
"all") {
66 KALDI_ERR <<
"--mode option invalid: expected \"present\"|\"all\"|\"strict\", got " 70 int32 num_words = 0, word_errs = 0, num_sent = 0, sent_errs = 0,
71 num_ins = 0, num_del = 0, num_sub = 0, num_absent_sents = 0;
78 for (; !ref_reader.
Done(); ref_reader.
Next()) {
79 std::string key = ref_reader.
Key();
80 const std::vector<std::string> &ref_sent = ref_reader.
Value();
81 std::vector<std::string> hyp_sent;
82 if (!hyp_reader.
HasKey(key)) {
84 KALDI_ERR <<
"No hypothesis for key " << key <<
" and strict " 87 if (mode ==
"present")
90 hyp_sent = hyp_reader.
Value(key);
92 num_words += ref_sent.size();
100 sent_errs += (ref_sent != hyp_sent);
105 / static_cast<BaseFloat>(num_words);
107 / static_cast<BaseFloat>(num_sent);
110 std::cout.precision(2);
111 std::cerr.precision(2);
112 std::cout <<
"%WER " << std::fixed << percent_wer <<
" [ " << word_errs
113 <<
" / " << num_words <<
", " << num_ins <<
" ins, " 114 << num_del <<
" del, " << num_sub <<
" sub ]" 115 << (num_absent_sents != 0 ?
" [PARTIAL]" :
"") <<
'\n';
116 std::cout <<
"%SER " << std::fixed << percent_ser <<
" [ " 117 << sent_errs <<
" / " << num_sent <<
" ]\n";
118 std::cout <<
"Scored " << num_sent <<
" sentences, " 119 << num_absent_sents <<
" not present in hyp.\n";
122 }
catch(
const std::exception &e) {
123 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void PrintUsage(bool print_command_line=false)
Prints the usage documentation [provided in the constructor].
void Register(const std::string &name, bool *ptr, const std::string &doc)
Allows random access to a collection of objects in an archive or script file; see The Table concept...
int32 LevenshteinEditDistance(const std::vector< T > &a, const std::vector< T > &b)
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).
int main(int argc, char *argv[])