34 std::vector<int32> *simple_labels) {
35 size_t num_frames = eg.
labels.size();
36 for (
int32 t = 0; t < num_frames; t++)
37 if (eg.
labels[t].size() != 1 || eg.
labels[t][0].second != 1.0)
39 simple_labels->resize(num_frames);
40 for (
int32 t = 0; t < num_frames; t++)
41 (*simple_labels)[t] = eg.
labels[t][0].first;
54 std::vector<int32> simple_labels;
62 for (
int32 t = 0; t < num_frames; t++) {
87 if (!strcmp(token.c_str(),
"<Lab1>")) {
88 std::vector<int32> simple_labels;
90 labels.resize(simple_labels.size());
91 for (
size_t i = 0;
i < simple_labels.size();
i++) {
93 labels[
i][0].first = simple_labels[
i];
96 }
else if (!strcmp(token.c_str(),
"<Lab2>")) {
100 labels.resize(num_frames);
101 for (
int32 t = 0; t < num_frames; t++) {
111 }
else if (!strcmp(token.c_str(),
"<Labels>")) {
121 KALDI_ERR <<
"Expected token <Lab1>, <Lab2> or <Labels>, got " << token;
137 labels[frame].push_back(std::make_pair(pdf_id, weight));
145 if (
labels[frame][
i].second > max) {
146 pdf_id =
labels[frame][
i].first;
150 if (weight != NULL) *weight = max;
161 int32 new_num_frames,
162 int32 new_left_context,
165 if (start_frame < 0) start_frame = 0;
168 if (start_frame + new_num_frames > num_label_frames || new_num_frames == -1)
169 new_num_frames = num_label_frames - start_frame;
171 int32 input_right_context =
173 if (new_left_context == -1) new_left_context = input.
left_context;
174 if (new_right_context == -1) new_right_context = input_right_context;
176 if (!nnet_example_warned_left) {
177 nnet_example_warned_left =
true;
178 KALDI_WARN <<
"Requested left-context " << new_left_context
180 <<
", will not warn again.";
184 if (new_right_context > input_right_context) {
187 KALDI_WARN <<
"Requested right-context " << new_right_context
188 <<
" exceeds input right-context " << input_right_context
189 <<
", will not warn again.";
191 new_right_context = input_right_context;
194 int32 new_tot_frames = new_left_context + new_num_frames + new_right_context,
195 left_frames_lost = (input.
left_context - new_left_context) + start_frame;
205 input.
labels.begin() + start_frame,
206 input.
labels.begin() + start_frame + new_num_frames);
210 std::vector<NnetExample> *examples) {
212 empty_semaphore_.Wait();
214 examples_.swap(*examples);
215 full_semaphore_.Signal();
219 empty_semaphore_.Wait();
222 full_semaphore_.Signal();
226 std::vector<NnetExample> *examples) {
227 full_semaphore_.Wait();
230 full_semaphore_.Signal();
235 examples->swap(examples_);
236 empty_semaphore_.Signal();
246 WriteToken(os, binary,
"<DiscriminativeNnetExample>");
254 KALDI_ERR <<
"Error writing CompactLattice to stream";
260 cm.
Write(os, binary);
266 WriteToken(os, binary,
"</DiscriminativeNnetExample>");
273 ExpectToken(is, binary,
"<DiscriminativeNnetExample>");
282 KALDI_ERR <<
"Error reading CompactLattice from stream";
284 den_lat = *den_lat_tmp;
292 ExpectToken(is, binary,
"</DiscriminativeNnetExample>");
298 int32 num_frames =
static_cast<int32>(num_ali.size());
301 std::vector<int32> times;
CompressedMatrix input_frames
The input data, with NumRows() >= labels.size() + left_context; it includes features to the left and ...
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
NnetExample is the input data and corresponding label (or labels) for one or more frames of input...
void AcceptExamples(std::vector< NnetExample > *examples)
The following function is called by the code that reads in the examples, with a batch of examples...
void Swap(CompressedMatrix *other)
void ReadBasicType(std::istream &is, bool binary, T *t)
ReadBasicType is the name of the read function for bool, integer types, and floating-point types...
int32 left_context
The number of frames of left context (we can work out the #frames of right context from input_frames...
void ExamplesDone()
The following function is called by the code that reads in the examples, when we're done reading exam...
void Read(std::istream &is, bool binary)
void ReadToken(std::istream &is, bool binary, std::string *str)
ReadToken gets the next token and puts it in str (exception on failure).
void Write(std::ostream &os, bool binary) const
void Read(std::istream &is, bool binary)
void Write(std::ostream &os, bool binary) const
void ReadIntegerVector(std::istream &is, bool binary, std::vector< T > *v)
Function for reading STL vector of integer types.
void ExpectToken(std::istream &is, bool binary, const char *token)
ExpectToken tries to read in the given token, and throws an exception on failure. ...
static bool nnet_example_warned_right
bool ProvideExamples(std::vector< NnetExample > *examples)
This function is called by the code that does the training.
bool HasSimpleLabels(const NnetExample &eg, std::vector< int32 > *simple_labels)
int32 CompactLatticeStateTimes(const CompactLattice &lat, vector< int32 > *times)
As LatticeStateTimes, but in the CompactLattice format.
void WriteToken(std::ostream &os, bool binary, const char *token)
The WriteToken functions are for writing nonempty sequences of non-space characters.
fst::VectorFst< CompactLatticeArc > CompactLattice
int32 GetLabelSingle(int32 frame, BaseFloat *weight=NULL)
Get the maximum weight label (pdf_id and weight) of this frame of this example.
MatrixIndexT NumRows() const
Returns number of rows (or zero for emtpy matrix).
#define KALDI_ASSERT(cond)
bool WriteCompactLattice(std::ostream &os, bool binary, const CompactLattice &t)
void WriteIntegerVector(std::ostream &os, bool binary, const std::vector< T > &v)
Function for writing STL vectors of integer types.
void WriteBasicType(std::ostream &os, bool binary, T t)
WriteBasicType is the name of the write function for bool, integer types, and floating-point types...
static bool nnet_example_warned_left
std::vector< std::vector< std::pair< int32, BaseFloat > > > labels
The label(s) for each frame in a sequence of frames; in the normal case, this will be just [ [ (pdf-i...
MatrixIndexT NumCols() const
Returns number of columns (or zero for emtpy matrix).
void SetLabelSingle(int32 frame, int32 pdf_id, BaseFloat weight=1.0)
Set the label of this frame of this example to the specified pdf_id with the specified weight...
bool ReadCompactLattice(std::istream &is, bool binary, CompactLattice **clat)
void Read(std::istream &is, bool binary)
void Write(std::ostream &os, bool binary) const
Vector< BaseFloat > spk_info
The speaker-specific input, if any, or an empty vector if we're not using this features.