nnet-example.h
Go to the documentation of this file.
1 // nnet2/nnet-example.h
2 
3 // Copyright 2012 Johns Hopkins University (author: Daniel Povey)
4 // 2014 Vimal Manohar
5 
6 // See ../../COPYING for clarification regarding multiple authors
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 // MERCHANTABLITY OR NON-INFRINGEMENT.
18 // See the Apache 2 License for the specific language governing permissions and
19 // limitations under the License.
20 
21 #ifndef KALDI_NNET2_NNET_EXAMPLE_H_
22 #define KALDI_NNET2_NNET_EXAMPLE_H_
23 
24 #include "nnet2/nnet-nnet.h"
25 #include "util/table-types.h"
26 #include "lat/kaldi-lattice.h"
27 #include "util/kaldi-semaphore.h"
28 
29 namespace kaldi {
30 namespace nnet2 {
31 
36 struct NnetExample {
37 
43  std::vector<std::vector<std::pair<int32, BaseFloat> > > labels;
44 
50 
54 
59 
60  void Write(std::ostream &os, bool binary) const;
61  void Read(std::istream &is, bool binary);
62 
64 
76  NnetExample(const NnetExample &input,
77  int32 start_frame,
78  int32 num_frames,
79  int32 left_context,
80  int32 right_context);
81 
84  void SetLabelSingle(int32 frame, int32 pdf_id, BaseFloat weight = 1.0);
85 
88  int32 GetLabelSingle(int32 frame, BaseFloat *weight = NULL);
89 };
90 
91 
95 
96 
100  public:
103  void AcceptExamples(std::vector<NnetExample> *examples);
104 
107  void ExamplesDone();
108 
113  bool ProvideExamples(std::vector<NnetExample> *examples);
114 
115  ExamplesRepository(): empty_semaphore_(1), done_(false) { }
116  private:
119 
120  std::vector<NnetExample> examples_;
121  bool done_;
123 };
124 
125 
141 
143  std::vector<int32> num_ali;
144 
149 
160 
165 
166 
172 
173  void Check() const; // will crash if invalid.
174 
175  void Write(std::ostream &os, bool binary) const;
176  void Read(std::istream &is, bool binary);
177 };
178 
179 // Yes, the length of typenames is getting out of hand.
186 
187 
188 }
189 } // namespace
190 
191 #endif // KALDI_NNET2_NNET_EXAMPLE_H_
CompressedMatrix input_frames
The input data, with NumRows() >= labels.size() + left_context; it includes features to the left and ...
Definition: nnet-example.h:49
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
NnetExample is the input data and corresponding label (or labels) for one or more frames of input...
Definition: nnet-example.h:36
std::vector< NnetExample > examples_
Definition: nnet-example.h:120
int32 left_context
The number of frames of left context (we can work out the #frames of right context from input_frames...
Definition: nnet-example.h:53
SequentialTableReader< KaldiObjectHolder< NnetExample > > SequentialNnetExampleReader
Definition: nnet-example.h:93
void Read(std::istream &is, bool binary)
Definition: nnet-example.cc:80
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
#define KALDI_DISALLOW_COPY_AND_ASSIGN(type)
Definition: kaldi-utils.h:121
Allows random access to a collection of objects in an archive or script file; see The Table concept...
Definition: kaldi-table.h:233
TableWriter< KaldiObjectHolder< DiscriminativeNnetExample > > DiscriminativeNnetExampleWriter
Definition: nnet-example.h:181
RandomAccessTableReader< KaldiObjectHolder< DiscriminativeNnetExample > > RandomAccessDiscriminativeNnetExampleReader
Definition: nnet-example.h:185
This class stores neural net training examples to be used in multi-threaded training.
Definition: nnet-example.h:99
RandomAccessTableReader< KaldiObjectHolder< NnetExample > > RandomAccessNnetExampleReader
Definition: nnet-example.h:94
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
Vector< BaseFloat > spk_info
spk_info contains any component of the features that varies slowly or not at all with time (and hence...
Definition: nnet-example.h:171
CompactLattice den_lat
The denominator lattice.
Definition: nnet-example.h:148
SequentialTableReader< KaldiObjectHolder< DiscriminativeNnetExample > > SequentialDiscriminativeNnetExampleReader
Definition: nnet-example.h:183
Matrix< BaseFloat > input_frames
The input data– typically with a number of frames [NumRows()] larger than labels.size(), because it includes features to the left and right as needed for the temporal context of the network.
Definition: nnet-example.h:159
std::vector< int32 > num_ali
The numerator alignment.
Definition: nnet-example.h:143
TableWriter< KaldiObjectHolder< NnetExample > > NnetExampleWriter
Definition: nnet-example.h:92
BaseFloat weight
The weight we assign to this example; this will typically be one, but we include it for the sake of g...
Definition: nnet-example.h:140
fst::VectorFst< CompactLatticeArc > CompactLattice
Definition: kaldi-lattice.h:46
int32 GetLabelSingle(int32 frame, BaseFloat *weight=NULL)
Get the maximum weight label (pdf_id and weight) of this frame of this example.
This struct is used to store the information we need for discriminative training (MMI or MPE)...
Definition: nnet-example.h:136
A class representing a vector.
Definition: kaldi-vector.h:406
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...
Definition: nnet-example.h:43
int32 left_context
The number of frames of left context in the features (we can work out the #frames of right context fr...
Definition: nnet-example.h:164
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...
void Write(std::ostream &os, bool binary) const
Definition: nnet-example.cc:46
Vector< BaseFloat > spk_info
The speaker-specific input, if any, or an empty vector if we&#39;re not using this features.
Definition: nnet-example.h:58