100 (*in_diff) = out_diff;
125 if (NULL != in_diff) {
274 KALDI_LOG <<
"Setting dropout-rate in component " << c
275 <<
" from " << r_old <<
" to " << r;
302 Input in(proto_file);
303 std::istream &is = in.
Stream();
304 std::string proto_line, token;
308 while (is >> std::ws, !is.eof()) {
312 std::getline(is, proto_line);
313 if (proto_line ==
"")
continue;
317 std::istringstream(proto_line) >> std::ws >> token;
319 if (token ==
"<NnetProto>" || token ==
"</NnetProto>")
continue;
335 Input in(rxfilename, &binary);
340 KALDI_WARN <<
"The network '" << rxfilename <<
"' is empty.";
353 <<
" Previous layer output:" <<
components_.back()->OutputDim()
354 <<
" Current layer input:" << comp->
InputDim();
367 void Nnet::Write(
const std::string &wxfilename,
bool binary)
const {
368 Output out(wxfilename, binary,
true);
377 if (binary ==
false) os << std::endl;
382 if (binary ==
false) os << std::endl;
388 std::ostringstream ostr;
392 ostr <<
"input-dim " <<
InputDim() << std::endl;
393 ostr <<
"output-dim " <<
OutputDim() << std::endl;
394 ostr <<
"number-of-parameters " <<
static_cast<float>(
NumParams())/1e6
395 <<
" millions" << std::endl;
398 ostr <<
"component " <<
i+1 <<
" : " 408 std::ostringstream ostr;
410 if (header) ostr <<
"\n### GRADIENT STATS :\n";
412 ostr <<
"Component " <<
i+1 <<
" : " 416 if (header) ostr <<
"### END GRADIENT\n";
421 std::ostringstream ostr;
423 if (header) ostr <<
"\n### FORWARD PROPAGATION BUFFER CONTENT :\n";
427 ostr <<
"[" << 1+
i <<
"] output of " 439 if (header) ostr <<
"### END FORWARD\n";
444 std::ostringstream ostr;
446 if (header) ostr <<
"\n### BACKWARD PROPAGATION BUFFER CONTENT :\n";
450 ostr <<
"["<<1+
i<<
"] diff-output of " 462 if (header) ostr <<
"### END BACKWARD\n\n";
474 if (output_dim != next_input_dim) {
475 KALDI_ERR <<
"Component dimension mismatch!" 476 <<
" Output dim of [" <<
i <<
"] " 478 <<
" is " << output_dim <<
". " 479 <<
"Input dim of next [" <<
i+1 <<
"] " 481 <<
" is " << next_input_dim <<
".";
489 KALDI_ERR <<
"'inf' in network parameters " 490 <<
"(weight explosion, need lower learning rate?)";
493 KALDI_ERR <<
"'nan' in network parameters (need lower learning rate?)";
void Backpropagate(const CuMatrixBase< BaseFloat > &out_diff, CuMatrix< BaseFloat > *in_diff)
Perform backward pass through the network,.
void RemoveLastComponent()
Remove the last of the Components,.
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void ResetStreams(const std::vector< int32 > &stream_reset_flag)
Reset streams in multi-stream training,.
void SetParams(const VectorBase< BaseFloat > ¶ms)
Set the network weights from a supervector,.
void AppendComponentPointer(Component *dynamically_allocated_comp)
Append Component* to 'this' instance of Nnet by a shallow copy ('this' instance of Nnet over-takes th...
void ReplaceComponent(int32 c, const Component &comp)
Replace c'th component in 'this' Nnet (deep copy),.
virtual void GetGradient(VectorBase< BaseFloat > *gradient) const =0
Get gradient reshaped as a vector,.
virtual int32 NumParams() const =0
Number of trainable parameters,.
void Propagate(const CuMatrixBase< BaseFloat > &in, CuMatrix< BaseFloat > *out)
Perform forward pass through the network,.
void GetParams(Vector< BaseFloat > *params) const
Get the network weights in a supervector,.
int32 NumParams() const
Get the number of parameters in the network,.
BaseFloat GetDropoutRate()
std::string MomentStatistics(const VectorBase< Real > &vec)
Get a string with statistics of the data in a vector, so we can print them easily.
void SetSeqLengths(const std::vector< int32 > &sequence_lengths)
Set sequence length in LSTM multi-stream training,.
int32 NumComponents() const
Returns the number of 'Components' which form the NN.
virtual void SetParams(const VectorBase< BaseFloat > ¶ms)=0
Set the trainable parameters from, reshaped as a vector,.
void Write(const std::string &wxfilename, bool binary) const
Write Nnet to 'wxfilename',.
int32 InputDim() const
Dimensionality on network input (input feature dim.),.
Class UpdatableComponent is a Component which has trainable parameters, it contains SGD training hype...
This class represents a matrix that's stored on the GPU if we have one, and in memory if not...
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
static Component * Init(const std::string &conf_line)
Initialize component from a line in config file,.
static Component * Read(std::istream &is, bool binary)
Read the component from a stream (static method),.
const Component & GetLastComponent() const
LastComponent accessor,.
void SetDropoutRate(BaseFloat dr)
virtual bool IsUpdatable() const
Check if componeny has 'Updatable' interface (trainable components),.
virtual void SetSeqLengths(const std::vector< int32 > &sequence_lengths)
static const char * TypeToMarker(ComponentType t)
Converts component type to marker,.
virtual void Update(const CuMatrixBase< BaseFloat > &input, const CuMatrixBase< BaseFloat > &diff)=0
Compute gradient and update parameters,.
void GetGradient(Vector< BaseFloat > *gradient) const
Get the gradient stored in the network,.
virtual void ResetStreams(const std::vector< int32 > &stream_reset_flag)
Optional function to reset the transfer of context (not used for BLSTMs.
int32 OutputDim() const
Dimensionality of network outputs (posteriors | bn-features | etc.),.
void SwapComponent(int32 c, Component **comp)
Swap c'th component with the pointer,.
void Swap(Matrix< Real > *mat)
std::string InfoBackPropagate(bool header=true) const
Create string with back-propagation-buffer statistics,.
void AppendNnet(const Nnet &nnet_to_append)
Append other Nnet to the 'this' Nnet (copy all its components),.
int32 InputDim() const
Get the dimension of the input,.
virtual Component * Copy() const =0
Copy component (deep copy),.
void Read(const std::string &rxfilename)
Read Nnet from 'rxfilename',.
virtual bool IsMultistream() const
Check if component has 'Recurrent' interface (trainable and recurrent),.
void Check() const
Consistency check,.
void Destroy()
Relese the memory,.
void WriteToken(std::ostream &os, bool binary, const char *token)
The WriteToken functions are for writing nonempty sequences of non-space characters.
MatrixIndexT Dim() const
Returns the dimension of the vector.
Class MultistreamComponent is an extension of UpdatableComponent for recurrent networks, which are trained with parallel sequences.
std::vector< CuMatrix< BaseFloat > > propagate_buf_
Buffers for forward pass (on demand initialization),.
Real Sum() const
Returns sum of the elements.
void Feedforward(const CuMatrixBase< BaseFloat > &in, CuMatrix< BaseFloat > *out)
Perform forward pass through the network (with 2 swapping buffers),.
std::vector< Component * > components_
Vector which contains all the components composing the neural network, the components are for example...
Matrix for CUDA computing.
void Init(const std::string &proto_file)
Initialize the Nnet from the prototype,.
A class representing a vector.
#define KALDI_ASSERT(cond)
virtual void GetParams(VectorBase< BaseFloat > *params) const =0
Get the trainable parameters reshaped as a vector,.
void SetDropoutRate(BaseFloat r)
Set the dropout rate.
std::string InfoGradient(bool header=true) const
Create string with per-component gradient statistics,.
std::string InfoPropagate(bool header=true) const
Create string with propagation-buffer statistics,.
std::string Info() const
Create string with human readable description of the nnet,.
void RemoveComponent(int32 c)
Remove c'th component,.
const Component & GetComponent(int32 c) const
Component accessor,.
virtual ComponentType GetType() const =0
Get Type Identification of the component,.
void SetTrainOptions(const NnetTrainOptions &opts)
Set hyper-parameters of the training (pushes to all UpdatableComponents),.
Abstract class, building block of the network.
NnetTrainOptions opts_
Option class with hyper-parameters passed to UpdatableComponent(s)
std::vector< CuMatrix< BaseFloat > > backpropagate_buf_
Buffers for backward pass (on demand initialization),.
Provides a vector abstraction class.
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
void AppendComponent(const Component &comp)
Append Component to 'this' instance of Nnet (deep copy),.
Nnet & operator=(const Nnet &other)
SubVector< Real > Range(const MatrixIndexT o, const MatrixIndexT l)
Returns a sub-vector of a vector (a range of elements).