All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
AmNnet Class Reference

#include <am-nnet.h>

Collaboration diagram for AmNnet:

Public Member Functions

 AmNnet ()
 
 AmNnet (const AmNnet &other)
 
 AmNnet (const Nnet &nnet)
 
void Init (std::istream &config_is)
 Initialize the neural network based acoustic model from a config file. More...
 
void Init (const Nnet &nnet)
 Initialize from a neural network that's already been set up. More...
 
int32 NumPdfs () const
 
void Write (std::ostream &os, bool binary) const
 
void Read (std::istream &is, bool binary)
 
const NnetGetNnet () const
 
NnetGetNnet ()
 
void SetPriors (const VectorBase< BaseFloat > &priors)
 
const VectorBase< BaseFloat > & Priors () const
 
std::string Info () const
 
void ResizeOutputLayer (int32 new_num_pdfs)
 This function is used when doing transfer learning to a new system. More...
 

Private Member Functions

const AmNnetoperator= (const AmNnet &other)
 

Private Attributes

Nnet nnet_
 
Vector< BaseFloatpriors_
 

Detailed Description

Definition at line 38 of file am-nnet.h.

Constructor & Destructor Documentation

AmNnet ( )
inline

Definition at line 40 of file am-nnet.h.

40 { }
AmNnet ( const AmNnet other)
inline

Definition at line 42 of file am-nnet.h.

42 : nnet_(other.nnet_), priors_(other.priors_) { }
Vector< BaseFloat > priors_
Definition: am-nnet.h:78
AmNnet ( const Nnet nnet)
inlineexplicit

Definition at line 44 of file am-nnet.h.

44 : nnet_(nnet) { }

Member Function Documentation

Nnet& GetNnet ( )
inline

Definition at line 63 of file am-nnet.h.

References AmNnet::nnet_.

63 { return nnet_; }
std::string Info ( ) const

Definition at line 57 of file am-nnet.cc.

References VectorBase< Real >::Dim(), Nnet::Info(), VectorBase< Real >::Min(), AmNnet::nnet_, AmNnet::priors_, and VectorBase< Real >::Sum().

Referenced by main().

57  {
58  std::ostringstream ostr;
59  ostr << "prior dimension: " << priors_.Dim();
60  if (priors_.Dim() != 0) {
61  ostr << ", prior sum: " << priors_.Sum() << ", prior min: " << priors_.Min()
62  << "\n";
63  }
64  return nnet_.Info() + ostr.str();
65 }
Vector< BaseFloat > priors_
Definition: am-nnet.h:78
Real Sum() const
Returns sum of the elements.
Real Min() const
Returns the minimum value of any element, or +infinity for the empty vector.
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:62
std::string Info() const
Definition: nnet-nnet.cc:257
void Init ( std::istream &  config_is)

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.

Definition at line 26 of file am-nnet.cc.

References Nnet::Init(), and AmNnet::nnet_.

Referenced by main().

26  {
27  nnet_.Init(config_is);
28 }
void Init(std::istream &is)
Initialize from config file.
Definition: nnet-nnet.cc:281
void Init ( const Nnet nnet)

Initialize from a neural network that's already been set up.

Again, the priors will be empty at this point.

Definition at line 67 of file am-nnet.cc.

References VectorBase< Real >::Dim(), KALDI_WARN, AmNnet::nnet_, Nnet::OutputDim(), AmNnet::priors_, and Vector< Real >::Resize().

67  {
68  nnet_ = nnet;
69  if (priors_.Dim() != 0 && priors_.Dim() != nnet.OutputDim()) {
70  KALDI_WARN << "Initializing neural net: prior dimension mismatch, "
71  << "discarding old priors.";
72  priors_.Resize(0);
73  }
74 }
Vector< BaseFloat > priors_
Definition: am-nnet.h:78
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
#define KALDI_WARN
Definition: kaldi-error.h:130
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:62
int32 NumPdfs ( ) const
inline

Definition at line 55 of file am-nnet.h.

References AmNnet::nnet_, and Nnet::OutputDim().

