32 using namespace kaldi;
34 using namespace kaldi;
38 "Cluster phones (or sets of phones) into sets for various purposes\n" 39 "Usage: cluster-phones [options] <tree-stats-in> <phone-sets-in> <clustered-phones-out>\n" 41 " cluster-phones 1.tacc phonesets.txt questions.txt\n";
52 std::string pdf_class_list_str =
"1";
53 std::string mode =
"questions";
54 int32 num_classes = -1;
58 po.Register(
"central-position", &P,
"Central position in context window [must match acc-tree-stats]");
59 po.Register(
"context-width", &N,
"Does not have any effect-- included for scripting convenience.");
60 po.Register(
"pdf-class-list", &pdf_class_list_str,
"Colon-separated list of HMM positions to consider [Default = 1: just central position for 3-state models].");
61 po.Register(
"mode", &mode,
"Mode of operation: \"questions\"->sets suitable for decision trees; \"k-means\"->k-means algorithm, output k classes (set num-classes options)\n");
62 po.Register(
"num-classes", &num_classes,
"For k-means mode, number of classes.");
67 if (po.NumArgs() != 3) {
73 std::string stats_rxfilename = po.GetArg(1),
74 phone_sets_rxfilename = po.GetArg(2),
75 phone_sets_wxfilename = po.GetArg(3);
82 Input ki(stats_rxfilename, &binary_in);
86 std::vector<int32> pdf_class_list;
88 || pdf_class_list.empty()) {
89 KALDI_ERR <<
"Invalid pdf-class-list string [expecting colon-separated list of integers]: " 90 << pdf_class_list_str;
93 std::vector<std::vector< int32> > phone_sets;
95 KALDI_ERR <<
"Could not read phone sets from " 98 if (phone_sets.size() == 0)
99 KALDI_ERR <<
"No phone sets in phone sets file ";
101 std::vector<std::vector<int32> > phone_sets_out;
103 if (mode ==
"questions") {
104 if (num_classes != -1)
105 KALDI_ERR <<
"num-classes option is not (currently) compatible " 106 "with \"questions\" mode.";
112 }
else if (mode ==
"k-means") {
113 if (num_classes <= 1 ||
114 static_cast<size_t>(num_classes) > phone_sets.size())
115 KALDI_ERR <<
"num-classes invalid: num_classes is " << num_classes
116 <<
", number of phone sets is " << phone_sets.size();
126 KALDI_ERR <<
"Error writing questions to " 129 KALDI_LOG <<
"Wrote questions to "<<phone_sets_wxfilename;
132 }
catch(
const std::exception &e) {
133 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
bool SplitStringToIntegers(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< I > *out)
Split a string (e.g.
void AutomaticallyObtainQuestions(BuildTreeStatsType &stats, const std::vector< std::vector< int32 > > &phone_sets_in, const std::vector< int32 > &all_pdf_classes_in, int32 P, std::vector< std::vector< int32 > > *questions_out)
Outputs sets of phones that are reasonable for questions to ask in the tree-building algorithm...
void DeleteBuildTreeStats(BuildTreeStatsType *stats)
This frees the Clusterable* pointers in "stats", where non-NULL, and sets them to NULL...
void ReadBuildTreeStats(std::istream &is, bool binary, const Clusterable &example, BuildTreeStatsType *stats)
Reads BuildTreeStats object.
The class ParseOptions is for parsing command-line options; see Parsing command-line options for more...
bool ReadIntegerVectorVectorSimple(const std::string &rxfilename, std::vector< std::vector< int32 > > *list)
bool WriteIntegerVectorVectorSimple(const std::string &wxfilename, const std::vector< std::vector< int32 > > &list)
std::string PrintableRxfilename(const std::string &rxfilename)
PrintableRxfilename turns the rxfilename into a more human-readable form for error reporting...
std::string PrintableWxfilename(const std::string &wxfilename)
PrintableWxfilename turns the wxfilename into a more human-readable form for error reporting...
std::vector< std::pair< EventType, Clusterable * > > BuildTreeStatsType
GaussClusterable wraps Gaussian statistics in a form accessible to generic clustering algorithms...
void KMeansClusterPhones(BuildTreeStatsType &stats, const std::vector< std::vector< int32 > > &phone_sets_in, const std::vector< int32 > &all_pdf_classes_in, int32 P, int32 num_classes, std::vector< std::vector< int32 > > *sets_out)
This function clusters the phones (or some initially specified sets of phones) into sets of phones...