All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
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. 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 by. 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 122 of file nnet-component-itf.h.

Constructor & Destructor Documentation

Component ( )
inline

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

384 { }
virtual ~Component ( )
inlinevirtual

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

386 { }

Member Function Documentation

virtual void Add ( BaseFloat  alpha,
const Component other 
)
inlinevirtual
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, BatchNormComponent, MaxpoolingComponent, LstmNonlinearityComponent, ConvolutionComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, SumBlockComponent, NoOpComponent, FixedBiasComponent, FixedScaleComponent, SumGroupComponent, FixedAffineComponent, LogSoftmaxComponent, DropoutMaskComponent, SoftmaxComponent, ConstantComponent, RepeatedAffineComponent, BlockAffineComponent, BackpropTruncationComponent, AffineComponent, RectifiedLinearComponent, StatisticsPoolingComponent, TanhComponent, SigmoidComponent, TimeHeightConvolutionComponent, StatisticsExtractionComponent, NormalizeComponent, ElementwiseProductComponent, RestrictedAttentionComponent, DropoutComponent, DistributeComponent, and PnormComponent.

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

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 BatchNormComponent, and RestrictedAttentionComponent.

Definition at line 381 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().

381 { KALDI_ASSERT(memo == NULL); }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
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, StatisticsPoolingComponent, TimeHeightConvolutionComponent, StatisticsExtractionComponent, RestrictedAttentionComponent, and DistributeComponent.

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

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

186  {
187  input_indexes->resize(1);
188  (*input_indexes)[0] = output_index;
189 }
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, BatchNormComponent, MaxpoolingComponent, LstmNonlinearityComponent, ConvolutionComponent, NaturalGradientPerElementScaleComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, SumBlockComponent, FixedBiasComponent, FixedScaleComponent, FixedAffineComponent, NaturalGradientAffineComponent, DropoutMaskComponent, ConstantComponent, RepeatedAffineComponent, NonlinearComponent, BlockAffineComponent, BackpropTruncationComponent, UpdatableComponent, AffineComponent, NormalizeComponent, TimeHeightConvolutionComponent, DropoutComponent, and RestrictedAttentionComponent.

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

References Component::InputDim(), Component::OutputDim(), and Component::Type().

Referenced by FixedAffineComponent::Info(), FixedScaleComponent::Info(), FixedBiasComponent::Info(), kaldi::nnet3::TestNnetComponentAddScale(), kaldi::nnet3::TestNnetComponentCopy(), and kaldi::nnet3::UnitTestNnetComponent().

177  {
178  std::stringstream stream;
179  stream << Type() << ", input-dim=" << InputDim()
180  << ", output-dim=" << OutputDim();
181  return stream.str();
182 }
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.
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, StatisticsPoolingComponent, TimeHeightConvolutionComponent, StatisticsExtractionComponent, RestrictedAttentionComponent, and DistributeComponent.

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

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

194  {
195  // the default Component dependency is for an output index to map directly to
196  // the same input index, which is required to compute the output.
197  if (!input_index_set(output_index))
198  return false;
199  if (used_inputs) {
200  used_inputs->clear();
201  used_inputs->push_back(output_index);
202  }
203  return true;
204 }
KALDI_DISALLOW_COPY_AND_ASSIGN ( Component  )
private
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 90 of file nnet-component-itf.cc.

References KALDI_ASSERT, and Component::Type().

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

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

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

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

