am-nnet.h
Go to the documentation of this file.
1 // nnet2/am-nnet.h
2 
3 // Copyright 2012 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_NNET2_AM_NNET_H_
21 #define KALDI_NNET2_AM_NNET_H_
22 
23 #include "base/kaldi-common.h"
24 #include "matrix/matrix-lib.h"
25 #include "nnet2/nnet-nnet.h"
26 
27 namespace kaldi {
28 namespace nnet2 {
29 
30 /*
31  The class AmNnet (AM stands for "acoustic model") has the job of taking the
32  "Nnet" class, which is a quite general neural network, and giving it an
33  interface that's suitable for acoustic modeling; it deals with storing, and
34  dividing by, the prior of each context-dependent state.
35 */
36 
37 
38 class AmNnet {
39  public:
40  AmNnet() { }
41 
42  AmNnet(const AmNnet &other): nnet_(other.nnet_), priors_(other.priors_) { }
43 
44  explicit AmNnet(const Nnet &nnet): nnet_(nnet) { }
45 
49  void Init(std::istream &config_is);
50 
53  void Init(const Nnet &nnet);
54 
55  int32 NumPdfs() const { return nnet_.OutputDim(); }
56 
57  void Write(std::ostream &os, bool binary) const;
58 
59  void Read(std::istream &is, bool binary);
60 
61  const Nnet &GetNnet() const { return nnet_; }
62 
63  Nnet &GetNnet() { return nnet_; }
64 
65  void SetPriors(const VectorBase<BaseFloat> &priors);
66 
67  const VectorBase<BaseFloat> &Priors() const { return priors_; }
68 
69  std::string Info() const;
70 
73  void ResizeOutputLayer(int32 new_num_pdfs);
74 
75  private:
76  const AmNnet &operator = (const AmNnet &other); // Disallow.
79 };
80 
81 
82 
83 } // namespace nnet2
84 } // namespace kaldi
85 
86 #endif // KALDI_NNET2_AM_NNET_H_
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
Vector< BaseFloat > priors_
Definition: am-nnet.h:78
Nnet & GetNnet()
Definition: am-nnet.h:63
AmNnet(const Nnet &nnet)
Definition: am-nnet.h:44
void Read(std::istream &is, bool binary)
Definition: am-nnet.cc:39
int32 OutputDim() const
The output dimension of the network – typically the number of pdfs.
Definition: nnet-nnet.cc:31
kaldi::int32 int32
std::string Info() const
Definition: am-nnet.cc:57
void Init(std::istream &config_is)
Initialize the neural network based acoustic model from a config file.
Definition: am-nnet.cc:26
const VectorBase< BaseFloat > & Priors() const
Definition: am-nnet.h:67
void Write(std::ostream &os, bool binary) const
Definition: am-nnet.cc:31
AmNnet(const AmNnet &other)
Definition: am-nnet.h:42
A class representing a vector.
Definition: kaldi-vector.h:406
void ResizeOutputLayer(int32 new_num_pdfs)
This function is used when doing transfer learning to a new system.
Definition: am-nnet.cc:76
const AmNnet & operator=(const AmNnet &other)
int32 NumPdfs() const
Definition: am-nnet.h:55
void SetPriors(const VectorBase< BaseFloat > &priors)
Definition: am-nnet.cc:44
Provides a vector abstraction class.
Definition: kaldi-vector.h:41
const Nnet & GetNnet() const
Definition: am-nnet.h:61