Component Class Referenceabstract

Abstract base-class for neural-net components. More...

#include <nnet-component-itf.h>

Inheritance diagram for Component:

Public Member Functions

virtual void * Propagate (const ComponentPrecomputedIndexes *indexes, const CuMatrixBase< BaseFloat > &in, CuMatrixBase< BaseFloat > *out) const =0
 Propagate function. More...
 
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 =0
 Backprop function; depending on which of the arguments 'to_update' and 'in_deriv' are non-NULL, this can compute input-data derivatives and/or perform model update. More...
 
virtual void StoreStats (const CuMatrixBase< BaseFloat > &in_value, const CuMatrixBase< BaseFloat > &out_value, void *memo)
 This function may store stats on average activation values, and for some component types, the average value of the derivative of the nonlinearity. More...
 
virtual void ZeroStats ()
 Components that provide an implementation of StoreStats should also provide an implementation of ZeroStats(), to set those stats to zero. More...
 
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. More...
 
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 possible to manage optionally-required inputs. More...
 
virtual void ReorderIndexes (std::vector< Index > *input_indexes, std::vector< Index > *output_indexes) const
 This function only does something interesting for non-simple Components. More...
 
virtual ComponentPrecomputedIndexesPrecomputeIndexes (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. More...
 
virtual std::string Type () const =0
 Returns a string such as "SigmoidComponent", describing the type of the object. More...
 
virtual void InitFromConfig (ConfigLine *cfl)=0
 Initialize, from a ConfigLine object. More...
 
virtual int32 InputDim () const =0
 Returns input-dimension of this component. More...
 
virtual int32 OutputDim () const =0
 Returns output-dimension of this component. More...
 
virtual int32 Properties () const =0
 Return bitmask of the component's properties. More...
 
virtual ComponentCopy () const =0
 Copies component (deep copy). More...
 
virtual void Read (std::istream &is, bool binary)=0
 Read function (used after we know the type of the Component); accepts input that is missing the token that describes the component type, in case it has already been consumed. More...
 
virtual void Write (std::ostream &os, bool binary) const =0
 Write component to stream. More...
 
virtual std::string Info () const
 Returns some text-form information about this component, for diagnostics. More...
 
virtual void Scale (BaseFloat scale)
 This virtual function when called on – an UpdatableComponent scales the parameters by "scale" when called by an UpdatableComponent. More...
 
virtual void Add (BaseFloat alpha, const Component &other)
 This virtual function when called by – an UpdatableComponent adds the parameters of another updatable component, times some constant, to the current parameters. More...
 
virtual void DeleteMemo (void *memo) const
 This virtual function only needs to be overwritten by Components that return a non-NULL memo from their Propagate() function. More...
 
 Component ()
 
virtual ~Component ()
 

Static Public Member Functions

static ComponentReadNew (std::istream &is, bool binary)
 Read component from stream (works out its type). Dies on error. More...
 
static ComponentNewComponentOfType (const std::string &type)
 Returns a new Component of the given type e.g. More...
 

Private Member Functions

 KALDI_DISALLOW_COPY_AND_ASSIGN (Component)
 

Detailed Description

Abstract base-class for neural-net components.

Definition at line 114 of file nnet-component-itf.h.

Constructor & Destructor Documentation

◆ Component()

Component ( )
inline

Definition at line 379 of file nnet-component-itf.h.

379 { }

◆ ~Component()

virtual ~Component ( )
inlinevirtual

Definition at line 381 of file nnet-component-itf.h.

References KALDI_DISALLOW_COPY_AND_ASSIGN.

381 { }

Member Function Documentation

◆ Add()

virtual void Add ( BaseFloat  alpha,
const Component other 
)
inlinevirtual

This virtual function when called by – an UpdatableComponent adds the parameters of another updatable component, times some constant, to the current parameters.

– a NonlinearComponent (or another component that stores stats, like BatchNormComponent)– it relates to adding stats. Otherwise it will normally do nothing.

Reimplemented in CompositeComponent, LstmNonlinearityComponent, ConvolutionComponent, ScaleAndOffsetComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, LinearComponent, NaturalGradientAffineComponent, ConstantComponent, NonlinearComponent, RepeatedAffineComponent, BlockAffineComponent, TdnnComponent, BackpropTruncationComponent, AffineComponent, TimeHeightConvolutionComponent, BatchNormComponent, and RestrictedAttentionComponent.

Definition at line 370 of file nnet-component-itf.h.

Referenced by CompositeComponent::Add(), kaldi::nnet3::AddNnet(), kaldi::nnet3::AddNnetComponents(), kaldi::nnet3::ApplyL2Regularization(), BatchNormComponent::Copy(), ClipGradientComponent::Copy(), ScaleAndOffsetComponent::Copy(), ConstantComponent::IsComputable(), LinearComponent::LinearComponent(), NaturalGradientAffineComponent::NaturalGradientAffineComponent(), AffineComponent::Properties(), BackpropTruncationComponent::Properties(), BlockAffineComponent::Properties(), RepeatedAffineComponent::Properties(), PerElementScaleComponent::Properties(), PerElementOffsetComponent::Properties(), ConstantFunctionComponent::Properties(), ConvolutionComponent::Properties(), LstmNonlinearityComponent::Properties(), kaldi::nnet3::TestNnetComponentAddScale(), and CompositeComponent::Type().

370 {};

◆ Backprop()

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
pure virtual

Backprop function; depending on which of the arguments 'to_update' and 'in_deriv' are non-NULL, this can compute input-data derivatives and/or perform model update.

Parameters
[in]debug_infoThe component name, to be printed out in any warning messages.
[in]indexesA pointer to some information output by this class's PrecomputeIndexes function (will be NULL for simple components, i.e. those that don't do things like splicing).
[in]in_valueThe matrix that was given as input to the Propagate function. Will be ignored (and may be empty) if Properties()&kBackpropNeedsInput == 0.
[in]out_valueThe matrix that was output from the Propagate function. Will be ignored (and may be empty) if Properties()&kBackpropNeedsOutput == 0
[in]out_derivThe derivative at the output of this component.
[in]memoThis will normally be NULL, but for component types that set the flag kUsesMemo, this will be the return value of the Propagate() function that corresponds to this Backprop() function. Ownership of any pointers is not transferred to the Backprop function; DeleteMemo() will be called to delete it.
[out]to_updateIf model update is desired, the Component to be updated, else NULL. Does not have to be identical to this. If supplied, you can assume that to_update->Properties() & kUpdatableComponent is nonzero.
[out]in_derivThe derivative at the input of this component, if needed (else NULL). If Properties()&kBackpropInPlace, may be the same matrix as out_deriv. If Properties()&kBackpropAdds, this is added to by the Backprop routine, else it is set. The component code chooses which mode to work in, based on convenience.

Implemented in CompositeComponent, MaxpoolingComponent, LstmNonlinearityComponent, ConvolutionComponent, ScaleAndOffsetComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, SumBlockComponent, NoOpComponent, FixedBiasComponent, FixedScaleComponent, SumGroupComponent, FixedAffineComponent, LinearComponent, GeneralDropoutComponent, DropoutMaskComponent, LogSoftmaxComponent, SoftmaxComponent, ConstantComponent, RepeatedAffineComponent, BlockAffineComponent, BackpropTruncationComponent, TdnnComponent, AffineComponent, StatisticsPoolingComponent, RectifiedLinearComponent, TanhComponent, TimeHeightConvolutionComponent, SigmoidComponent, StatisticsExtractionComponent, BatchNormComponent, ElementwiseProductComponent, RestrictedAttentionComponent, DropoutComponent, NormalizeComponent, DistributeComponent, and PnormComponent.

Referenced by NnetComputer::ExecuteCommand(), kaldi::nnet3::TestSimpleComponentDataDerivative(), kaldi::nnet3::TestSimpleComponentModelDerivative(), and kaldi::nnet3::TestSimpleComponentPropagateProperties().

◆ Copy()

virtual Component* Copy ( ) const
pure virtual

◆ DeleteMemo()

virtual void DeleteMemo ( void *  memo) const
inlinevirtual

This virtual function only needs to be overwritten by Components that return a non-NULL memo from their Propagate() function.

It's called by NnetComputer in cases where Propagate returns a memo but there will be no backprop to consume it.

Reimplemented in GeneralDropoutComponent, BatchNormComponent, and RestrictedAttentionComponent.

Definition at line 376 of file nnet-component-itf.h.

References KALDI_ASSERT.

Referenced by NnetComputer::ExecuteCommand(), NnetComputer::SaveMemo(), kaldi::nnet3::TestSimpleComponentDataDerivative(), kaldi::nnet3::TestSimpleComponentModelDerivative(), and kaldi::nnet3::TestSimpleComponentPropagateProperties().

376 { KALDI_ASSERT(memo == NULL); }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169

◆ GetInputIndexes()

void GetInputIndexes ( const MiscComputationInfo misc_info,
const Index output_index,
std::vector< Index > *  desired_indexes 
) const
virtual

This function only does something interesting for non-simple Components.

For a given index at the output of the component, tells us what indexes are required at its input (note: "required" encompasses also optionally-required things; it will enumerate all things that we'd like to have). See also IsComputable().

Parameters
[in]misc_infoThis argument is supplied to handle things that the framework can't very easily supply: information like which time indexes are needed for AggregateComponent, which time-indexes are available at the input of a recurrent network, and so on. We will add members to misc_info as needed.
[in]output_indexThe Index at the output of the component, for which we are requesting the list of indexes at the component's input.
[out]desired_indexesA list of indexes that are desired at the input. are to be written to here. By "desired" we mean required or optionally-required.

The default implementation of this function is suitable for any SimpleComponent; it just copies the output_index to a single identical element in input_indexes.

Reimplemented in DropoutMaskComponent, ConstantComponent, TdnnComponent, StatisticsPoolingComponent, TimeHeightConvolutionComponent, StatisticsExtractionComponent, RestrictedAttentionComponent, and DistributeComponent.

Definition at line 197 of file nnet-component-itf.cc.

Referenced by ComputationGraphBuilder::AddDependencies(), and kaldi::nnet3::ComputeComputationGraph().

199  {
200  input_indexes->resize(1);
201  (*input_indexes)[0] = output_index;
202 }

◆ Info()

std::string Info ( ) const
virtual

Returns some text-form information about this component, for diagnostics.

Starts with the type of the component. E.g. "SigmoidComponent dim=900", although most components will have much more info.

Reimplemented in CompositeComponent, MaxpoolingComponent, LstmNonlinearityComponent, ConvolutionComponent, ScaleAndOffsetComponent, NaturalGradientPerElementScaleComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, SumBlockComponent, NoOpComponent, FixedBiasComponent, FixedScaleComponent, FixedAffineComponent, LinearComponent, GeneralDropoutComponent, NaturalGradientAffineComponent, DropoutMaskComponent, ConstantComponent, NonlinearComponent, RepeatedAffineComponent, BlockAffineComponent, UpdatableComponent, BackpropTruncationComponent, TdnnComponent, AffineComponent, TimeHeightConvolutionComponent, BatchNormComponent, DropoutComponent, RestrictedAttentionComponent, and NormalizeComponent.

Definition at line 190 of file nnet-component-itf.cc.

References ComponentPrecomputedIndexes::Type().

Referenced by PermuteComponent::Add(), NoOpComponent::Copy(), ClipGradientComponent::Copy(), FixedAffineComponent::Info(), FixedScaleComponent::Info(), FixedBiasComponent::Info(), LinearComponent::LinearComponent(), MaxpoolingComponent::MaxpoolingComponent(), NaturalGradientAffineComponent::NaturalGradientAffineComponent(), AffineComponent::OrthonormalConstraint(), DropoutComponent::OutputDim(), BlockAffineComponent::OutputDim(), RepeatedAffineComponent::OutputDim(), ConstantComponent::OutputDim(), DropoutMaskComponent::OutputDim(), GeneralDropoutComponent::OutputDim(), SumBlockComponent::OutputDim(), PerElementScaleComponent::OutputDim(), PerElementOffsetComponent::OutputDim(), ConstantFunctionComponent::OutputDim(), ScaleAndOffsetComponent::OutputDim(), BackpropTruncationComponent::Properties(), kaldi::nnet3::TestNnetComponentAddScale(), kaldi::nnet3::TestNnetComponentCopy(), FixedAffineComponent::Type(), FixedScaleComponent::Type(), FixedBiasComponent::Type(), and kaldi::nnet3::UnitTestNnetComponent().

190  {
191  std::stringstream stream;
192  stream << Type() << ", input-dim=" << InputDim()
193  << ", output-dim=" << OutputDim();
194  return stream.str();
195 }
virtual int32 OutputDim() const =0
Returns output-dimension of this component.
virtual std::string Type() const =0
Returns a string such as "SigmoidComponent", describing the type of the object.
virtual int32 InputDim() const =0
Returns input-dimension of this component.

◆ InitFromConfig()

◆ InputDim()

◆ IsComputable()

bool IsComputable ( const MiscComputationInfo misc_info,
const Index output_index,
const IndexSet input_index_set,
std::vector< Index > *  used_inputs 
) const
virtual

This function only does something interesting for non-simple Components, and it exists to make it possible to manage optionally-required inputs.

It tells the user whether a given output index is computable from a given set of input indexes, and if so, says which input indexes will be used in the computation.

Implementations of this function are required to have the property that adding an element to "input_index_set" can only ever change IsComputable from false to true, never vice versa.

Parameters
[in]misc_infoSome information specific to the computation, such as minimum and maximum times for certain components to do adaptation on; it's a place to put things that don't easily fit in the framework.
[in]output_indexThe index that is to be computed at the output of this Component.
[in]input_index_setThe set of indexes that is available at the input of this Component.
[out]used_inputsIf this is non-NULL and the output is computable this will be set to the list of input indexes that will actually be used in the computation.
Returns
Returns true iff this output is computable from the provided inputs.

The default implementation of this function is suitable for any SimpleComponent: it just returns true if output_index is in input_index_set, and if so sets used_inputs to vector containing that one Index.

Reimplemented in DropoutMaskComponent, ConstantComponent, TdnnComponent, StatisticsPoolingComponent, TimeHeightConvolutionComponent, StatisticsExtractionComponent, RestrictedAttentionComponent, and DistributeComponent.

Definition at line 204 of file nnet-component-itf.cc.

Referenced by ComputationGraphBuilder::ComputeComputableInfo(), and ComputationGraphBuilder::PruneDependencies().

207  {
208  // the default Component dependency is for an output index to map directly to
209  // the same input index, which is required to compute the output.
210  if (!input_index_set(output_index))
211  return false;
212  if (used_inputs) {
213  used_inputs->clear();
214  used_inputs->push_back(output_index);
215  }
216  return true;
217 }

◆ KALDI_DISALLOW_COPY_AND_ASSIGN()

KALDI_DISALLOW_COPY_AND_ASSIGN ( Component  )
private

◆ NewComponentOfType()

Component * NewComponentOfType ( const std::string &  type)
static

Returns a new Component of the given type e.g.

"SoftmaxComponent", or NULL if no such component type exists.

Definition at line 95 of file nnet-component-itf.cc.

References KALDI_ASSERT, and Component::Type().

Referenced by kaldi::nnet3::GenerateRandomSimpleComponent(), CompositeComponent::InitFromConfig(), and Nnet::ProcessComponentConfigLine().

95  {
96  Component *ans = NULL;
97  if (component_type == "SigmoidComponent") {
98  ans = new SigmoidComponent();
99  } else if (component_type == "TanhComponent") {
100  ans = new TanhComponent();
101  } else if (component_type == "SoftmaxComponent") {
102  ans = new SoftmaxComponent();
103  } else if (component_type == "LogSoftmaxComponent") {
104  ans = new LogSoftmaxComponent();
105  } else if (component_type == "RectifiedLinearComponent") {
106  ans = new RectifiedLinearComponent();
107  } else if (component_type == "NormalizeComponent") {
108  ans = new NormalizeComponent();
109  } else if (component_type == "PnormComponent") {
110  ans = new PnormComponent();
111  } else if (component_type == "AffineComponent") {
112  ans = new AffineComponent();
113  } else if (component_type == "LinearComponent") {
114  ans = new LinearComponent();
115  } else if (component_type == "NaturalGradientAffineComponent") {
116  ans = new NaturalGradientAffineComponent();
117  } else if (component_type == "PerElementScaleComponent") {
118  ans = new PerElementScaleComponent();
119  } else if (component_type == "NaturalGradientPerElementScaleComponent") {
120  ans = new NaturalGradientPerElementScaleComponent();
121  } else if (component_type == "PerElementOffsetComponent") {
122  ans = new PerElementOffsetComponent();
123  } else if (component_type == "SumGroupComponent") {
124  ans = new SumGroupComponent();
125  } else if (component_type == "FixedAffineComponent") {
126  ans = new FixedAffineComponent();
127  } else if (component_type == "FixedScaleComponent") {
128  ans = new FixedScaleComponent();
129  } else if (component_type == "FixedBiasComponent") {
130  ans = new FixedBiasComponent();
131  } else if (component_type == "NoOpComponent") {
132  ans = new NoOpComponent();
133  } else if (component_type == "ClipGradientComponent") {
134  ans = new ClipGradientComponent();
135  } else if (component_type == "ElementwiseProductComponent") {
136  ans = new ElementwiseProductComponent();
137  } else if (component_type == "ConvolutionComponent") {
138  ans = new ConvolutionComponent();
139  } else if (component_type == "TdnnComponent") {
140  ans = new TdnnComponent();
141  } else if (component_type == "MaxpoolingComponent") {
142  ans = new MaxpoolingComponent();
143  } else if (component_type == "PermuteComponent") {
144  ans = new PermuteComponent();
145  } else if (component_type == "DistributeComponent") {
146  ans = new DistributeComponent();
147  } else if (component_type == "CompositeComponent") {
148  ans = new CompositeComponent();
149  } else if (component_type == "RepeatedAffineComponent") {
150  ans = new RepeatedAffineComponent();
151  } else if (component_type == "BlockAffineComponent") {
152  ans = new BlockAffineComponent();
153  } else if (component_type == "NaturalGradientRepeatedAffineComponent") {
154  ans = new NaturalGradientRepeatedAffineComponent();
155  } else if (component_type == "StatisticsExtractionComponent") {
156  ans = new StatisticsExtractionComponent();
157  } else if (component_type == "StatisticsPoolingComponent") {
158  ans = new StatisticsPoolingComponent();
159  } else if (component_type == "ConstantFunctionComponent") {
160  ans = new ConstantFunctionComponent();
161  } else if (component_type == "ConstantComponent") {
162  ans = new ConstantComponent();
163  } else if (component_type == "DropoutComponent") {
164  ans = new DropoutComponent();
165  } else if (component_type == "DropoutMaskComponent") {
166  ans = new DropoutMaskComponent();
167  } else if (component_type == "GeneralDropoutComponent") {
168  ans = new GeneralDropoutComponent();
169  } else if (component_type == "BackpropTruncationComponent") {
170  ans = new BackpropTruncationComponent();
171  } else if (component_type == "LstmNonlinearityComponent") {
172  ans = new LstmNonlinearityComponent();
173  } else if (component_type == "BatchNormComponent") {
174  ans = new BatchNormComponent();
175  } else if (component_type == "TimeHeightConvolutionComponent") {
176  ans = new TimeHeightConvolutionComponent();
177  } else if (component_type == "RestrictedAttentionComponent") {
178  ans = new RestrictedAttentionComponent();
179  } else if (component_type == "SumBlockComponent") {
180  ans = new SumBlockComponent();
181  } else if (component_type == "ScaleAndOffsetComponent") {
182  ans = new ScaleAndOffsetComponent();
183  }
184  if (ans != NULL) {
185  KALDI_ASSERT(component_type == ans->Type());
186  }
187  return ans;
188 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169

◆ OutputDim()

◆ PrecomputeIndexes()

virtual ComponentPrecomputedIndexes* PrecomputeIndexes ( const MiscComputationInfo misc_info,
const std::vector< Index > &  input_indexes,
const std::vector< Index > &  output_indexes,
bool  need_backprop 
) const
inlinevirtual

This function must return NULL for simple Components.

Returns a pointer to a class that may contain some precomputed component-specific and computation-specific indexes to be in used in the Propagate and Backprop functions.

Parameters
[in]misc_infoThis argument is supplied to handle things that the framework can't very easily supply: information like which time indexes are needed for AggregateComponent, which time-indexes are available at the input of a recurrent network, and so on. misc_info may not even ever be used here. We will add members to misc_info as needed.
[in]input_indexesA vector of indexes that explains what time-indexes (and other indexes) each row of the in/in_value/in_deriv matrices given to Propagate and Backprop will mean.
[in]output_indexesA vector of indexes that explains what time-indexes (and other indexes) each row of the out/out_value/out_deriv matrices given to Propagate and Backprop will mean.
[in]need_backpropTrue if we might need to do backprop with this component, so that if any different indexes are needed for backprop then those should be computed too.
Returns
Returns a child-class of class ComponentPrecomputedIndexes, or NULL if this component for does not need to precompute any indexes (e.g. if it is a simple component and does not care about indexes).

Reimplemented in GeneralDropoutComponent, TdnnComponent, BackpropTruncationComponent, StatisticsPoolingComponent, TimeHeightConvolutionComponent, StatisticsExtractionComponent, RestrictedAttentionComponent, and DistributeComponent.

Definition at line 302 of file nnet-component-itf.h.

References ComponentPrecomputedIndexes::Copy(), ComponentPrecomputedIndexes::Read(), ComponentPrecomputedIndexes::ReadNew(), ComponentPrecomputedIndexes::Type(), and ComponentPrecomputedIndexes::Write().

Referenced by ComputationExpander::ComputePrecomputedIndexes(), kaldi::nnet3::GetPrecomputedIndexes(), and Compiler::SetUpPrecomputedIndexes().

306  { return NULL; }

◆ Propagate()

virtual void* Propagate ( const ComponentPrecomputedIndexes indexes,
const CuMatrixBase< BaseFloat > &  in,
CuMatrixBase< BaseFloat > *  out 
) const
pure virtual

Propagate function.

Parameters
[in]indexesA pointer to some information output by this class's PrecomputeIndexes function (will be NULL for simple components, i.e. those that don't do things like splicing).
[in]inThe input to this component. Num-columns == InputDim().
[out]outThe output of this component. Num-columns == OutputDim(). Note: output of this component will be added to the initial value of "out" if Properties()&kPropagateAdds != 0; otherwise the output will be set and the initial value ignored. Each Component chooses whether it is more convenient implementation-wise to add or set, and the calling code has to deal with it.
Returns
Normally returns NULL, but may return a non-NULL value for components which have the flag kUsesMemo set. This value will be passed into the corresponding Backprop routine.

Implemented in CompositeComponent, MaxpoolingComponent, LstmNonlinearityComponent, ConvolutionComponent, ScaleAndOffsetComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, SumBlockComponent, NoOpComponent, FixedBiasComponent, FixedScaleComponent, SumGroupComponent, FixedAffineComponent, LinearComponent, GeneralDropoutComponent, DropoutMaskComponent, LogSoftmaxComponent, SoftmaxComponent, ConstantComponent, RepeatedAffineComponent, BlockAffineComponent, BackpropTruncationComponent, TdnnComponent, AffineComponent, StatisticsPoolingComponent, RectifiedLinearComponent, TanhComponent, TimeHeightConvolutionComponent, SigmoidComponent, StatisticsExtractionComponent, BatchNormComponent, ElementwiseProductComponent, RestrictedAttentionComponent, DropoutComponent, NormalizeComponent, DistributeComponent, and PnormComponent.

Referenced by NnetComputer::ExecuteCommand(), FixedBiasComponent::OutputDim(), kaldi::nnet3::TestSimpleComponentDataDerivative(), kaldi::nnet3::TestSimpleComponentModelDerivative(), and kaldi::nnet3::TestSimpleComponentPropagateProperties().

◆ Properties()

virtual int32 Properties ( ) const
pure virtual

Return bitmask of the component's properties.

These properties depend only on the component's type. See enum ComponentProperties.

Implemented in CompositeComponent, MaxpoolingComponent, LstmNonlinearityComponent, ConvolutionComponent, ScaleAndOffsetComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, SumBlockComponent, NoOpComponent, FixedBiasComponent, FixedScaleComponent, SumGroupComponent, FixedAffineComponent, LinearComponent, GeneralDropoutComponent, DropoutMaskComponent, LogSoftmaxComponent, SoftmaxComponent, ConstantComponent, RepeatedAffineComponent, BlockAffineComponent, BackpropTruncationComponent, TdnnComponent, AffineComponent, RectifiedLinearComponent, StatisticsPoolingComponent, TanhComponent, TimeHeightConvolutionComponent, SigmoidComponent, StatisticsExtractionComponent, BatchNormComponent, ElementwiseProductComponent, RestrictedAttentionComponent, DropoutComponent, NormalizeComponent, DistributeComponent, and PnormComponent.

Referenced by Compiler::AddBackwardStepComponent(), Compiler::AddForwardStepComponent(), kaldi::nnet3::AddNnetComponents(), kaldi::nnet3::ApplyL2Regularization(), ComputationChecker::CheckComputationIndexes(), kaldi::nnet3::ComponentDotProducts(), kaldi::nnet3::ComputeCommandAttributes(), Compiler::ComputeDerivNeeded(), ModelUpdateConsolidator::ConsolidateModelUpdate(), ModelUpdateConsolidator::ConsolidateUpdateForComponent(), NnetComputer::DebugAfterExecute(), NnetComputer::DebugBeforeExecute(), kaldi::nnet3::DotProduct(), NnetComputer::ExecuteCommand(), kaldi::nnet3::FreezeNaturalGradient(), kaldi::nnet3::GetPrecomputedIndexes(), Compiler::GetStrideType(), CompositeComponent::InitFromConfig(), VariableMergingOptimizer::MergeVariables(), DerivativeTimeLimiter::ModifyCommand(), kaldi::nnet3::NnetParametersAreIdentical(), kaldi::nnet3::NumParameters(), kaldi::nnet3::NumUpdatableComponents(), kaldi::nnet3::PerturbParams(), NnetChainTrainer::PrintMaxChangeStats(), NnetTrainer::PrintMaxChangeStats(), kaldi::nnet3::PrintVectorPerUpdatableComponent(), ComputationStepsComputer::ProcessComponentStep(), kaldi::nnet3::SetLearningRate(), kaldi::nnet3::SetNnetAsGradient(), kaldi::nnet3::TestNnetComponentUpdatable(), kaldi::nnet3::TestNnetComponentVectorizeUnVectorize(), kaldi::nnet3::TestSimpleComponentDataDerivative(), kaldi::nnet3::TestSimpleComponentModelDerivative(), kaldi::nnet3::TestSimpleComponentPropagateProperties(), kaldi::nnet3::UnVectorizeNnet(), kaldi::nnet3::UpdateNnetWithMaxChange(), and kaldi::nnet3::VectorizeNnet().

◆ Read()

◆ ReadNew()

Component * ReadNew ( std::istream &  is,
bool  binary 
)
static

Read component from stream (works out its type). Dies on error.

Definition at line 81 of file nnet-component-itf.cc.

References KALDI_ERR, Component::Read(), and kaldi::ReadToken().

Referenced by Nnet::Read(), CompositeComponent::Read(), and kaldi::nnet3::TestNnetComponentIo().

81  {
82  std::string token;
83  ReadToken(is, binary, &token); // e.g. "<SigmoidComponent>".
84  token.erase(0, 1); // erase "<".
85  token.erase(token.length()-1); // erase ">".
86  Component *ans = NewComponentOfType(token);
87  if (!ans)
88  KALDI_ERR << "Unknown component type " << token;
89  ans->Read(is, binary);
90  return ans;
91 }
void ReadToken(std::istream &is, bool binary, std::string *str)
ReadToken gets the next token and puts it in str (exception on failure).
Definition: io-funcs.cc:154
#define KALDI_ERR
Definition: kaldi-error.h:127
static Component * NewComponentOfType(const std::string &type)
Returns a new Component of the given type e.g.

◆ ReorderIndexes()

virtual void ReorderIndexes ( std::vector< Index > *  input_indexes,
std::vector< Index > *  output_indexes 
) const
inlinevirtual

This function only does something interesting for non-simple Components.

It provides an opportunity for a Component to reorder the or pad the indexes at its input and output. This might be useful, for instance, if a component requires a particular ordering of the indexes that doesn't correspond to their natural ordering. Components that might modify the indexes are required to return the kReordersIndexes flag in their Properties(). The ReorderIndexes() function is now allowed to insert blanks into the indexes. The 'blanks' must be of the form (n,kNoTime,x), where the marker kNoTime (a very negative number) is there where the 't' indexes normally live. The reason we don't just have, say, (-1,-1,-1), relates to the need to preserve a regular pattern over the 'n' indexes so that 'shortcut compilation' (c.f. ExpandComputation()) can work correctly

Parameters
[in,out]Indexesat the input of the Component.
[in,out]Indexesat the output of the Component

Reimplemented in TdnnComponent, StatisticsPoolingComponent, TimeHeightConvolutionComponent, StatisticsExtractionComponent, and RestrictedAttentionComponent.

Definition at line 272 of file nnet-component-itf.h.

Referenced by StatisticsExtractionComponent::Copy(), StatisticsPoolingComponent::Copy(), kaldi::nnet3::GetPrecomputedIndexes(), and ComputationStepsComputer::ProcessComponentStep().

273  {}

◆ Scale()

virtual void Scale ( BaseFloat  scale)
inlinevirtual

This virtual function when called on – an UpdatableComponent scales the parameters by "scale" when called by an UpdatableComponent.

– a Nonlinear component (or another component that stores stats, like BatchNormComponent)– it relates to scaling activation stats, not parameters. Otherwise it will normally do nothing.

Reimplemented in CompositeComponent, LstmNonlinearityComponent, ConvolutionComponent, ScaleAndOffsetComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, LinearComponent, NaturalGradientAffineComponent, ConstantComponent, NonlinearComponent, RepeatedAffineComponent, BlockAffineComponent, TdnnComponent, BackpropTruncationComponent, AffineComponent, TimeHeightConvolutionComponent, BatchNormComponent, and RestrictedAttentionComponent.

Definition at line 360 of file nnet-component-itf.h.

Referenced by BatchNormComponent::Copy(), ClipGradientComponent::Copy(), ScaleAndOffsetComponent::Copy(), ConstantComponent::IsComputable(), LinearComponent::LinearComponent(), NaturalGradientAffineComponent::NaturalGradientAffineComponent(), AffineComponent::Properties(), BackpropTruncationComponent::Properties(), BlockAffineComponent::Properties(), RepeatedAffineComponent::Properties(), PerElementScaleComponent::Properties(), PerElementOffsetComponent::Properties(), ConstantFunctionComponent::Properties(), ConvolutionComponent::Properties(), LstmNonlinearityComponent::Properties(), CompositeComponent::Scale(), kaldi::nnet3::ScaleNnet(), kaldi::nnet3::TestNnetComponentAddScale(), kaldi::nnet3::TestNnetComponentUpdatable(), kaldi::nnet3::TestNnetComponentVectorizeUnVectorize(), kaldi::nnet3::TestSimpleComponentModelDerivative(), and CompositeComponent::Type().

360 {};

◆ StoreStats()

virtual void StoreStats ( const CuMatrixBase< BaseFloat > &  in_value,
const CuMatrixBase< BaseFloat > &  out_value,
void *  memo 
)
inlinevirtual

This function may store stats on average activation values, and for some component types, the average value of the derivative of the nonlinearity.

It only does something for those components that have nonzero Properties()&kStoresStats.

Parameters
[in]in_valueThe input to the Propagate() function. Note: if the component sets the flag kPropagateInPlace, this should not be used; the empty matrix will be provided here if in-place propagation was used.
[in]out_valueThe output of the Propagate() function.
[in]memoThe 'memo' returned by the Propagate() function; this will usually be NULL.

Reimplemented in SoftmaxComponent, RectifiedLinearComponent, TanhComponent, SigmoidComponent, BatchNormComponent, and RestrictedAttentionComponent.

Definition at line 186 of file nnet-component-itf.h.

Referenced by CompositeComponent::Backprop(), SigmoidComponent::Copy(), BatchNormComponent::DeleteMemo(), NnetComputer::ExecuteCommand(), TanhComponent::Properties(), RectifiedLinearComponent::Properties(), and SoftmaxComponent::Properties().

188  { }

◆ Type()

virtual std::string Type ( ) const
pure virtual

Returns a string such as "SigmoidComponent", describing the type of the object.

Implemented in CompositeComponent, MaxpoolingComponent, LstmNonlinearityComponent, ConvolutionComponent, ScaleAndOffsetComponent, NaturalGradientPerElementScaleComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, SumBlockComponent, NoOpComponent, FixedBiasComponent, FixedScaleComponent, SumGroupComponent, FixedAffineComponent, LinearComponent, GeneralDropoutComponent, NaturalGradientAffineComponent, DropoutMaskComponent, LogSoftmaxComponent, SoftmaxComponent, NaturalGradientRepeatedAffineComponent, ConstantComponent, RepeatedAffineComponent, BlockAffineComponent, BackpropTruncationComponent, TdnnComponent, AffineComponent, StatisticsPoolingComponent, RectifiedLinearComponent, TanhComponent, TimeHeightConvolutionComponent, SigmoidComponent, StatisticsExtractionComponent, BatchNormComponent, ElementwiseProductComponent, RestrictedAttentionComponent, DropoutComponent, NormalizeComponent, DistributeComponent, and PnormComponent.

Referenced by ComputationChecker::CheckComputationCompression(), kaldi::nnet3::ConvertRepeatedToBlockAffine(), UpdatableComponent::Info(), NonlinearComponent::Info(), NonlinearComponent::InitFromConfig(), CompositeComponent::InitFromConfig(), Component::NewComponentOfType(), kaldi::nnet3::NnetParametersAreIdentical(), MemoryCompressionOptimizer::ProcessMatrix(), NonlinearComponent::Read(), UpdatableComponent::ReadUpdatableCommon(), kaldi::nnet3::TestSimpleComponentDataDerivative(), kaldi::nnet3::TestSimpleComponentModelDerivative(), kaldi::nnet3::TestSimpleComponentPropagateProperties(), kaldi::nnet3::UnitTestConvertRepeatedToBlockAffine(), kaldi::nnet3::UnitTestConvertRepeatedToBlockAffineComposite(), NonlinearComponent::Write(), and UpdatableComponent::WriteUpdatableCommon().

◆ Write()

◆ ZeroStats()

virtual void ZeroStats ( )
inlinevirtual

Components that provide an implementation of StoreStats should also provide an implementation of ZeroStats(), to set those stats to zero.

Other components that store other types of statistics (e.g. regarding gradient clipping) should implement ZeroStats() also.

Reimplemented in CompositeComponent, LstmNonlinearityComponent, PermuteComponent, ClipGradientComponent, NonlinearComponent, BackpropTruncationComponent, BatchNormComponent, and RestrictedAttentionComponent.

Definition at line 195 of file nnet-component-itf.h.

Referenced by BatchNormComponent::Copy(), BackpropTruncationComponent::Properties(), ClipGradientComponent::Properties(), LstmNonlinearityComponent::Properties(), CompositeComponent::Type(), kaldi::nnet3::ZeroComponentStats(), and CompositeComponent::ZeroStats().

195 { }

The documentation for this class was generated from the following files: