#include <nnet-component.h>
Public Member Functions | |
virtual int32 | InputDim () const |
Get size of input vectors. More... | |
virtual int32 | OutputDim () const |
Get size of output vectors. More... | |
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... | |
void | Init (BaseFloat learning_rate, int32 input_dim, int32 output_dim, BaseFloat param_stddev, BaseFloat bias_stddev, int32 num_blocks) |
virtual void | InitFromString (std::string args) |
Initialize, typically from a line of a config file. More... | |
BlockAffineComponent () | |
virtual std::string | Type () const |
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 | 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 void | Read (std::istream &is, bool binary) |
virtual void | Write (std::ostream &os, bool binary) const |
Write component to stream. More... | |
virtual BaseFloat | DotProduct (const UpdatableComponent &other) const |
Here, "other" is a component of the same specific type. More... | |
virtual Component * | Copy () const |
Copy component (deep copy). More... | |
virtual void | PerturbParams (BaseFloat stddev) |
We introduce a new virtual function that only applies to class UpdatableComponent. 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... | |
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... | |
virtual std::string | Info () const |
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 () |
Protected Member Functions | |
virtual void | Update (const CuMatrixBase< BaseFloat > &in_value, const CuMatrixBase< BaseFloat > &out_deriv) |
virtual void | UpdateSimple (const CuMatrixBase< BaseFloat > &in_value, const CuMatrixBase< BaseFloat > &out_deriv) |
Protected Attributes | |
CuMatrix< BaseFloat > | linear_params_ |
CuVector< BaseFloat > | bias_params_ |
int32 | num_blocks_ |
Protected Attributes inherited from UpdatableComponent | |
BaseFloat | learning_rate_ |
learning rate (0.0..0.01) More... | |
Private Member Functions | |
KALDI_DISALLOW_COPY_AND_ASSIGN (BlockAffineComponent) | |
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... | |
Definition at line 1171 of file nnet-component.h.
|
inline |
Definition at line 1186 of file nnet-component.h.
|
virtual |
This new virtual function adds the parameters of another updatable component, times some constant, to the current parameters.
Implements UpdatableComponent.
Definition at line 1965 of file nnet-component.cc.
References AffineComponent::bias_params_, BlockAffineComponent::bias_params_, KALDI_ASSERT, AffineComponent::linear_params_, and BlockAffineComponent::linear_params_.
|
virtual |
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).
Note: in_value and out_value are the values of the input and output of the component, and these may be dummy variables if respectively BackpropNeedsInput() or BackpropNeedsOutput() return false for that component (not all components need these).
num_chunks lets us treat the input matrix as contiguous-in-time chunks of equal size; it only matters if splicing is involved.
Implements Component.
Definition at line 2035 of file nnet-component.cc.
References AffineComponent::InputDim(), KALDI_ASSERT, kaldi::kNoTrans, AffineComponent::linear_params_, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), CuMatrix< Real >::Resize(), and BlockAffineComponent::Update().
|
inlinevirtual |
Reimplemented from Component.
Definition at line 1188 of file nnet-component.h.
|
inlinevirtual |
Reimplemented from Component.
Definition at line 1189 of file nnet-component.h.
References kaldi::cu::Copy(), kaldi::nnet3::DotProduct(), kaldi::nnet3::PerturbParams(), and Component::Propagate().
|
virtual |
Copy component (deep copy).
Implements Component.
Reimplemented in BlockAffineComponentPreconditioned.
Definition at line 1951 of file nnet-component.cc.
References AffineComponent::bias_params_, BlockAffineComponent::bias_params_, UpdatableComponent::learning_rate_, AffineComponent::linear_params_, BlockAffineComponent::linear_params_, and BlockAffineComponent::num_blocks_.
|
virtual |
Here, "other" is a component of the same specific type.
This function computes the dot product in parameters, and is computed while automatically adjusting learning rates; typically, one of the two will actually contain the gradient.
Implements UpdatableComponent.
Definition at line 1943 of file nnet-component.cc.
References AffineComponent::bias_params_, BlockAffineComponent::bias_params_, kaldi::kTrans, AffineComponent::linear_params_, BlockAffineComponent::linear_params_, kaldi::TraceMatMat(), and kaldi::VecVec().
|
virtual |
The following new virtual function returns the total dimension of the parameters in this class.
E.g. used for L-BFGS update
Reimplemented from UpdatableComponent.
Definition at line 2142 of file nnet-component.cc.
References AffineComponent::InputDim(), and AffineComponent::OutputDim().
void Init | ( | BaseFloat | learning_rate, |
int32 | input_dim, | ||
int32 | output_dim, | ||
BaseFloat | param_stddev, | ||
BaseFloat | bias_stddev, | ||
int32 | num_blocks | ||
) |
Definition at line 2074 of file nnet-component.cc.
References AffineComponent::bias_params_, UpdatableComponent::Init(), KALDI_ASSERT, and AffineComponent::linear_params_.
Referenced by BlockAffineComponentPreconditioned::Init(), and kaldi::nnet2::UnitTestBlockAffineComponent().
|
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.
Implements Component.
Reimplemented in BlockAffineComponentPreconditioned.
Definition at line 2093 of file nnet-component.cc.
References AffineComponentPreconditionedOnline::Init(), KALDI_ERR, UpdatableComponent::learning_rate_, and kaldi::nnet2::ParseFromString().
Referenced by kaldi::nnet2::UnitTestBlockAffineComponent().
|
inlinevirtual |
Get size of input vectors.
Implements Component.
Definition at line 1173 of file nnet-component.h.
|
private |
|
inlinevirtual |
Get size of output vectors.
Implements Component.
Definition at line 1174 of file nnet-component.h.
|
virtual |
We introduce a new virtual function that only applies to class UpdatableComponent.
This is used in testing.
Implements UpdatableComponent.
Definition at line 1933 of file nnet-component.cc.
References AffineComponent::bias_params_, AffineComponent::linear_params_, CuVectorBase< Real >::SetRandn(), and CuMatrixBase< Real >::SetRandn().
|
virtual |
Perform forward pass propagation Input->Output.
Each row is one frame or training example. Interpreted as "num_chunks" equally sized chunks of frames; this only matters for layers that do things like context splicing. Typically this variable will either be 1 (when we're processing a single contiguous chunk of data) or will be the same as in.NumFrames(), but other values are possible if some layers do splicing.
Implements Component.
Definition at line 1974 of file nnet-component.cc.
References AffineComponent::bias_params_, ChunkInfo::CheckSize(), CuMatrixBase< Real >::CopyRowsFromVec(), KALDI_ASSERT, kaldi::kNoTrans, kaldi::kTrans, AffineComponent::linear_params_, ChunkInfo::NumChunks(), CuMatrixBase< Real >::NumCols(), and CuMatrixBase< Real >::NumRows().
|
virtual |
Implements Component.
Reimplemented in BlockAffineComponentPreconditioned.
Definition at line 2116 of file nnet-component.cc.
References AffineComponent::bias_params_, kaldi::nnet2::ExpectOneOrTwoTokens(), kaldi::ExpectToken(), UpdatableComponent::learning_rate_, AffineComponent::linear_params_, and kaldi::ReadBasicType().
|
virtual |
This new virtual function scales the parameters by this amount.
Implements UpdatableComponent.
Definition at line 1960 of file nnet-component.cc.
References AffineComponent::bias_params_, and AffineComponent::linear_params_.
|
virtual |
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).
Implements UpdatableComponent.
Reimplemented in BlockAffineComponentPreconditioned.
Definition at line 1925 of file nnet-component.cc.
References AffineComponent::bias_params_, AffineComponent::linear_params_, and UpdatableComponent::SetLearningRate().
Referenced by BlockAffineComponentPreconditioned::SetZero().
|
inlinevirtual |
Implements Component.
Reimplemented in BlockAffineComponentPreconditioned.
Definition at line 1187 of file nnet-component.h.
|
virtual |
Converts the parameters from vector form.
Reimplemented from UpdatableComponent.
Definition at line 2153 of file nnet-component.cc.
References AffineComponent::bias_params_, AffineComponent::linear_params_, and VectorBase< Real >::Range().
|
inlineprotectedvirtual |
Reimplemented in BlockAffineComponentPreconditioned.
Definition at line 1211 of file nnet-component.h.
Referenced by BlockAffineComponent::Backprop().
|
protectedvirtual |
Definition at line 2012 of file nnet-component.cc.
References CuMatrixBase< Real >::AddMatMat(), AffineComponent::bias_params_, kaldi::kNoTrans, kaldi::kTrans, UpdatableComponent::learning_rate_, AffineComponent::linear_params_, and CuMatrixBase< Real >::NumRows().
|
virtual |
Turns the parameters into vector form.
We put the vector form on the CPU, because in the kinds of situations where we do this, we'll tend to use too much memory for the GPU.
Reimplemented from UpdatableComponent.
Definition at line 2147 of file nnet-component.cc.
References AffineComponent::bias_params_, AffineComponent::linear_params_, and VectorBase< Real >::Range().
|
virtual |
Write component to stream.
Implements Component.
Reimplemented in BlockAffineComponentPreconditioned.
Definition at line 2128 of file nnet-component.cc.
References AffineComponent::bias_params_, UpdatableComponent::learning_rate_, AffineComponent::linear_params_, kaldi::WriteBasicType(), and kaldi::WriteToken().
Definition at line 1231 of file nnet-component.h.
Referenced by BlockAffineComponent::Add(), BlockAffineComponent::Copy(), BlockAffineComponentPreconditioned::Copy(), and BlockAffineComponent::DotProduct().
Definition at line 1230 of file nnet-component.h.
Referenced by BlockAffineComponent::Add(), BlockAffineComponent::Copy(), BlockAffineComponentPreconditioned::Copy(), and BlockAffineComponent::DotProduct().
|
protected |
Definition at line 1232 of file nnet-component.h.
Referenced by BlockAffineComponent::Copy(), and BlockAffineComponentPreconditioned::Copy().