314  { return NULL; }
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, BatchNormComponent, MaxpoolingComponent, LstmNonlinearityComponent, ConvolutionComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, SumBlockComponent, NoOpComponent, FixedBiasComponent, FixedScaleComponent, SumGroupComponent, FixedAffineComponent, LogSoftmaxComponent, SoftmaxComponent, DropoutMaskComponent, ConstantComponent, RepeatedAffineComponent, BlockAffineComponent, BackpropTruncationComponent, AffineComponent, RectifiedLinearComponent, StatisticsPoolingComponent, TanhComponent, SigmoidComponent, TimeHeightConvolutionComponent, StatisticsExtractionComponent, NormalizeComponent, ElementwiseProductComponent, RestrictedAttentionComponent, DropoutComponent, DistributeComponent, and PnormComponent.

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

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, BatchNormComponent, MaxpoolingComponent, LstmNonlinearityComponent, ConvolutionComponent, ConstantFunctionComponent, PerElementOffsetComponent, PerElementScaleComponent, PermuteComponent, ClipGradientComponent, SumBlockComponent, NoOpComponent, FixedBiasComponent, FixedScaleComponent, SumGroupComponent, FixedAffineComponent, LogSoftmaxComponent, DropoutMaskComponent, SoftmaxComponent, ConstantComponent, RepeatedAffineComponent, BlockAffineComponent, BackpropTruncationComponent, AffineComponent, RectifiedLinearComponent, StatisticsPoolingComponent, TanhComponent, SigmoidComponent, TimeHeightConvolutionComponent, StatisticsExtractionComponent, NormalizeComponent, ElementwiseProductComponent, RestrictedAttentionComponent, DropoutComponent, DistributeComponent, and PnormComponent.

Referenced by Compiler::AddBackwardStepComponent(), Compiler::AddForwardStepComponent(), kaldi::nnet3::AddNnetComponents(), ComputationChecker::CheckComputationIndexes(), kaldi::nnet3::ComponentDotProducts(), kaldi::nnet3::ComputeCommandAttributes(), Compiler::ComputeDerivNeeded(), NnetChainCombiner::ComputeUpdatableComponentDims(), NnetCombiner::ComputeUpdatableComponentDims(), ModelUpdateConsolidator::ConsolidateModelUpdate(), ModelUpdateConsolidator::ConsolidateUpdateForComponent(), NnetComputer::DebugAfterExecute(), NnetComputer::DebugBeforeExecute(), kaldi::nnet3::DotProduct(), kaldi::nnet3::FreezeNaturalGradient(), Compiler::GetStrideType(), CompositeComponent::InitFromConfig(), VariableMergingOptimizer::MergeVariables(), DerivativeTimeLimiter::ModifyCommand(), kaldi::nnet3::NnetParametersAreIdentical(), kaldi::nnet3::NumParameters(), kaldi::nnet3::NumUpdatableComponents(), kaldi::nnet3::PerturbParams(), NnetChainTrainer::PrintMaxChangeStats(), NnetTrainer::PrintMaxChangeStats(), NnetChainCombiner::PrintParams(), NnetCombiner::PrintParams(), 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().

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

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

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

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

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

76  {
77  std::string token;
78  ReadToken(is, binary, &token); // e.g. "<SigmoidComponent>".
79  token.erase(0, 1); // erase "<".
80  token.erase(token.length()-1); // erase ">".
81  Component *ans = NewComponentOfType(token);
82  if (!ans)
83  KALDI_ERR << "Unknown component type " << token;
84  ans->Read(is, binary);
85  return ans;
86 }
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.
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 StatisticsPoolingComponent, StatisticsExtractionComponent, TimeHeightConvolutionComponent, and RestrictedAttentionComponent.

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

Referenced by ComputationStepsComputer::ProcessComponentStep().

281  {}
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 BatchNormComponent, SoftmaxComponent, RectifiedLinearComponent, TanhComponent, SigmoidComponent, and RestrictedAttentionComponent.

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

Referenced by CompositeComponent::Backprop(), and NnetComputer::ExecuteCommand().

196  { }
virtual std::string Type ( ) const
pure virtual

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

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

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

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, BatchNormComponent, LstmNonlinearityComponent, PermuteComponent, ClipGradientComponent, NonlinearComponent, BackpropTruncationComponent, and RestrictedAttentionComponent.

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

Referenced by kaldi::nnet3::ZeroComponentStats().

203 { }

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