Referenced by main(), kaldi::nnet2::SetPriors(), and AmNnet::SetPriors().

55 { return nnet_.OutputDim(); }
int32 OutputDim() const
The output dimension of the network – typically the number of pdfs.
Definition: nnet-nnet.cc:31
const AmNnet& operator= ( const AmNnet other)
private
void Read ( std::istream &  is,
bool  binary 
)

Definition at line 39 of file am-nnet.cc.

References AmNnet::nnet_, AmNnet::priors_, Nnet::Read(), and Vector< Real >::Read().

Referenced by main(), and kaldi::nnet2::UnitTestAmNnet().

39  {
40  nnet_.Read(is, binary);
41  priors_.Read(is, binary);
42 }
void Read(std::istream &is, bool binary)
Definition: nnet-nnet.cc:175
Vector< BaseFloat > priors_
Definition: am-nnet.h:78
void Read(std::istream &in, bool binary, bool add=false)
Read function using C++ streams.
void ResizeOutputLayer ( int32  new_num_pdfs)

This function is used when doing transfer learning to a new system.

It will set the priors to be all the same.

Definition at line 76 of file am-nnet.cc.

References AmNnet::nnet_, AmNnet::priors_, Vector< Real >::Resize(), Nnet::ResizeOutputLayer(), and VectorBase< Real >::Set().

Referenced by main().

76  {
77  nnet_.ResizeOutputLayer(new_num_pdfs);
78  priors_.Resize(new_num_pdfs);
79  priors_.Set(1.0 / new_num_pdfs);
80 }
Vector< BaseFloat > priors_
Definition: am-nnet.h:78
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
void ResizeOutputLayer(int32 new_num_pdfs)
This function is used when doing transfer learning to a new system.
Definition: nnet-nnet.cc:356
void Set(Real f)
Set all members of a vector to a specified value.
void SetPriors ( const VectorBase< BaseFloat > &  priors)

Definition at line 44 of file am-nnet.cc.

References VectorBase< Real >::Dim(), KALDI_ERR, KALDI_WARN, kaldi::kCopyData, AmNnet::NumPdfs(), AmNnet::priors_, and Vector< Real >::Resize().

Referenced by main(), kaldi::nnet2::SetPriors(), kaldi::nnet2::UnitTestAmNnet(), and kaldi::nnet2::UnitTestNnetDecodable().

44  {
45  priors_ = priors;
46  if (priors_.Dim() > NumPdfs())
47  KALDI_ERR << "Dimension of priors cannot exceed number of pdfs.";
48 
49  if (priors_.Dim() > 0 && priors_.Dim() < NumPdfs()) {
50  KALDI_WARN << "Dimension of priors is " << priors_.Dim() << " < "
51  << NumPdfs() << ": extending with zeros, in case you had "
52  << "unseen pdf's, but this possibly indicates a serious problem.";
54  }
55 }
Vector< BaseFloat > priors_
Definition: am-nnet.h:78
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
int32 NumPdfs() const
Definition: am-nnet.h:55
#define KALDI_ERR
Definition: kaldi-error.h:127
#define KALDI_WARN
Definition: kaldi-error.h:130
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:62
void Write ( std::ostream &  os,
bool  binary 
) const

Definition at line 31 of file am-nnet.cc.

References AmNnet::nnet_, AmNnet::priors_, Nnet::Write(), and VectorBase< Real >::Write().

Referenced by main(), and kaldi::nnet2::UnitTestAmNnet().

31  {
32  // We don't write any header or footer like <AmNnet> and </AmNnet> -- we just
33  // write the neural net and then the priors. Who knows, there might be some
34  // situation where we want to just read the neural net.
35  nnet_.Write(os, binary);
36  priors_.Write(os, binary);
37 }
void Write(std::ostream &Out, bool binary) const
Writes to C++ stream (option to write in binary).
Vector< BaseFloat > priors_
Definition: am-nnet.h:78
void Write(std::ostream &os, bool binary) const
Definition: nnet-nnet.cc:160

Member Data Documentation


The documentation for this class was generated from the following files: