32     use_natural_gradient_(true) { }
    66   std::ostringstream stream;
    77   if (use_natural_gradient_) {
    78     stream << 
", num-minibatches-history="    90     KALDI_ERR << 
"You cannot specify init-unit if the num-filters-in "    91               << 
"and num-filters-out differ.";
    94   int32 zero_offset = 0;
   103     KALDI_ERR << 
"You cannot specify init-unit if the model does "   104               << 
"not have the offset (0, 0).";
   110   KALDI_ASSERT(zero_offset_block.NumRows() == zero_offset_block.NumCols());
   111   zero_offset_block.AddToDiag(1.0);  
   121   std::string height_offsets, time_offsets, required_time_offsets = 
"undef",
   129     KALDI_ERR << 
"Bad initializer: expected all the values "   130         "num-filters-in, num-filters-out, height-in, height-out, "   135   cfl->
GetValue(
"required-time-offsets", &required_time_offsets);
   142     if (cfl->
GetValue(
"offsets", &offsets)) {
   144       std::vector<std::string> splits;
   146       for (
size_t i = 0; 
i < splits.size(); 
i++) {
   147         std::vector<int32> int_pair;
   149             int_pair.size() != 2)
   150           KALDI_ERR << 
"Bad config value offsets=" << offsets;
   158         KALDI_ERR << 
"Error in offsets: probably repeated offset.  "   159             "offsets=" << offsets;
   160     } 
else if (cfl->
GetValue(
"height-offsets", &height_offsets) &&
   161                cfl->
GetValue(
"time-offsets", &time_offsets)) {
   162       std::vector<int32> height_offsets_vec,
   165                                  &height_offsets_vec) ||
   167                                  &time_offsets_vec)) {
   168         KALDI_ERR << 
"Formatting problem in time-offsets or height-offsets: "   171       if (height_offsets_vec.empty() || !
IsSortedAndUniq(height_offsets_vec) ||
   173         KALDI_ERR << 
"time-offsets and height-offsets must be nonempty, "   174             "sorted and unique.";
   177       for (
size_t i = 0; 
i < time_offsets_vec.size(); 
i++) {
   178         for (
size_t j = 0; 
j < height_offsets_vec.size(); 
j++) {
   186       KALDI_ERR << 
"Expected either 'offsets', or both 'height-offsets' and "   187           "'time-offsets', to be defined: " << cfl->
WholeLine();
   196     std::vector<int32> required_time_offsets_vec;
   197     if (required_time_offsets == 
"undef") {
   199       std::set<int32> required_time_offsets;
   201         required_time_offsets_vec.push_back(
model_.
offsets[
i].time_offset);
   205                                  &required_time_offsets_vec) ||
   206           required_time_offsets_vec.empty() ||
   208         KALDI_ERR << 
"Formatting problem in required-time-offsets: "   214         required_time_offsets_vec.begin(),
   215         required_time_offsets_vec.end());
   220     KALDI_ERR << 
"Parameters used to initialize TimeHeightConvolutionComponent "   221               << 
"do not make sense,  line was: " << cfl->
WholeLine();
   224     KALDI_WARN << 
"There are input heights unused in "   225         "TimeHeightConvolutionComponent; consider increasing output "   226         "height or decreasing height of preceding layer."   231   BaseFloat param_stddev = -1, bias_stddev = 0.0;
   232   bool init_unit = 
false;
   233   cfl->
GetValue(
"param-stddev", ¶m_stddev);
   234   cfl->
GetValue(
"bias-stddev", &bias_stddev);
   235   cfl->
GetValue(
"init-unit", &init_unit);
   236   if (param_stddev < 0.0) {
   255   int32 rank_out = -1, rank_in = -1;
   256   BaseFloat alpha_out = 4.0, alpha_in = 4.0,
   257       num_minibatches_history = 4.0;
   260   cfl->
GetValue(
"rank-out", &rank_out);
   261   cfl->
GetValue(
"alpha-in", &alpha_in);
   262   cfl->
GetValue(
"alpha-out", &alpha_out);
   263   cfl->
GetValue(
"num-minibatches-history", &num_minibatches_history);
   268     rank_in = std::min<int32>(80, (dim_in + 1) / 2);
   271     rank_out = std::min<int32>(80, (dim_out + 1) / 2);
   302     const std::string &debug_info,
   310   NVTX_RANGE(
"TimeHeightConvolutionComponent::Backprop");
   315   if (in_deriv != NULL) {
   317                          out_deriv, in_deriv);
   319   if (to_update_in != NULL) {
   368     bias_deriv.AddRowSumMat(1.0, out_deriv_reshaped);
   381                          1.0, &linear_params_deriv);
   409     std::vector<Index> *input_indexes,
   410     std::vector<Index> *output_indexes)
 const {
   411   using namespace time_height_convolution;
   412   ConvolutionComputationOptions opts;
   414   ConvolutionComputation computation_temp;
   415   std::vector<Index> input_indexes_modified,
   416       output_indexes_modified;
   418       model_, *input_indexes, *output_indexes, opts,
   419       &computation_temp, &input_indexes_modified, &output_indexes_modified);
   420   input_indexes->swap(input_indexes_modified);
   421   output_indexes->swap(output_indexes_modified);
   434   WriteToken(os, binary, 
"<UseNaturalGradient>");
   441   WriteToken(os, binary, 
"<NumMinibatchesHistory>");
   449   WriteToken(os, binary, 
"</TimeHeightConvolutionComponent>");
   469   int32 rank_in,  rank_out;
   471       num_minibatches_history;
   472   ExpectToken(is, binary, 
"<NumMinibatchesHistory>");
   486   ExpectToken(is, binary, 
"</TimeHeightConvolutionComponent>");
   506     const Index &output_index,
   507     std::vector<Index> *desired_indexes)
 const {
   510   desired_indexes->resize(size);
   511   for (
size_t i = 0; 
i < size; 
i++) {
   512     (*desired_indexes)[
i].n = output_index.
n;
   514     (*desired_indexes)[
i].x = output_index.
x;
   521     const Index &output_index,
   523     std::vector<Index> *used_inputs)
 const {
   526   Index index(output_index);
   527   if (used_inputs != NULL) {
   528     used_inputs->clear();
   529     used_inputs->reserve(size);
   530     for (
size_t i = 0; 
i < size; 
i++) {
   532       if (input_index_set(index)) {
   534         used_inputs->push_back(index);
   540           used_inputs->clear();
   548     for (
size_t i = 0; 
i < size; 
i++) {
   551         if (!input_index_set(index))
   562       const std::vector<Index> &input_indexes,
   563       const std::vector<Index> &output_indexes,
   564       bool need_backprop)
 const {
   565   using namespace time_height_convolution;
   566   ConvolutionComputationOptions opts;
   569   std::vector<Index> input_indexes_modified,
   570       output_indexes_modified;
   572       model_, input_indexes, output_indexes, opts,
   573       &(ans->
computation), &input_indexes_modified, &output_indexes_modified);
   574   if (input_indexes_modified != input_indexes ||
   575       output_indexes_modified != output_indexes) {
   576     KALDI_ERR << 
"Problem precomputing indexes";
   653     std::ostream &os, 
bool binary)
 const {
   654   WriteToken(os, binary, 
"<TimeHeightConvolutionComponentPrecomputedIndexes>");
   656   computation.Write(os, binary);
   657   WriteToken(os, binary, 
"</TimeHeightConvolutionComponentPrecomputedIndexes>");
   661     std::istream &is, 
bool binary) {
   663                        "<TimeHeightConvolutionComponentPrecomputedIndexes>",
   665   computation.Read(is, binary);
   666   ExpectToken(is, binary, 
"</TimeHeightConvolutionComponentPrecomputedIndexes>");
 This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
 
MatrixIndexT Stride() const
 
int32 height_subsample_out
 
void Write(std::ostream &os, bool binary) const
 
const std::string WholeLine()
 
void ConvolveBackwardParams(const ConvolutionComputation &cc, const CuMatrixBase< BaseFloat > &input, const CuMatrixBase< BaseFloat > &output_deriv, BaseFloat alpha, CuMatrixBase< BaseFloat > *params_deriv)
This does the part of the backward derivative computation of convolution, that computes derivatives w...
 
const CuSubVector< Real > Row(MatrixIndexT i) const
 
virtual void Vectorize(VectorBase< BaseFloat > *params) const
Turns the parameters into vector form. 
 
Abstract base-class for neural-net components. 
 
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...
 
bool Check(bool check_heights_used=true, bool allow_height_padding=true) const
 
bool SplitStringToIntegers(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< I > *out)
Split a string (e.g. 
 
An abstract representation of a set of Indexes. 
 
void InitLearningRatesFromConfig(ConfigLine *cfl)
 
Keywords for search: natural gradient, naturalgradient, NG-SGD. 
 
This class represents a matrix that's stored on the GPU if we have one, and in memory if not...
 
virtual void FreezeNaturalGradient(bool freeze)
freezes/unfreezes NaturalGradient updates, if applicable (to be overriden by components that use Natu...
 
virtual void GetInputIndexes(const MiscComputationInfo &misc_info, const Index &output_index, std::vector< Index > *desired_indexes) const
This function only does something interesting for non-simple Components. 
 
void CopyRowsFromVec(const CuVectorBase< Real > &v)
This function has two modes of operation. 
 
virtual void UnVectorize(const VectorBase< BaseFloat > ¶ms)
Converts the parameters from vector form. 
 
virtual bool IsComputable(const MiscComputationInfo &misc_info, const Index &output_index, const IndexSet &input_index_set, std::vector< Index > *used_inputs) const
This function only does something interesting for non-simple Components, and it exists to make it pos...
 
void SortAndUniq(std::vector< T > *vec)
Sorts and uniq's (removes duplicates) from a vector. 
 
CuMatrix< BaseFloat > linear_params_
 
void UpdateNaturalGradient(const PrecomputedIndexes &indexes, const CuMatrixBase< BaseFloat > &in_value, const CuMatrixBase< BaseFloat > &out_deriv)
 
virtual void InitFromConfig(ConfigLine *cfl)
Initialize, from a ConfigLine object. 
 
virtual void * Propagate(const ComponentPrecomputedIndexes *indexes, const CuMatrixBase< BaseFloat > &in, CuMatrixBase< BaseFloat > *out) const
Propagate function. 
 
struct Index is intended to represent the various indexes by which we number the rows of the matrices...
 
std::set< int32 > all_time_offsets
 
virtual ComponentPrecomputedIndexes * PrecomputeIndexes(const MiscComputationInfo &misc_info, const std::vector< Index > &input_indexes, const std::vector< Index > &output_indexes, bool need_backprop) const
This function must return NULL for simple Components. 
 
void CopyColFromVec(const CuVectorBase< Real > &v, const MatrixIndexT col)
Copy vector into specific column of matrix. 
 
OnlineNaturalGradient preconditioner_out_
 
void ExpectOneOrTwoTokens(std::istream &is, bool binary, const std::string &token1, const std::string &token2)
This function is like ExpectToken but for two tokens, and it will either accept token1 and then token...
 
std::vector< int32 > all_time_offsets_
 
virtual PrecomputedIndexes * Copy() const
 
virtual void Scale(BaseFloat scale)
This virtual function when called on – an UpdatableComponent scales the parameters by "scale" when c...
 
virtual void Read(std::istream &is, bool binary)
Read function (used after we know the type of the Component); accepts input that is missing the token...
 
TimeHeightConvolutionComponent()
 
static void ExpectToken(const std::string &token, const std::string &what_we_are_parsing, const std::string **next_token)
 
void ConvolveBackwardData(const ConvolutionComputation &cc, const CuMatrixBase< BaseFloat > ¶ms, const CuMatrixBase< BaseFloat > &output_deriv, CuMatrixBase< BaseFloat > *input_deriv)
This does the part of the backward derivative computation of convolution, that propagates derivatives...
 
void Read(std::istream &is, bool binary)
 
virtual void Add(BaseFloat alpha, const Component &other)
This virtual function when called by – an UpdatableComponent adds the parameters of another updatabl...
 
virtual void Write(std::ostream &os, bool binary) const
 
virtual void ReorderIndexes(std::vector< Index > *input_indexes, std::vector< Index > *output_indexes) const
This function only does something interesting for non-simple Components. 
 
time_height_convolution::ConvolutionModel model_
 
void SplitStringToVector(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< std::string > *out)
Split a string using any of the single character delimiters. 
 
BaseFloat learning_rate_
learning rate (typically 0.0..0.01) 
 
virtual void Backprop(const std::string &debug_info, const ComponentPrecomputedIndexes *indexes, const CuMatrixBase< BaseFloat > &in_value, const CuMatrixBase< BaseFloat > &out_value, const CuMatrixBase< BaseFloat > &out_deriv, void *memo, Component *to_update, CuMatrixBase< BaseFloat > *in_deriv) const
Backprop function; depending on which of the arguments 'to_update' and 'in_deriv' are non-NULL...
 
std::string ReadUpdatableCommon(std::istream &is, bool binary)
 
void UpdateSimple(const PrecomputedIndexes &indexes, const CuMatrixBase< BaseFloat > &in_value, const CuMatrixBase< BaseFloat > &out_deriv)
 
virtual int32 OutputDim() const
Returns output-dimension of this component. 
 
void PreconditionDirections(CuMatrixBase< BaseFloat > *X, BaseFloat *scale)
This call implements the main functionality of this class. 
 
void CompileConvolutionComputation(const ConvolutionModel &model, const std::vector< Index > &input_indexes, const std::vector< Index > &output_indexes, const ConvolutionComputationOptions &opts, ConvolutionComputation *computation, std::vector< Index > *input_indexes_modified, std::vector< Index > *output_indexes_modified)
This function does the compilation for a convolution computation; it's a wrapper for the functions be...
 
Real TraceMatMat(const MatrixBase< Real > &A, const MatrixBase< Real > &B, MatrixTransposeType trans)
We need to declare this here as it will be a friend function. 
 
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. 
 
std::vector< Offset > offsets
 
MatrixIndexT Dim() const
Returns the dimension of the vector. 
 
CuSubMatrix< Real > RowRange(const MatrixIndexT row_offset, const MatrixIndexT num_rows) const
 
void Swap(OnlineNaturalGradient *other)
 
virtual BaseFloat DotProduct(const UpdatableComponent &other) const
Computes dot-product between parameters of two instances of a Component. 
 
virtual void Write(std::ostream &os, bool binary) const
Write component to stream. 
 
virtual int32 InputDim() const
Returns input-dimension of this component. 
 
Class UpdatableComponent is a Component which has trainable parameters; it extends the interface of C...
 
void SetAlpha(BaseFloat alpha)
 
BaseFloat GetNumMinibatchesHistory() const
 
const Real * Data() const
Return data pointer (const). 
 
Matrix for CUDA computing. 
 
MatrixIndexT NumCols() const
 
This class is responsible for parsing input like hi-there xx=yyy a=b c empty= f-oo=Append(bar, sss) ba_z=123 bing='a b c' baz="a b c d='a b' e" and giving you access to the fields, in this case. 
 
virtual std::string Info() const
Returns some text-form information about this component, for diagnostics. 
 
bool is_gradient_
True if this component is to be treated as a gradient rather than as parameters. 
 
virtual void PerturbParams(BaseFloat stddev)
This function is to be used in testing. 
 
#define KALDI_ASSERT(cond)
 
void WriteUpdatableCommon(std::ostream &is, bool binary) const
 
CuVector< BaseFloat > bias_params_
 
virtual void Read(std::istream &os, bool binary)
 
std::set< int32 > required_time_offsets
 
virtual int32 NumParameters() const
The following new virtual function returns the total dimension of the parameters in this class...
 
bool GetValue(const std::string &key, std::string *value)
 
void ConsolidateMemory()
This virtual function relates to memory management, and avoiding fragmentation. 
 
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...
 
void SetNumMinibatchesHistory(BaseFloat num_minibatches_history)
 
BaseFloat GetAlpha() const
 
void PrintParameterStats(std::ostringstream &os, const std::string &name, const CuVectorBase< BaseFloat > ¶ms, bool include_mean)
Print to 'os' some information about the mean and standard deviation of some parameters, used in Info() functions in nnet-simple-component.cc. 
 
MatrixIndexT NumRows() const
Dimensions. 
 
Provides a vector abstraction class. 
 
bool use_natural_gradient_
 
OnlineNaturalGradient preconditioner_in_
 
std::vector< bool > time_offset_required_
 
bool IsSortedAndUniq(const std::vector< T > &vec)
Returns true if the vector is sorted and contains each element only once. 
 
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2. 
 
TimeHeightConvolutionComponent implements 2-dimensional convolution where one of the dimensions of co...
 
void ConvolveForward(const ConvolutionComputation &cc, const CuMatrixBase< BaseFloat > &input, const CuMatrixBase< BaseFloat > ¶ms, CuMatrixBase< BaseFloat > *output)
This does the forward computation of convolution. 
 
virtual std::string Info() const
Returns some text-form information about this component, for diagnostics. 
 
SubVector< Real > Range(const MatrixIndexT o, const MatrixIndexT l)
Returns a sub-vector of a vector (a range of elements). 
 
time_height_convolution::ConvolutionComputation computation