30 int32 word_start_sym = 1, word_end_sym = 2;
32 std::vector<int32> phnx;
33 std::vector<int32>
words;
34 std::vector<std::vector<int32> > ans, ans_check;
41 std::vector<int32> phnx; phnx.push_back(3);
42 std::vector<int32>
words;
43 std::vector<std::vector<int32> > ans;
44 std::vector<std::vector<int32> > ans_check(1);
45 ans_check[0].push_back(0);
46 ans_check[0].push_back(3);
53 std::vector<int32> phnx; phnx.push_back(3); phnx.push_back(4);
54 std::vector<int32>
words;
55 std::vector<std::vector<int32> > ans;
56 std::vector<std::vector<int32> > ans_check(1);
57 ans_check[0].push_back(0);
58 ans_check[0].push_back(3);
59 ans_check[0].push_back(4);
66 std::vector<int32> phnx; phnx.push_back(3); phnx.push_back(4);
68 std::vector<int32>
words;
69 std::vector<std::vector<int32> > ans;
75 std::vector<int32> phnx; phnx.push_back(3); phnx.push_back(4);
76 phnx.push_back(word_end_sym);
77 std::vector<int32>
words;
78 std::vector<std::vector<int32> > ans;
85 std::vector<int32> phnx; phnx.push_back(3); phnx.push_back(4);
86 phnx.push_back(word_start_sym);
87 std::vector<int32>
words;
88 std::vector<std::vector<int32> > ans;
95 std::vector<int32> phnx; phnx.push_back(3); phnx.push_back(4);
96 phnx.push_back(word_start_sym); phnx.push_back(word_end_sym);
97 std::vector<int32>
words; words.push_back(100);
98 std::vector<std::vector<int32> > ans;
99 std::vector<std::vector<int32> > ans_check(2);
100 ans_check[0].push_back(0);
101 ans_check[0].push_back(3);
102 ans_check[0].push_back(4);
103 ans_check[1].push_back(100);
106 && ans == ans_check);
110 std::vector<int32> phnx; phnx.push_back(3); phnx.push_back(4);
111 phnx.push_back(word_start_sym); phnx.push_back(5); phnx.push_back(word_end_sym);
112 std::vector<int32>
words; words.push_back(100);
113 std::vector<std::vector<int32> > ans;
114 std::vector<std::vector<int32> > ans_check(2);
115 ans_check[0].push_back(0);
116 ans_check[0].push_back(3);
117 ans_check[0].push_back(4);
118 ans_check[1].push_back(100);
119 ans_check[1].push_back(5);
122 && ans == ans_check);
126 std::vector<int32> phnx;
127 phnx.push_back(word_start_sym); phnx.push_back(5); phnx.push_back(word_end_sym);
128 std::vector<int32>
words; words.push_back(100);
129 std::vector<std::vector<int32> > ans;
130 std::vector<std::vector<int32> > ans_check(1);
131 ans_check[0].push_back(100);
132 ans_check[0].push_back(5);
135 && ans == ans_check);
140 std::vector<int32> phnx;
141 phnx.push_back(word_start_sym); phnx.push_back(5); phnx.push_back(word_end_sym);
142 std::vector<int32>
words;
143 std::vector<std::vector<int32> > ans;
145 word_end_sym, &ans));
150 std::vector<int32> phnx;
151 phnx.push_back(word_start_sym); phnx.push_back(5); phnx.push_back(word_end_sym);
152 std::vector<int32>
words(2, 10);
153 std::vector<std::vector<int32> > ans;
155 word_end_sym, &ans));
160 std::vector<int32> phnx;
161 phnx.push_back(word_start_sym); phnx.push_back(5); phnx.push_back(word_end_sym);
162 std::vector<int32>
words(1, 0);
163 std::vector<std::vector<int32> > ans;
165 word_end_sym, &ans));
170 std::vector<int32> phnx;
171 phnx.push_back(word_start_sym); phnx.push_back(5);
172 phnx.push_back(7); phnx.push_back(word_end_sym);
174 std::vector<int32>
words; words.push_back(100);
175 std::vector<std::vector<int32> > ans;
176 std::vector<std::vector<int32> > ans_check(2);
177 ans_check[0].push_back(100);
178 ans_check[0].push_back(5);
179 ans_check[0].push_back(7);
180 ans_check[1].push_back(0);
181 ans_check[1].push_back(10);
184 && ans == ans_check);
206 std::vector<int32> phone_seq;
208 const std::vector<int32> &phone_list = trans_model->
GetPhones();
209 for (
int32 i = 0;
i < num_phones;
i++) {
210 int32 rand_phone = phone_list[
RandInt(0, phone_list.size() - 1)];
211 phone_seq.push_back(rand_phone);
213 bool reorder = (
RandInt(0, 1) == 0);
214 std::vector<int32> alignment;
216 phone_seq, &alignment);
217 std::vector<std::vector<int32> > split_alignment;
219 KALDI_ASSERT(split_alignment.size() == phone_seq.size());
220 for (
size_t i = 0;
i < split_alignment.size();
i++) {
222 for (
size_t j = 0;
j < split_alignment[
i].size();
j++) {
223 int32 transition_id = split_alignment[
i][
j];
233 bool old_reorder = (
RandInt(0, 1) == 1),
234 new_reorder = (
RandInt(0, 1) == 1),
235 new_tree = (
RandInt(0, 1) == 1),
236 new_topology = (
RandInt(0, 1) == 1);
242 KALDI_LOG <<
" old-reorder = " << old_reorder
243 <<
", new-reorder = " << new_reorder
244 <<
", new-tree = " << new_tree
245 <<
", subsample-factor = " << subsample_factor;
247 std::vector<int32> phones;
252 int32 N = 2 + rand() % 2,
255 std::vector<int32> num_pdf_classes_old,
260 true, &num_pdf_classes_old),
265 true, &num_pdf_classes_new);
267 num_pdf_classes_new = num_pdf_classes_old;
271 num_pdf_classes_new = num_pdf_classes_old;
272 ctx_dep_new = ctx_dep_old->
Copy();
277 topo_new = (new_topology ?
281 trans_model_new(*ctx_dep_new, topo_new);
283 std::vector<int32> phone_sequence;
285 for (
int32 i = 0;
i < phone_sequence_length;
i++)
286 phone_sequence.push_back(phones[
RandInt(0, phones.size() - 1)]);
287 std::vector<int32> old_alignment;
289 old_reorder, phone_sequence,
292 std::vector<int32> new_alignment;
295 old_alignment, subsample_factor,
false,
296 new_reorder, NULL, &new_alignment);
302 std::vector<std::vector<int32> > old_split, new_split;
303 bool b1 =
SplitToPhones(trans_model_old, old_alignment, &old_split),
304 b2 =
SplitToPhones(trans_model_new, new_alignment, &new_split);
307 for (
size_t i = 0;
i < new_split.size();
i++)
308 KALDI_ASSERT(trans_model_old.TransitionIdToPhone(old_split[
i].front()) ==
310 if (!new_topology && subsample_factor == 1) {
312 std::vector<int32> old_alignment_copy;
314 new_alignment, subsample_factor,
false,
315 old_reorder, NULL, &old_alignment_copy);
337 std::cout <<
"Test OK.\n";
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
ContextDependency * GenRandContextDependencyLarge(const std::vector< int32 > &phone_ids, int N, int P, bool ensure_all_covered, std::vector< int32 > *hmm_lengths)
GenRandContextDependencyLarge is like GenRandContextDependency but generates a larger tree with speci...
A class for storing topology information for phones.
const std::vector< int32 > & GetPhones() const
Returns a sorted, unique list of phones.
void TestAccumulateTreeStatsOptions()
bool ConvertPhnxToProns(const std::vector< int32 > &phnx, const std::vector< int32 > &words, int32 word_start_sym, int32 word_end_sym, std::vector< std::vector< int32 > > *prons)
ContextDependency * MonophoneContextDependency(const std::vector< int32 > &phones, const std::vector< int32 > &phone2num_pdf_classes)
std::vector< int32 > phone_map
virtual ContextDependencyInterface * Copy() const =0
Returns pointer to new object which is copy of current one.
bool SplitToPhones(const TransitionModel &trans_model, const std::vector< int32 > &alignment, std::vector< std::vector< int32 > > *split_alignment)
SplitToPhones splits up the TransitionIds in "alignment" into their individual phones (one vector per...
HmmTopology GenRandTopology(const std::vector< int32 > &phones_in, const std::vector< int32 > &num_pdf_classes)
This method of generating an arbitrary HmmTopology object allows you to specify the number of pdf-cla...
std::string ci_phones_str
void GenerateRandomAlignment(const ContextDependencyInterface &ctx_dep, const TransitionModel &trans_model, bool reorder, const std::vector< int32 > &phone_sequence, std::vector< int32 > *alignment)
For use in test code, this function generates an alignment (a sequence of transition-ids) correspondi...
std::vector< int32 > ci_phones
context-dep-itf.h provides a link between the tree-building code in ../tree/, and the FST code in ...
void TestConvertAlignment()
#define KALDI_ASSERT(cond)
std::string phone_map_rxfilename
TransitionModel * GenRandTransitionModel(ContextDependency **ctx_dep_out)
int32 TransitionIdToPhone(int32 trans_id) const
bool ConvertAlignment(const TransitionModel &old_trans_model, const TransitionModel &new_trans_model, const ContextDependencyInterface &new_ctx_dep, const std::vector< int32 > &old_alignment, int32 subsample_factor, bool repeat_frames, bool new_is_reordered, const std::vector< int32 > *phone_map, std::vector< int32 > *new_alignment)
ConvertAlignment converts an alignment that was created using one model, to another model...
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)
void TestConvertPhnxToProns()