Abstract class, basic element of the network, it is a box with defined inputs, outputs, and tranformation functions interface. More...
#include <nnet-component.h>
Public Member Functions | |
Component () | |
virtual std::string | Type () const =0 |
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 void | InitFromString (std::string args)=0 |
Initialize, typically from a line of a config file. More... | |
virtual int32 | InputDim () const =0 |
Get size of input vectors. More... | |
virtual int32 | OutputDim () const =0 |
Get size of output vectors. More... | |
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... | |
virtual void | Propagate (const ChunkInfo &in_info, const ChunkInfo &out_info, const CuMatrixBase< BaseFloat > &in, CuMatrixBase< BaseFloat > *out) const =0 |
Perform forward pass propagation Input->Output. 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 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 =0 |
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 bool | BackpropNeedsInput () const |
virtual bool | BackpropNeedsOutput () const |
virtual Component * | Copy () const =0 |
Copy component (deep copy). More... | |
virtual void | Read (std::istream &is, bool binary)=0 |
virtual void | Write (std::ostream &os, bool binary) const =0 |
Write component to stream. More... | |
virtual std::string | Info () const |
virtual | ~Component () |
Static Public Member Functions | |
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... | |
Private Member Functions | |
KALDI_DISALLOW_COPY_AND_ASSIGN (Component) | |
Private Attributes | |
int32 | index_ |
Abstract class, basic element of the network, it is a box with defined inputs, outputs, and tranformation functions interface.
It is able to propagate and backpropagate exact implementation is to be implemented in descendants.
Definition at line 157 of file nnet-component.h.
|
inline |
Definition at line 159 of file nnet-component.h.
|
inlinevirtual |
Definition at line 264 of file nnet-component.h.
|
pure 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.
Implemented in Convolutional1dComponent, AdditiveNoiseComponent, DropoutComponent, FixedBiasComponent, FixedScaleComponent, FixedAffineComponent, FixedLinearComponent, DctComponent, PermuteComponent, SumGroupComponent, BlockAffineComponent, SpliceMaxComponent, SpliceComponent, AffineComponent, LogSoftmaxComponent, SoftmaxComponent, ScaleComponent, SoftHingeComponent, RectifiedLinearComponent, PowerComponent, TanhComponent, SigmoidComponent, NormalizeComponent, PnormComponent, MaxpoolingComponent, and MaxoutComponent.
Referenced by NnetComputer::Backprop(), NnetDiscriminativeUpdater::Backprop(), NnetUpdater::Backprop(), NnetRescaler::RescaleComponent(), and kaldi::nnet2::UnitTestGenericComponentInternal().
|
inlinevirtual |
Reimplemented in Convolutional1dComponent, AdditiveNoiseComponent, DropoutComponent, FixedBiasComponent, FixedScaleComponent, FixedAffineComponent, FixedLinearComponent, DctComponent, PermuteComponent, SumGroupComponent, BlockAffineComponent, SpliceMaxComponent, SpliceComponent, AffineComponent, LogSoftmaxComponent, SoftmaxComponent, ScaleComponent, SoftHingeComponent, RectifiedLinearComponent, PowerComponent, TanhComponent, SigmoidComponent, NormalizeComponent, PnormComponent, MaxpoolingComponent, and MaxoutComponent.
Definition at line 235 of file nnet-component.h.
Referenced by NnetComputer::Propagate(), NnetDiscriminativeUpdater::Propagate(), NnetUpdater::Propagate(), and kaldi::nnet2::UnitTestGenericComponentInternal().
|
inlinevirtual |
Reimplemented in Convolutional1dComponent, AdditiveNoiseComponent, DropoutComponent, FixedBiasComponent, FixedScaleComponent, FixedAffineComponent, FixedLinearComponent, DctComponent, PermuteComponent, SumGroupComponent, BlockAffineComponent, SpliceMaxComponent, SpliceComponent, AffineComponent, LogSoftmaxComponent, SoftmaxComponent, ScaleComponent, SoftHingeComponent, RectifiedLinearComponent, PowerComponent, TanhComponent, SigmoidComponent, NormalizeComponent, PnormComponent, MaxpoolingComponent, and MaxoutComponent.
Definition at line 237 of file nnet-component.h.
References kaldi::cu::Copy().
Referenced by NnetComputer::Propagate(), NnetDiscriminativeUpdater::Propagate(), NnetUpdater::Propagate(), and kaldi::nnet2::UnitTestGenericComponentInternal().
|
inlinevirtual |
Return a vector describing the temporal context this component requires for each frame of output, as a sorted list.
The default implementation returns a vector ( 0 ), but a splicing layer might return e.g. (-2, -1, 0, 1, 2), but it doesn't have to be contiguous. Note : The context needed by the entire network is a function of the contexts needed by all the components. It is required that Context().front() <= 0 and Context().back() >= 0.
Reimplemented in SpliceMaxComponent, and SpliceComponent.
Definition at line 188 of file nnet-component.h.
Referenced by Nnet::ComputeChunkInfo(), and NnetOnlineComputer::Propagate().
|
pure virtual |
Copy component (deep copy).
Implemented in Convolutional1dComponent, AdditiveNoiseComponent, DropoutComponent, FixedBiasComponent, FixedScaleComponent, FixedAffineComponent, FixedLinearComponent, DctComponent, PermuteComponent, SumGroupComponent, BlockAffineComponentPreconditioned, BlockAffineComponent, SpliceMaxComponent, SpliceComponent, AffineComponentPreconditionedOnline, AffineComponentPreconditioned, AffineComponent, LogSoftmaxComponent, SoftmaxComponent, ScaleComponent, SoftHingeComponent, RectifiedLinearComponent, PowerComponent, TanhComponent, SigmoidComponent, NormalizeComponent, PnormComponent, MaxpoolingComponent, and MaxoutComponent.
Referenced by kaldi::nnet2::InsertComponents(), kaldi::nnet2::ReplaceLastComponents(), and kaldi::nnet2::UnitTestGenericComponentInternal().
|
inlinevirtual |
Returns the index in the sequence of layers in the neural net; intended only to be used in debugging information.
Definition at line 166 of file nnet-component.h.
Referenced by AffineComponentPreconditioned::GetScalingFactor(), and AffineComponentPreconditionedOnline::GetScalingFactor().
|
virtual |
Reimplemented in Convolutional1dComponent, DropoutComponent, FixedBiasComponent, FixedScaleComponent, FixedAffineComponent, FixedLinearComponent, DctComponent, SpliceMaxComponent, SpliceComponent, AffineComponentPreconditionedOnline, AffineComponentPreconditioned, AffineComponent, ScaleComponent, PowerComponent, PnormComponent, MaxpoolingComponent, MaxoutComponent, and UpdatableComponent.
Definition at line 305 of file nnet-component.cc.
References Component::InputDim(), Component::OutputDim(), and Component::Type().
Referenced by SpliceComponent::Info(), SpliceMaxComponent::Info(), DctComponent::Info(), FixedLinearComponent::Info(), FixedAffineComponent::Info(), FixedScaleComponent::Info(), FixedBiasComponent::Info(), DropoutComponent::Info(), main(), and kaldi::nnet2::UnitTestGenericComponentInternal().
|
pure 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.
Implemented in Convolutional1dComponent, AdditiveNoiseComponent, DropoutComponent, FixedBiasComponent, FixedScaleComponent, FixedAffineComponent, FixedLinearComponent, DctComponent, PermuteComponent, SumGroupComponent, BlockAffineComponentPreconditioned, BlockAffineComponent, SpliceMaxComponent, SpliceComponent, AffineComponentPreconditionedOnline, AffineComponentPreconditioned, AffineComponent, ScaleComponent, PowerComponent, PnormComponent, MaxpoolingComponent, MaxoutComponent, and NonlinearComponent.
Referenced by Component::NewFromString().
|
pure virtual |
Get size of input vectors.
Implemented in Convolutional1dComponent, AdditiveNoiseComponent, DropoutComponent, FixedBiasComponent, FixedScaleComponent, FixedAffineComponent, FixedLinearComponent, DctComponent, PermuteComponent, SumGroupComponent, BlockAffineComponent, SpliceMaxComponent, SpliceComponent, AffineComponent, ScaleComponent, PowerComponent, PnormComponent, MaxpoolingComponent, MaxoutComponent, and NonlinearComponent.
Referenced by Component::Info(), UpdatableComponent::Info(), main(), NnetOnlineComputer::Propagate(), kaldi::nnet2::UnitTestGenericComponentInternal(), and NonlinearComponent::UpdateStats().
|
private |
|
static |
Return a new Component of the given type e.g.
"SoftmaxComponent", or NULL if no such type exists.
Definition at line 51 of file nnet-component.cc.
Referenced by Component::NewFromString(), and Component::ReadNew().
|
static |
Initialize the Component from one line that will contain first the type, e.g.
SigmoidComponent, and then a number of tokens (typically integers or floats) that will be used to initialize the component.
Definition at line 116 of file nnet-component.cc.
References Component::InitFromString(), KALDI_ERR, and Component::NewComponentOfType().
Referenced by Nnet::Init().
|
pure virtual |
Get size of output vectors.
Implemented in Convolutional1dComponent, AdditiveNoiseComponent, DropoutComponent, FixedBiasComponent, FixedScaleComponent, FixedAffineComponent, FixedLinearComponent, DctComponent, PermuteComponent, SumGroupComponent, BlockAffineComponent, SpliceMaxComponent, SpliceComponent, AffineComponent, ScaleComponent, PowerComponent, PnormComponent, MaxpoolingComponent, MaxoutComponent, and NonlinearComponent.
Referenced by kaldi::nnet2::GiveNnetCorrectTopology(), Component::Info(), UpdatableComponent::Info(), and kaldi::nnet2::UnitTestGenericComponentInternal().
|
pure 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.
Implemented in Convolutional1dComponent, AdditiveNoiseComponent, DropoutComponent, FixedBiasComponent, FixedScaleComponent, FixedAffineComponent, FixedLinearComponent, DctComponent, PermuteComponent, SumGroupComponent, BlockAffineComponent, SpliceMaxComponent, SpliceComponent, AffineComponent, LogSoftmaxComponent, SoftmaxComponent, ScaleComponent, SoftHingeComponent, RectifiedLinearComponent, PowerComponent, TanhComponent, SigmoidComponent, NormalizeComponent, PnormComponent, MaxpoolingComponent, and MaxoutComponent.
Referenced by NormalizeComponent::BackpropNeedsOutput(), TanhComponent::BackpropNeedsOutput(), RectifiedLinearComponent::BackpropNeedsOutput(), SoftHingeComponent::BackpropNeedsOutput(), ScaleComponent::BackpropNeedsOutput(), SoftmaxComponent::BackpropNeedsOutput(), LogSoftmaxComponent::BackpropNeedsOutput(), AffineComponent::BackpropNeedsOutput(), BlockAffineComponent::BackpropNeedsOutput(), SumGroupComponent::BackpropNeedsOutput(), PermuteComponent::BackpropNeedsOutput(), DropoutComponent::BackpropNeedsOutput(), Convolutional1dComponent::BackpropNeedsOutput(), SpliceComponent::Context(), SpliceMaxComponent::Context(), SigmoidComponent::Copy(), AdditiveNoiseComponent::Copy(), MaxoutComponent::OutputDim(), MaxpoolingComponent::OutputDim(), PnormComponent::OutputDim(), PowerComponent::OutputDim(), DctComponent::OutputDim(), FixedLinearComponent::OutputDim(), FixedAffineComponent::OutputDim(), FixedScaleComponent::OutputDim(), FixedBiasComponent::OutputDim(), NnetComputer::Propagate(), NnetDiscriminativeUpdater::Propagate(), NnetOnlineComputer::Propagate(), NnetUpdater::Propagate(), NnetRescaler::Rescale(), NnetRescaler::RescaleComponent(), and kaldi::nnet2::UnitTestGenericComponentInternal().
|
inline |
A non-virtual propagate function that first resizes output if necessary.
Definition at line 203 of file nnet-component.h.
References ChunkInfo::NumCols(), CuMatrixBase< Real >::NumCols(), ChunkInfo::NumRows(), CuMatrixBase< Real >::NumRows(), and CuMatrix< Real >::Resize().
|
pure virtual |
Implemented in Convolutional1dComponent, AdditiveNoiseComponent, DropoutComponent, FixedBiasComponent, FixedScaleComponent, FixedAffineComponent, FixedLinearComponent, DctComponent, PermuteComponent, SumGroupComponent, BlockAffineComponentPreconditioned, BlockAffineComponent, SpliceMaxComponent, SpliceComponent, AffineComponentPreconditionedOnline, AffineComponentPreconditioned, AffineComponent, ScaleComponent, PowerComponent, PnormComponent, MaxpoolingComponent, MaxoutComponent, and NonlinearComponent.
Referenced by Component::ReadNew().
Read component from stream.
Definition at line 37 of file nnet-component.cc.
References KALDI_ERR, Component::NewComponentOfType(), Component::Read(), and kaldi::ReadToken().
Referenced by Nnet::Read(), and kaldi::nnet2::UnitTestGenericComponentInternal().
|
inlinevirtual |
Definition at line 168 of file nnet-component.h.
|
pure virtual |
Implemented in Convolutional1dComponent, AdditiveNoiseComponent, DropoutComponent, FixedBiasComponent, FixedScaleComponent, FixedAffineComponent, FixedLinearComponent, DctComponent, PermuteComponent, SumGroupComponent, BlockAffineComponentPreconditioned, BlockAffineComponent, SpliceMaxComponent, SpliceComponent, AffineComponentPreconditionedOnline, AffineComponentPreconditioned, AffineComponent, LogSoftmaxComponent, SoftmaxComponent, ScaleComponent, SoftHingeComponent, RectifiedLinearComponent, PowerComponent, TanhComponent, SigmoidComponent, NormalizeComponent, PnormComponent, MaxpoolingComponent, and MaxoutComponent.
Referenced by kaldi::nnet2::GiveNnetCorrectTopology(), Component::Info(), UpdatableComponent::Info(), MaxoutComponent::Info(), PnormComponent::Info(), PowerComponent::Info(), ScaleComponent::Info(), NonlinearComponent::InitFromString(), MaxoutComponent::InitFromString(), PnormComponent::InitFromString(), PowerComponent::InitFromString(), NonlinearComponent::Read(), Nnet::ScaleLearningRates(), and NonlinearComponent::Write().
|
pure virtual |
Write component to stream.
Implemented in Convolutional1dComponent, AdditiveNoiseComponent, DropoutComponent, FixedBiasComponent, FixedScaleComponent, FixedAffineComponent, FixedLinearComponent, DctComponent, PermuteComponent, SumGroupComponent, BlockAffineComponentPreconditioned, BlockAffineComponent, SpliceMaxComponent, SpliceComponent, AffineComponentPreconditionedOnline, AffineComponentPreconditioned, AffineComponent, ScaleComponent, PowerComponent, PnormComponent, MaxpoolingComponent, MaxoutComponent, and NonlinearComponent.
Referenced by kaldi::nnet2::UnitTestGenericComponentInternal().
|
private |
Definition at line 267 of file nnet-component.h.