21 #ifndef KALDI_NNET_NNET_PARALLEL_COMPONENT_H_    22 #define KALDI_NNET_NNET_PARALLEL_COMPONENT_H_    53     std::vector<std::string> nested_nnet_proto;
    54     std::vector<std::string> nested_nnet_filename;
    57     while (is >> std::ws, !is.eof()) {
    59        if (token == 
"<NestedNnet>" || token == 
"<NestedNnetFilename>") {
    60         while (is >> std::ws, !is.eof()) {
    61           std::string file_or_end;
    63           if (file_or_end == 
"</NestedNnet>" ||
    64               file_or_end == 
"</NestedNnetFilename>") 
break;
    65           nested_nnet_filename.push_back(file_or_end);
    67       } 
else if (token == 
"<NestedNnetProto>") {
    68         while (is >> std::ws, !is.eof()) {
    69           std::string file_or_end;
    71           if (file_or_end == 
"</NestedNnetProto>") 
break;
    72           nested_nnet_proto.push_back(file_or_end);
    74       } 
else { 
KALDI_ERR << 
"Unknown token " << token << 
", typo in config?"    75                          << 
" (NestedNnet|NestedNnetFilename|NestedNnetProto)";
    80     if (nested_nnet_filename.size() > 0) {
    81       for (
int32 i = 0; 
i < nested_nnet_filename.size(); 
i++) {
    83         nnet.
Read(nested_nnet_filename[
i]);
    84         nnet_.push_back(nnet);
    85         KALDI_LOG << 
"Loaded nested <Nnet> from file : "    86                   << nested_nnet_filename[
i];
    90     if (nested_nnet_proto.size() > 0) {
    91       for (
int32 i = 0; 
i < nested_nnet_proto.size(); 
i++) {
    93         nnet.
Init(nested_nnet_proto[
i]);
    94         nnet_.push_back(nnet);
    95         KALDI_LOG << 
"Initialized nested <Nnet> from prototype : "    96                   << nested_nnet_proto[
i];
   100     int32 nnet_input_sum = 0, nnet_output_sum = 0;
   102       nnet_input_sum += 
nnet_[
i].InputDim();
   103       nnet_output_sum += 
nnet_[
i].OutputDim();
   114     for (
int32 i = 0; 
i < nnet_count; 
i++) {
   119       nnet.
Read(is, binary);
   120       nnet_.push_back(nnet);
   125     int32 nnet_input_sum = 0, nnet_output_sum = 0;
   127       nnet_input_sum += 
nnet_[
i].InputDim();
   128       nnet_output_sum += 
nnet_[
i].OutputDim();
   140     if (!binary) os << 
"\n";
   141     for (
int32 i = 0; 
i < nnet_count; 
i++) {
   144       if (!binary) os << 
"\n";
   145       nnet_[
i].Write(os, binary);
   147     WriteToken(os, binary, 
"</ParallelComponent>");
   153       ans += 
nnet_[
i].NumParams();
   164       nnet_[
i].GetGradient(&gradient_aux);  
   165       gradient->
Range(offset, n_params).CopyFromVec(gradient_aux);
   177       nnet_[
i].GetParams(¶ms_aux);  
   178       params->
Range(offset, n_params).CopyFromVec(params_aux);
   189       nnet_[
i].SetParams(params.
Range(offset, n_params));
   196     std::ostringstream os;
   199       os << 
"nested_network #" << 
i+1 << 
" {\n"   203     std::string s(os.str());
   209     std::ostringstream os;
   212       os << 
"nested_gradient #" << 
i+1 << 
" {\n"   213          << 
nnet_[
i].InfoGradient(
false)
   216     std::string s(os.str());
   222     std::ostringstream os;
   224       os << 
"nested_propagate #" << 
i+1 << 
" {\n"   225          << 
nnet_[
i].InfoPropagate(
false)
   232     std::ostringstream os;
   234       os << 
"nested_backpropagate #" << 
i+1 << 
" {\n"   235          << 
nnet_[
i].InfoBackPropagate(
false)
   244     int32 input_offset = 0, output_offset = 0;
   256       nnet_[
i].Propagate(src, &tgt_aux);
   259       input_offset += 
nnet_[
i].InputDim();
   260       output_offset += 
nnet_[
i].OutputDim();
   269     int32 input_offset = 0, output_offset = 0;
   281       nnet_[
i].Backpropagate(src, &tgt_aux);
   284       input_offset += 
nnet_[
i].InputDim();
   285       output_offset += 
nnet_[
i].OutputDim();
   300       nnet_[
i].SetTrainOptions(opts);
   313         if (
nnet_[
i].GetComponent(
j).IsUpdatable()) {
   332         if (
nnet_[
i].GetComponent(
j).IsUpdatable()) {
   350       nnet_[
i].SetSeqLengths(sequence_lengths);
   361 #endif  // KALDI_NNET_NNET_PARALLEL_COMPONENT_H_ void WriteData(std::ostream &os, bool binary) const
Writes the component content. 
 
void CopyFromMat(const MatrixBase< OtherReal > &src, MatrixTransposeType trans=kNoTrans)
 
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
 
void PropagateFnc(const CuMatrixBase< BaseFloat > &in, CuMatrixBase< BaseFloat > *out)
Abstract interface for propagation/backpropagation. 
 
std::string Info() const
Print some additional info (after <ComponentName> and the dims),. 
 
std::string InfoBackPropagate() const
 
void ReadBasicType(std::istream &is, bool binary, T *t)
ReadBasicType is the name of the read function for bool, integer types, and floating-point types...
 
Class UpdatableComponent is a Component which has trainable parameters, it contains SGD training hype...
 
int32 NumParams() const
Number of trainable parameters,. 
 
void ReadToken(std::istream &is, bool binary, std::string *str)
ReadToken gets the next token and puts it in str (exception on failure). 
 
void SetTrainOptions(const NnetTrainOptions &opts)
Overriding the default, which was UpdatableComponent::SetTrainOptions(...) 
 
This class represents a matrix that's stored on the GPU if we have one, and in memory if not...
 
const Nnet & GetNestedNnet(int32 id) const
 
Nnet & GetNestedNnet(int32 id)
 
ComponentType GetType() const
Get Type Identification of the component,. 
 
virtual void SetLearnRateCoef(BaseFloat val)
Set the learn-rate coefficient,. 
 
ComponentType
Component type identification mechanism,. 
 
void SetParams(const VectorBase< BaseFloat > ¶ms)
Set the trainable parameters from, reshaped as a vector,. 
 
void SetSeqLengths(const std::vector< int32 > &sequence_lengths)
Overriding the default, which was MultistreamComponent::SetSeqLengths(...) 
 
void SetBiasLearnRateCoef(BaseFloat val)
Overriding the default, which was UpdatableComponent::SetBiasLearnRateCoef(...) 
 
void ReadData(std::istream &is, bool binary)
Reads the component content. 
 
std::string InfoPropagate() const
 
virtual void SetBiasLearnRateCoef(BaseFloat val)
Set the learn-rate coefficient for bias,. 
 
void ExpectToken(std::istream &is, bool binary, const char *token)
ExpectToken tries to read in the given token, and throws an exception on failure. ...
 
int32 InputDim() const
Get the dimension of the input,. 
 
void Read(const std::string &rxfilename)
Read Nnet from 'rxfilename',. 
 
This class is used for a piece of a CuMatrix. 
 
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::string InfoGradient() const
Print some additional info about gradient (after <...> and dims),. 
 
ParallelComponent(int32 dim_in, int32 dim_out)
 
CuSubMatrix< Real > ColRange(const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
 
void InitData(std::istream &is)
Initialize the content of the component by the 'line' from the prototype,. 
 
Matrix for CUDA computing. 
 
void Init(const std::string &proto_file)
Initialize the Nnet from the prototype,. 
 
Component * Copy() const
Copy component (deep copy),. 
 
void GetParams(VectorBase< BaseFloat > *params) const
Get the trainable parameters reshaped as a vector,. 
 
A class representing a vector. 
 
#define KALDI_ASSERT(cond)
 
void BackpropagateFnc(const CuMatrixBase< BaseFloat > &in, const CuMatrixBase< BaseFloat > &out, const CuMatrixBase< BaseFloat > &out_diff, CuMatrixBase< BaseFloat > *in_diff)
Backward pass transformation (to be implemented by descending class...) 
 
void WriteBasicType(std::ostream &os, bool binary, T t)
WriteBasicType is the name of the write function for bool, integer types, and floating-point types...
 
Abstract class, building block of the network. 
 
std::vector< Nnet > nnet_
 
std::vector< int32 > sequence_lengths_
 
int32 OutputDim() const
Get the dimension of the output,. 
 
void Update(const CuMatrixBase< BaseFloat > &input, const CuMatrixBase< BaseFloat > &diff)
Compute gradient and update parameters,. 
 
Provides a vector abstraction class. 
 
void GetGradient(VectorBase< BaseFloat > *gradient) const
Get gradient reshaped as a vector,. 
 
void SetLearnRateCoef(BaseFloat val)
Overriding the default, which was UpdatableComponent::SetLearnRateCoef(...) 
 
SubVector< Real > Range(const MatrixIndexT o, const MatrixIndexT l)
Returns a sub-vector of a vector (a range of elements).