am-nnet-simple.h
Go to the documentation of this file.
1 // nnet3/am-nnet-simple.h
2 
3 // Copyright 2015 Johns Hopkins University (author: Daniel Povey)
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 #ifndef KALDI_NNET3_AM_NNET_SIMPLE_H_
21 #define KALDI_NNET3_AM_NNET_SIMPLE_H_
22 
23 #include "base/kaldi-common.h"
24 #include "matrix/matrix-lib.h"
25 #include "nnet3/nnet-nnet.h"
26 
27 namespace kaldi {
28 namespace nnet3 {
29 
30 /*
31 
32  The class AmNnetSimple (AM stands for "acoustic model") has the job of taking
33  the "Nnet" class, which is a quite general neural network, and giving it an
34  interface that's suitable for acoustic modeling, i.e. all the stuff that's
35  specific to the speech recognition application, including dividing by the
36  prior.
37 
38  This class is intended for wrapping "simple" neural nets, defined as those
39  having one output named "output", an input named "input" (provided for various
40  t and x=0) and a possible input named "ivector" (provided only for t=0,x=0).
41  The inputs and outputs should have the expected relationship, e.g. the minimum
42  context required to compute an output should be expressible as a left-context
43  and right-context sufficient to cover all cases (for instance, the output
44  can't depend on the input at 2*t).
45 
46 */
47 
48 
49 class AmNnetSimple {
50  public:
52 
53  AmNnetSimple(const AmNnetSimple &other):
54  nnet_(other.nnet_),
55  priors_(other.priors_),
58 
59  explicit AmNnetSimple(const Nnet &nnet):
60  nnet_(nnet) { SetContext(); }
61 
62  int32 NumPdfs() const;
63 
64  void Write(std::ostream &os, bool binary) const;
65 
66  void Read(std::istream &is, bool binary);
67 
68  const Nnet &GetNnet() const { return nnet_; }
69 
72  Nnet &GetNnet() { return nnet_; }
73 
74  void SetNnet(const Nnet &nnet);
75 
76  void SetPriors(const VectorBase<BaseFloat> &priors);
77 
78  const VectorBase<BaseFloat> &Priors() const { return priors_; }
79 
80  std::string Info() const;
81 
83  int32 LeftContext() const { return left_context_; }
84 
86  int32 RightContext() const { return right_context_; }
87 
89  int32 InputDim() const { return nnet_.InputDim("input"); }
90 
92  int32 IvectorDim() const { return nnet_.InputDim("ivector"); }
93 
98  void SetContext();
99  private:
100 
101  const AmNnetSimple &operator = (const AmNnetSimple &other); // Disallow.
104 
105  // The following variables are derived; they are re-computed
106  // when we read the network or when it is changed.
109 };
110 
111 
112 
113 } // namespace nnet3
114 } // namespace kaldi
115 
116 #endif // KALDI_NNET3_AM_NNET_SIMPLE_H_
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
std::string Info() const
Vector< BaseFloat > priors_
int32 InputDim(const std::string &input_name) const
Definition: nnet-nnet.cc:669
int32 LeftContext() const
Minimum left context required to compute an output.
int32 RightContext() const
Minimum right context required to compute an output.
const AmNnetSimple & operator=(const AmNnetSimple &other)
int32 InputDim() const
Returns the input feature dim.
int32 IvectorDim() const
Returns the iVector dimension, or -1 if there is no such input.
kaldi::int32 int32
const Nnet & GetNnet() const
void Read(std::istream &is, bool binary)
void SetPriors(const VectorBase< BaseFloat > &priors)
Nnet & GetNnet()
Caution: if you structurally change the nnet, you should call SetContext() afterward.
AmNnetSimple(const Nnet &nnet)
void SetNnet(const Nnet &nnet)
const VectorBase< BaseFloat > & Priors() const
void SetContext()
This function works out the left_context_ and right_context_ variables from the network (it&#39;s a rathe...
A class representing a vector.
Definition: kaldi-vector.h:406
AmNnetSimple(const AmNnetSimple &other)
Provides a vector abstraction class.
Definition: kaldi-vector.h:41
void Write(std::ostream &os, bool binary) const