am-nnet.h
2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// nnet2/am-nnet.h
// Copyright 2012 Johns Hopkins University (author: Daniel Povey)
// See ../../COPYING for clarification regarding multiple authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
// WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
// MERCHANTABLITY OR NON-INFRINGEMENT.
// See the Apache 2 License for the specific language governing permissions and
// limitations under the License.
#ifndef KALDI_NNET2_AM_NNET_H_
#define KALDI_NNET2_AM_NNET_H_
#include "base/kaldi-common.h"
#include "matrix/matrix-lib.h"
#include "nnet2/nnet-nnet.h"
namespace kaldi {
namespace nnet2 {
/*
The class AmNnet (AM stands for "acoustic model") has the job of taking the
"Nnet" class, which is a quite general neural network, and giving it an
interface that's suitable for acoustic modeling; it deals with storing, and
dividing by, the prior of each context-dependent state.
*/
class AmNnet {
public:
AmNnet() { }
AmNnet(const AmNnet &other): nnet_(other.nnet_), priors_(other.priors_) { }
explicit AmNnet(const Nnet &nnet): nnet_(nnet) { }
/// Initialize the neural network based acoustic model from a config file.
/// At this point the priors won't be initialized; you'd have to do
/// SetPriors for that.
void Init(std::istream &config_is);
/// Initialize from a neural network that's already been set up.
/// Again, the priors will be empty at this point.
void Init(const Nnet &nnet);
int32 NumPdfs() const { return nnet_.OutputDim(); }
void Write(std::ostream &os, bool binary) const;
void Read(std::istream &is, bool binary);
const Nnet &GetNnet() const { return nnet_; }
Nnet &GetNnet() { return nnet_; }
void SetPriors(const VectorBase<BaseFloat> &priors);
const VectorBase<BaseFloat> &Priors() const { return priors_; }
std::string Info() const;
/// This function is used when doing transfer learning to a new system.
/// It will set the priors to be all the same.
void ResizeOutputLayer(int32 new_num_pdfs);
private:
const AmNnet &operator = (const AmNnet &other); // Disallow.
Nnet nnet_;
Vector<BaseFloat> priors_;
};
} // namespace nnet2
} // namespace kaldi
#endif // KALDI_NNET2_AM_NNET_H_