Keywords: natural gradient descent, NG-SGD, naturalgradient. More...
#include <nnet-component.h>
Public Member Functions | |
virtual std::string | Type () const |
virtual void | Read (std::istream &is, bool binary) |
virtual void | Write (std::ostream &os, bool binary) const |
Write component to stream. More... | |
void | Init (BaseFloat learning_rate, int32 input_dim, int32 output_dim, BaseFloat param_stddev, BaseFloat bias_stddev, int32 rank_in, int32 rank_out, int32 update_period, BaseFloat num_samples_history, BaseFloat alpha, BaseFloat max_change_per_sample) |
void | Init (BaseFloat learning_rate, int32 rank_in, int32 rank_out, int32 update_period, BaseFloat num_samples_history, BaseFloat alpha, BaseFloat max_change_per_sample, std::string matrix_filename) |
virtual void | Resize (int32 input_dim, int32 output_dim) |
AffineComponentPreconditionedOnline (const AffineComponent &orig, int32 rank_in, int32 rank_out, int32 update_period, BaseFloat eta, BaseFloat alpha) | |
virtual void | InitFromString (std::string args) |
Initialize, typically from a line of a config file. More... | |
virtual std::string | Info () const |
virtual Component * | Copy () const |
Copy component (deep copy). More... | |
AffineComponentPreconditionedOnline () | |
Public Member Functions inherited from AffineComponent | |
AffineComponent (const AffineComponent &other) | |
AffineComponent (const CuMatrixBase< BaseFloat > &linear_params, const CuVectorBase< BaseFloat > &bias_params, BaseFloat learning_rate) | |
virtual int32 | InputDim () const |
Get size of input vectors. More... | |
virtual int32 | OutputDim () const |
Get size of output vectors. More... | |
void | Init (BaseFloat learning_rate, int32 input_dim, int32 output_dim, BaseFloat param_stddev, BaseFloat bias_stddev) |
void | Init (BaseFloat learning_rate, std::string matrix_filename) |
Component * | CollapseWithNext (const AffineComponent &next) const |
Component * | CollapseWithNext (const FixedAffineComponent &next) const |
Component * | CollapseWithNext (const FixedScaleComponent &next) const |
Component * | CollapseWithPrevious (const FixedAffineComponent &prev) const |
AffineComponent () | |
virtual bool | BackpropNeedsInput () const |
virtual bool | BackpropNeedsOutput () const |
virtual void | Propagate (const ChunkInfo &in_info, const ChunkInfo &out_info, const CuMatrixBase< BaseFloat > &in, CuMatrixBase< BaseFloat > *out) const |
Perform forward pass propagation Input->Output. More... | |
virtual void | Scale (BaseFloat scale) |
This new virtual function scales the parameters by this amount. More... | |
virtual void | Add (BaseFloat alpha, const UpdatableComponent &other) |
This new virtual function adds the parameters of another updatable component, times some constant, to the current parameters. More... | |
virtual void | Backprop (const ChunkInfo &in_info, const ChunkInfo &out_info, const CuMatrixBase< BaseFloat > &in_value, const CuMatrixBase< BaseFloat > &out_value, const CuMatrixBase< BaseFloat > &out_deriv, Component *to_update, CuMatrix< BaseFloat > *in_deriv) const |
Perform backward pass propagation of the derivative, and also either update the model (if to_update == this) or update another model or compute the model derivative (otherwise). More... | |
virtual void | SetZero (bool treat_as_gradient) |
Set parameters to zero, and if treat_as_gradient is true, we'll be treating this as a gradient so set the learning rate to 1 and make any other changes necessary (there's a variable we have to set for the MixtureProbComponent). More... | |
virtual BaseFloat | DotProduct (const UpdatableComponent &other) const |
Here, "other" is a component of the same specific type. More... | |
virtual void | PerturbParams (BaseFloat stddev) |
We introduce a new virtual function that only applies to class UpdatableComponent. More... | |
virtual void | SetParams (const VectorBase< BaseFloat > &bias, const MatrixBase< BaseFloat > &linear) |
const CuVector< BaseFloat > & | BiasParams () |
const CuMatrix< BaseFloat > & | LinearParams () |
virtual int32 | GetParameterDim () const |
The following new virtual function returns the total dimension of the parameters in this class. More... | |
virtual void | Vectorize (VectorBase< BaseFloat > *params) const |
Turns the parameters into vector form. More... | |
virtual void | UnVectorize (const VectorBase< BaseFloat > ¶ms) |
Converts the parameters from vector form. More... | |
virtual void | LimitRank (int32 dimension, AffineComponent **a, AffineComponent **b) const |
This function is for getting a low-rank approximations of this AffineComponent by two AffineComponents. More... | |
void | Widen (int32 new_dimension, BaseFloat param_stddev, BaseFloat bias_stddev, std::vector< NonlinearComponent *> c2, AffineComponent *c3) |
This function is implemented in widen-nnet.cc. More... | |
Public Member Functions inherited from UpdatableComponent | |
UpdatableComponent (const UpdatableComponent &other) | |
void | Init (BaseFloat learning_rate) |
UpdatableComponent (BaseFloat learning_rate) | |
UpdatableComponent () | |
virtual | ~UpdatableComponent () |
void | SetLearningRate (BaseFloat lrate) |
Sets the learning rate of gradient descent. More... | |
BaseFloat | LearningRate () const |
Gets the learning rate of gradient descent. More... | |
Public Member Functions inherited from Component | |
Component () | |
virtual int32 | Index () const |
Returns the index in the sequence of layers in the neural net; intended only to be used in debugging information. More... | |
virtual void | SetIndex (int32 index) |
virtual std::vector< int32 > | Context () const |
Return a vector describing the temporal context this component requires for each frame of output, as a sorted list. More... | |
void | Propagate (const ChunkInfo &in_info, const ChunkInfo &out_info, const CuMatrixBase< BaseFloat > &in, CuMatrix< BaseFloat > *out) const |
A non-virtual propagate function that first resizes output if necessary. More... | |
virtual | ~Component () |
Private Member Functions | |
KALDI_DISALLOW_COPY_AND_ASSIGN (AffineComponentPreconditionedOnline) | |
BaseFloat | GetScalingFactor (const CuVectorBase< BaseFloat > &in_products, BaseFloat gamma_prod, CuVectorBase< BaseFloat > *out_products) |
The following function is only called if max_change_per_sample_ > 0, it returns a scaling factor alpha <= 1.0 (1.0 in the normal case) that enforces the "max-change" constraint. More... | |
void | SetPreconditionerConfigs () |
virtual void | Update (const CuMatrixBase< BaseFloat > &in_value, const CuMatrixBase< BaseFloat > &out_deriv) |
Additional Inherited Members | |
Static Public Member Functions inherited from Component | |
static Component * | ReadNew (std::istream &is, bool binary) |
Read component from stream. More... | |
static Component * | NewFromString (const std::string &initializer_line) |
Initialize the Component from one line that will contain first the type, e.g. More... | |
static Component * | NewComponentOfType (const std::string &type) |
Return a new Component of the given type e.g. More... | |
Protected Member Functions inherited from AffineComponent | |
virtual void | UpdateSimple (const CuMatrixBase< BaseFloat > &in_value, const CuMatrixBase< BaseFloat > &out_deriv) |
const AffineComponent & | operator= (const AffineComponent &other) |
Protected Attributes inherited from AffineComponent | |
CuMatrix< BaseFloat > | linear_params_ |
CuVector< BaseFloat > | bias_params_ |
bool | is_gradient_ |
Protected Attributes inherited from UpdatableComponent | |
BaseFloat | learning_rate_ |
learning rate (0.0..0.01) More... | |
Keywords: natural gradient descent, NG-SGD, naturalgradient.
For the top-level of the natural gradient code look here, and also in nnet-precondition-online.h. AffineComponentPreconditionedOnline is, like AffineComponentPreconditioned, a version of AffineComponent that has a non-(multiple of unit) learning-rate matrix. See nnet-precondition-online.h for a description of the technique.
Definition at line 997 of file nnet-component.h.
AffineComponentPreconditionedOnline | ( | const AffineComponent & | orig, |
int32 | rank_in, | ||
int32 | rank_out, | ||
int32 | update_period, | ||
BaseFloat | eta, | ||
BaseFloat | alpha | ||
) |
Definition at line 1728 of file nnet-component.cc.
References AffineComponentPreconditionedOnline::alpha_, AffineComponent::bias_params_, AffineComponent::is_gradient_, UpdatableComponent::learning_rate_, AffineComponent::linear_params_, AffineComponentPreconditionedOnline::num_samples_history_, AffineComponentPreconditionedOnline::rank_in_, AffineComponentPreconditionedOnline::rank_out_, AffineComponentPreconditionedOnline::SetPreconditionerConfigs(), and AffineComponentPreconditionedOnline::update_period_.
|
inline |
Definition at line 1030 of file nnet-component.h.
References KALDI_DISALLOW_COPY_AND_ASSIGN.
Referenced by AffineComponentPreconditionedOnline::Copy().
|
virtual |
Copy component (deep copy).
Reimplemented from AffineComponent.
Definition at line 1821 of file nnet-component.cc.
References AffineComponentPreconditionedOnline::AffineComponentPreconditionedOnline(), AffineComponentPreconditionedOnline::alpha_, AffineComponent::bias_params_, AffineComponent::is_gradient_, UpdatableComponent::learning_rate_, AffineComponent::linear_params_, AffineComponentPreconditionedOnline::max_change_per_sample_, AffineComponentPreconditionedOnline::num_samples_history_, AffineComponentPreconditionedOnline::preconditioner_in_, AffineComponentPreconditionedOnline::preconditioner_out_, AffineComponentPreconditionedOnline::rank_in_, AffineComponentPreconditionedOnline::rank_out_, AffineComponentPreconditionedOnline::SetPreconditionerConfigs(), and AffineComponentPreconditionedOnline::update_period_.
|
private |
The following function is only called if max_change_per_sample_ > 0, it returns a scaling factor alpha <= 1.0 (1.0 in the normal case) that enforces the "max-change" constraint.
"in_products" is the inner product with itself of each row of the matrix of preconditioned input features; "out_products" is the same for the output derivatives. gamma_prod is a product of two scalars that are output by the preconditioning code (for the input and output), which we will need to multiply into the learning rate. out_products is a pointer because we modify it in-place.
Definition at line 1841 of file nnet-component.cc.
References CuVectorBase< Real >::ApplyPow(), CuVectorBase< Real >::Dim(), Component::Index(), KALDI_ASSERT, KALDI_LOG, UpdatableComponent::learning_rate_, AffineComponentPreconditionedOnline::max_change_per_sample_, CuVectorBase< Real >::MulElements(), and CuVectorBase< Real >::Sum().
Referenced by AffineComponentPreconditionedOnline::Update().
|
virtual |
Reimplemented from AffineComponent.
Definition at line 1798 of file nnet-component.cc.
References AffineComponentPreconditionedOnline::alpha_, AffineComponent::bias_params_, AffineComponent::InputDim(), kaldi::kTrans, UpdatableComponent::LearningRate(), AffineComponent::linear_params_, AffineComponentPreconditionedOnline::max_change_per_sample_, AffineComponentPreconditionedOnline::num_samples_history_, AffineComponent::OutputDim(), AffineComponentPreconditionedOnline::rank_in_, AffineComponentPreconditionedOnline::rank_out_, kaldi::TraceMatMat(), AffineComponentPreconditionedOnline::Type(), AffineComponentPreconditionedOnline::update_period_, and kaldi::VecVec().
void Init | ( | BaseFloat | learning_rate, |
int32 | input_dim, | ||
int32 | output_dim, | ||
BaseFloat | param_stddev, | ||
BaseFloat | bias_stddev, | ||
int32 | rank_in, | ||
int32 | rank_out, | ||
int32 | update_period, | ||
BaseFloat | num_samples_history, | ||
BaseFloat | alpha, | ||
BaseFloat | max_change_per_sample | ||
) |
Definition at line 1745 of file nnet-component.cc.
References AffineComponentPreconditionedOnline::alpha_, AffineComponent::bias_params_, UpdatableComponent::Init(), KALDI_ASSERT, AffineComponent::linear_params_, AffineComponentPreconditionedOnline::max_change_per_sample_, AffineComponentPreconditionedOnline::num_samples_history_, AffineComponentPreconditionedOnline::rank_in_, AffineComponentPreconditionedOnline::rank_out_, AffineComponentPreconditionedOnline::SetPreconditionerConfigs(), and AffineComponentPreconditionedOnline::update_period_.
Referenced by SpliceComponent::InitFromString(), SpliceMaxComponent::InitFromString(), BlockAffineComponent::InitFromString(), BlockAffineComponentPreconditioned::InitFromString(), SumGroupComponent::InitFromString(), PermuteComponent::InitFromString(), DctComponent::InitFromString(), FixedLinearComponent::InitFromString(), FixedAffineComponent::InitFromString(), FixedScaleComponent::InitFromString(), FixedBiasComponent::InitFromString(), DropoutComponent::InitFromString(), AdditiveNoiseComponent::InitFromString(), SumGroupComponent::Read(), DctComponent::Read(), and kaldi::nnet2::UnitTestAffineComponentPreconditionedOnline().
void Init | ( | BaseFloat | learning_rate, |
int32 | rank_in, | ||
int32 | rank_out, | ||
int32 | update_period, | ||
BaseFloat | num_samples_history, | ||
BaseFloat | alpha, | ||
BaseFloat | max_change_per_sample, | ||
std::string | matrix_filename | ||
) |
Definition at line 1704 of file nnet-component.cc.
References AffineComponent::bias_params_, UpdatableComponent::Init(), KALDI_ASSERT, AffineComponent::linear_params_, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), CuMatrixBase< Real >::Range(), and kaldi::ReadKaldiObject().
|
virtual |
Initialize, typically from a line of a config file.
The "args" will contain any parameters that need to be passed to the Component, e.g. dimensions.
Reimplemented from AffineComponent.
Definition at line 1648 of file nnet-component.cc.
References AffineComponent::Init(), AffineComponent::InputDim(), KALDI_ASSERT, KALDI_ERR, UpdatableComponent::learning_rate_, AffineComponent::OutputDim(), and kaldi::nnet2::ParseFromString().
Referenced by kaldi::nnet2::UnitTestAffineComponentPreconditionedOnline().
|
private |
|
virtual |
Reimplemented from AffineComponent.
Definition at line 1608 of file nnet-component.cc.
References AffineComponent::bias_params_, kaldi::nnet2::ExpectOneOrTwoTokens(), kaldi::ExpectToken(), KALDI_ASSERT, UpdatableComponent::learning_rate_, AffineComponent::linear_params_, kaldi::ReadBasicType(), kaldi::ReadToken(), and AffineComponent::Type().
Reimplemented from AffineComponent.
Definition at line 1594 of file nnet-component.cc.
References AffineComponent::bias_params_, KALDI_ASSERT, and AffineComponent::linear_params_.
|
private |
Definition at line 1693 of file nnet-component.cc.
Referenced by AffineComponentPreconditionedOnline::AffineComponentPreconditionedOnline(), AffineComponentPreconditionedOnline::Copy(), and AffineComponentPreconditionedOnline::Init().
|
inlinevirtual |
Reimplemented from AffineComponent.
Definition at line 999 of file nnet-component.h.
References kaldi::cu::Copy().
Referenced by AffineComponentPreconditionedOnline::Info(), SpliceComponent::InitFromString(), SpliceMaxComponent::InitFromString(), SumGroupComponent::InitFromString(), PermuteComponent::InitFromString(), DctComponent::InitFromString(), FixedLinearComponent::InitFromString(), FixedAffineComponent::InitFromString(), FixedScaleComponent::InitFromString(), FixedBiasComponent::InitFromString(), and AffineComponentPreconditionedOnline::Write().
|
privatevirtual |
Reimplemented from AffineComponent.
Definition at line 1869 of file nnet-component.cc.
References AffineComponent::bias_params_, CuVectorBase< Real >::CopyColFromMat(), AffineComponentPreconditionedOnline::GetScalingFactor(), kaldi::kNoTrans, kaldi::kTrans, kaldi::kUndefined, UpdatableComponent::learning_rate_, AffineComponent::linear_params_, AffineComponentPreconditionedOnline::max_change_per_sample_, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), OnlinePreconditioner::PreconditionDirections(), AffineComponentPreconditionedOnline::preconditioner_in_, AffineComponentPreconditionedOnline::preconditioner_out_, CuMatrixBase< Real >::Range(), and CuMatrix< Real >::Resize().
|
virtual |
Write component to stream.
Reimplemented from AffineComponent.
Definition at line 1772 of file nnet-component.cc.
References AffineComponentPreconditionedOnline::alpha_, AffineComponent::bias_params_, UpdatableComponent::learning_rate_, AffineComponent::linear_params_, AffineComponentPreconditionedOnline::max_change_per_sample_, AffineComponentPreconditionedOnline::num_samples_history_, AffineComponentPreconditionedOnline::rank_in_, AffineComponentPreconditionedOnline::rank_out_, AffineComponentPreconditionedOnline::Type(), AffineComponentPreconditionedOnline::update_period_, kaldi::WriteBasicType(), and kaldi::WriteToken().
|
private |
Definition at line 1042 of file nnet-component.h.
Referenced by AffineComponentPreconditionedOnline::AffineComponentPreconditionedOnline(), AffineComponentPreconditionedOnline::Copy(), BlockAffineComponentPreconditioned::Copy(), AffineComponentPreconditionedOnline::Info(), AffineComponentPreconditionedOnline::Init(), BlockAffineComponentPreconditioned::Init(), BlockAffineComponentPreconditioned::Read(), BlockAffineComponentPreconditioned::Update(), AffineComponentPreconditionedOnline::Write(), and BlockAffineComponentPreconditioned::Write().
|
private |
Definition at line 1048 of file nnet-component.h.
Referenced by AffineComponentPreconditionedOnline::Copy(), AffineComponentPreconditionedOnline::GetScalingFactor(), AffineComponentPreconditionedOnline::Info(), AffineComponentPreconditionedOnline::Init(), AffineComponentPreconditionedOnline::Update(), and AffineComponentPreconditionedOnline::Write().
|
private |
Definition at line 1041 of file nnet-component.h.
Referenced by AffineComponentPreconditionedOnline::AffineComponentPreconditionedOnline(), AffineComponentPreconditionedOnline::Copy(), AffineComponentPreconditionedOnline::Info(), AffineComponentPreconditionedOnline::Init(), and AffineComponentPreconditionedOnline::Write().
|
private |
Definition at line 1044 of file nnet-component.h.
Referenced by AffineComponentPreconditionedOnline::Copy(), and AffineComponentPreconditionedOnline::Update().
|
private |
Definition at line 1046 of file nnet-component.h.
Referenced by AffineComponentPreconditionedOnline::Copy(), and AffineComponentPreconditionedOnline::Update().
|
private |
Definition at line 1038 of file nnet-component.h.
Referenced by AffineComponentPreconditionedOnline::AffineComponentPreconditionedOnline(), AffineComponentPreconditionedOnline::Copy(), AffineComponentPreconditionedOnline::Info(), AffineComponentPreconditionedOnline::Init(), and AffineComponentPreconditionedOnline::Write().
|
private |
Definition at line 1039 of file nnet-component.h.
Referenced by AffineComponentPreconditionedOnline::AffineComponentPreconditionedOnline(), AffineComponentPreconditionedOnline::Copy(), AffineComponentPreconditionedOnline::Info(), AffineComponentPreconditionedOnline::Init(), and AffineComponentPreconditionedOnline::Write().
|
private |
Definition at line 1040 of file nnet-component.h.
Referenced by AffineComponentPreconditionedOnline::AffineComponentPreconditionedOnline(), AffineComponentPreconditionedOnline::Copy(), AffineComponentPreconditionedOnline::Info(), AffineComponentPreconditionedOnline::Init(), and AffineComponentPreconditionedOnline::Write().