54 using namespace kaldi;
56 using namespace kaldi;
60 "Trains two-level decision tree. Outputs the larger tree, and a mapping from the\n" 61 "leaf-ids of the larger tree to those of the smaller tree. Useful, for instance,\n" 62 "in tied-mixture systems with multiple codebooks.\n" 64 "Usage: build-tree-two-level [options] <tree-stats-in> <roots-file> <questions-file> <topo-file> <tree-out> <mapping-out>\n" 66 " build-tree-two-level treeacc roots.txt 1.qst topo tree tree.map\n";
71 bool cluster_leaves =
true;
72 int32 max_leaves_first = 1000;
73 int32 max_leaves_second = 5000;
74 std::string occs_out_filename;
77 po.Register(
"binary", &binary,
"Write output in binary mode");
78 po.Register(
"context-width", &N,
"Context window size [must match " 80 po.Register(
"central-position", &P,
"Central position in context window " 81 "[must match acc-tree-stats]");
82 po.Register(
"max-leaves-first", &max_leaves_first,
"Maximum number of " 83 "leaves in first-level decision tree.");
84 po.Register(
"max-leaves-second", &max_leaves_second,
"Maximum number of " 85 "leaves in second-level decision tree.");
86 po.Register(
"cluster-leaves", &cluster_leaves,
"If true, do a post-clustering" 87 " of the leaves of the final decision tree.");
91 if (po.NumArgs() != 6) {
96 std::string stats_filename = po.GetArg(1),
97 roots_filename = po.GetArg(2),
98 questions_filename = po.GetArg(3),
99 topo_filename = po.GetArg(4),
100 tree_out_filename = po.GetArg(5),
101 map_out_filename = po.GetArg(6);
107 std::vector<std::vector<int32> > phone_sets;
108 std::vector<bool> is_shared_root;
109 std::vector<bool> is_split_root;
111 Input ki(roots_filename.c_str());
112 ReadRootsFile(ki.Stream(), &phone_sets, &is_shared_root, &is_split_root);
122 Input ki(stats_filename, &binary_in);
125 std::cerr <<
"Number of separate statistics is " << stats.size() <<
'\n';
131 Input ki(questions_filename, &binary_in);
132 qo.
Read(ki.Stream(), binary_in);
133 }
catch (
const std::exception &e) {
134 KALDI_ERR <<
"Error reading questions file "<<questions_filename<<
", error is: " << e.what();
139 std::vector<int32> phone2num_pdf_classes;
140 topo.GetPhoneToNumPdfClasses(&phone2num_pdf_classes);
144 std::vector<int32> mapping;
150 phone2num_pdf_classes,
167 Output ko(map_out_filename, binary);
173 std::vector<int32> all_phones;
174 for (
size_t i = 0;
i < phone_sets.size();
i++)
175 all_phones.insert(all_phones.end(),
176 phone_sets[
i].begin(), phone_sets[
i].end());
178 if (all_phones != topo.GetPhones()) {
179 std::ostringstream ss;
183 KALDI_WARN <<
"Mismatch between phone sets provided in roots file, and those in topology: " << ss.str();
185 std::vector<int32> phones_vec;
188 std::vector<int32> unseen_phones;
189 for (
size_t i = 0;
i < all_phones.size();
i++)
190 if (!std::binary_search(phones_vec.begin(), phones_vec.end(), all_phones[
i]))
191 unseen_phones.push_back(all_phones[
i]);
192 for (
size_t i = 0; i < phones_vec.size(); i++)
193 if (!std::binary_search(all_phones.begin(), all_phones.end(), phones_vec[
i]))
194 KALDI_ERR <<
"Phone "<< (phones_vec[
i]) <<
" appears in stats but is not listed in roots file.";
195 if (!unseen_phones.empty()) {
196 std::ostringstream ss;
197 for (
size_t i = 0; i < unseen_phones.size(); i++)
198 ss << unseen_phones[i] <<
' ';
202 KALDI_WARN <<
"Saw no stats for following phones: " << ss.str();
206 std::cerr <<
"Wrote tree and mapping\n";
209 }
catch(
const std::exception &e) {
210 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
EventMap * BuildTreeTwoLevel(Questions &qopts, const std::vector< std::vector< int32 > > &phone_sets, const std::vector< int32 > &phone2num_pdf_classes, const std::vector< bool > &share_roots, const std::vector< bool > &do_split, const BuildTreeStatsType &stats, int32 max_leaves_first, int32 max_leaves_second, bool cluster_leaves, int32 P, std::vector< int32 > *leaf_map)
BuildTreeTwoLevel builds a two-level tree, useful for example in building tied mixture systems with m...
This class defines, for each EventKeyType, a set of initial questions that it tries and also a number...
A class for storing topology information for phones.
void SortAndUniq(std::vector< T > *vec)
Sorts and uniq's (removes duplicates) from a vector.
void ReadKaldiObject(const std::string &filename, Matrix< float > *m)
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...
void Read(std::istream &is, bool binary)
void GetSeenPhones(BuildTreeStatsType &stats, int P, std::vector< int32 > *phones_out)
A class that is capable of representing a generic mapping from EventType (which is a vector of (key...
void WriteIntegerVector(std::ostream &os, bool binary, const std::vector< T > &v)
Function for writing STL vectors of integer types.
void WriteKaldiObject(const C &c, const std::string &filename, bool binary)
void ReadRootsFile(std::istream &is, std::vector< std::vector< int32 > > *phone_sets, std::vector< bool > *is_shared_root, std::vector< bool > *is_split_root)
Reads the roots file (throws on error).
std::vector< std::pair< EventType, Clusterable * > > BuildTreeStatsType
GaussClusterable wraps Gaussian statistics in a form accessible to generic clustering algorithms...