nnet-example.h
Go to the documentation of this file.
1 // nnet3/nnet-example.h
2 
3 // Copyright 2012-2015 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_NNET3_NNET_EXAMPLE_H_
22 #define KALDI_NNET3_NNET_EXAMPLE_H_
23 
24 #include "nnet3/nnet-nnet.h"
25 #include "hmm/posterior.h"
26 #include "util/table-types.h"
27 #include "hmm/posterior.h"
28 
29 namespace kaldi {
30 namespace nnet3 {
31 
32 
33 struct NnetIo {
36  std::string name;
37 
42  std::vector<Index> indexes;
43 
47 
53  NnetIo(const std::string &name,
54  int32 t_begin, const MatrixBase<BaseFloat> &feats,
55  int32 t_stride = 1);
56 
62  NnetIo(const std::string &name,
63  int32 t_begin, const GeneralMatrix &feats,
64  int32 t_stride = 1);
65 
70  NnetIo(const std::string &name,
71  int32 dim,
72  int32 t_begin,
73  const Posterior &labels,
74  int32 t_stride = 1);
75 
76  void Swap(NnetIo *other);
77 
78  NnetIo() { }
79 
80  // Use default copy constructor and assignment operators.
81  void Write(std::ostream &os, bool binary) const;
82 
83  void Read(std::istream &is, bool binary);
84 
85  // this comparison is not very efficient, especially for sparse supervision.
86  // It's only used in testing code.
87  bool operator == (const NnetIo &other) const;
88 };
89 
90 
95  size_t operator () (const NnetIo &a) const noexcept;
96 };
102  bool operator () (const NnetIo &a,
103  const NnetIo &b) const;
104 };
105 
106 
107 
111 struct NnetExample {
112 
116  std::vector<NnetIo> io;
117 
118  void Write(std::ostream &os, bool binary) const;
119  void Read(std::istream &is, bool binary);
120 
122 
123  NnetExample(const NnetExample &other): io(other.io) { }
124 
125  void Swap(NnetExample *other) { io.swap(other->io); }
126 
128  void Compress();
129 
132  bool operator == (const NnetExample &other) const { return io == other.io; }
133 };
134 
135 
146  size_t operator () (const NnetExample &eg) const noexcept;
147  // We also provide a version of this that works from pointers.
148  size_t operator () (const NnetExample *eg) const noexcept {
149  return (*this)(*eg);
150  }
151 };
152 
153 
160  bool operator () (const NnetExample &a,
161  const NnetExample &b) const;
162  // We also provide a version of this that works from pointers.
163  bool operator () (const NnetExample *a,
164  const NnetExample *b) const { return (*this)(*a, *b); }
165 
166 };
167 
168 
169 
173 
174 } // namespace nnet3
175 } // namespace kaldi
176 
177 #endif // KALDI_NNET3_NNET_EXAMPLE_H_
NnetExample is the input data and corresponding label (or labels) for one or more frames of input...
Definition: nnet-example.h:111
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void Swap(NnetExample *other)
Definition: nnet-example.h:125
This class is a wrapper that enables you to store a matrix in one of three forms: either as a Matrix<...
SequentialTableReader< KaldiObjectHolder< NnetExample > > SequentialNnetExampleReader
Definition: nnet-example.h:171
Base class which provides matrix operations not involving resizing or allocation. ...
Definition: kaldi-matrix.h:49
RandomAccessTableReader< KaldiObjectHolder< NnetExample > > RandomAccessNnetExampleReader
Definition: nnet-example.h:172
bool operator==(const NnetIo &other) const
Definition: nnet-example.cc:46
A templated class for writing objects to an archive or script file; see The Table concept...
Definition: kaldi-table.h:368
kaldi::int32 int32
GeneralMatrix features
The features or labels.
Definition: nnet-example.h:46
std::vector< Index > indexes
"indexes" is a vector the same length as features.NumRows(), explaining the meaning of each row of th...
Definition: nnet-example.h:42
void Swap(NnetIo *other)
Definition: nnet-example.cc:80
Allows random access to a collection of objects in an archive or script file; see The Table concept...
Definition: kaldi-table.h:233
This hashing object hashes just the structural aspects of the NnetExample without looking at the valu...
Definition: nnet-example.h:145
std::vector< std::vector< std::pair< int32, BaseFloat > > > Posterior
Posterior is a typedef for storing acoustic-state (actually, transition-id) posteriors over an uttera...
Definition: posterior.h:42
A templated class for reading objects sequentially from an archive or script file; see The Table conc...
Definition: kaldi-table.h:287
This comparator object compares just the structural aspects of the NnetExample without looking at the...
Definition: nnet-example.h:159
This comparison object compares just the structural aspects of the NnetIo object (name, indexes, feature dimension) without looking at the value of features.
Definition: nnet-example.h:101
void Read(std::istream &is, bool binary)
Definition: nnet-example.cc:38
TableWriter< KaldiObjectHolder< NnetExample > > NnetExampleWriter
Definition: nnet-example.h:170
This hashing object hashes just the structural aspects of the NnetIo object (name, indexes, feature dimension) without looking at the value of features.
Definition: nnet-example.h:94
std::string name
the name of the input in the neural net; in simple setups it will just be "input".
Definition: nnet-example.h:36
std::vector< NnetIo > io
"io" contains the input and output.
Definition: nnet-example.h:116
NnetExample(const NnetExample &other)
Definition: nnet-example.h:123
void Write(std::ostream &os, bool binary) const
Definition: nnet-example.cc:28