All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CompositeComponent Class Reference

CompositeComponent is a component representing a sequence of [simple] components. More...

#include <nnet-simple-component.h>

Inheritance diagram for CompositeComponent:
Collaboration diagram for CompositeComponent:

Public Member Functions

virtual int32 InputDim () const
 Returns input-dimension of this component. More...
 
virtual int32 OutputDim () const
 Returns output-dimension of this component. More...
 
virtual std::string Info () const
 Returns some text-form information about this component, for diagnostics. More...
 
virtual void InitFromConfig (ConfigLine *cfl)
 Initialize, from a ConfigLine object. More...
 
virtual ComponentCopy () const
 Copies component (deep copy). More...
 
 CompositeComponent ()
 
void Init (const std::vector< Component * > &components, int32 max_rows_process)
 
virtual std::string Type () const
 Returns a string such as "SigmoidComponent", describing the type of the object. More...
 
virtual int32 Properties () const
 Return bitmask of the component's properties. More...
 
virtual void * Propagate (const ComponentPrecomputedIndexes *indexes, const CuMatrixBase< BaseFloat > &in, CuMatrixBase< BaseFloat > *out) const
 Propagate function. More...
 
virtual void Backprop (const std::string &debug_info, const ComponentPrecomputedIndexes *indexes, const CuMatrixBase< BaseFloat > &in_value, const CuMatrixBase< BaseFloat > &, const CuMatrixBase< BaseFloat > &out_deriv, void *memo, Component *to_update, CuMatrixBase< BaseFloat > *in_deriv) const
 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 ZeroStats ()
 Components that provide an implementation of StoreStats should also provide an implementation of ZeroStats(), to set those stats to zero. More...
 
virtual void Read (std::istream &is, bool binary)
 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
 Write component to stream. More...
 
virtual void SetUnderlyingLearningRate (BaseFloat lrate)
 Sets the learning rate of gradient descent- gets multiplied by learning_rate_factor_. More...
 
virtual void SetActualLearningRate (BaseFloat lrate)
 Sets the learning rate directly, bypassing learning_rate_factor_. More...
 
virtual void SetAsGradient ()
 Sets is_gradient_ to true and sets learning_rate_ to 1, ignoring learning_rate_factor_. 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 PerturbParams (BaseFloat stddev)
 This function is to be used in testing. More...
 
virtual BaseFloat DotProduct (const UpdatableComponent &other) const
 Computes dot-product between parameters of two instances of a Component. More...
 
virtual int32 NumParameters () 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 > &params)
 Converts the parameters from vector form. More...
 
virtual void FreezeNaturalGradient (bool freeze)
 virtual More...
 
int32 NumComponents () const
 
const ComponentGetComponent (int32 i) const
 Gets the ith component in this component. More...
 
void SetComponent (int32 i, Component *component)
 Sets the ith component. More...
 
virtual ~CompositeComponent ()
 
- Public Member Functions inherited from UpdatableComponent
 UpdatableComponent (const UpdatableComponent &other)
 
 UpdatableComponent ()
 
virtual ~UpdatableComponent ()
 
virtual void SetLearningRateFactor (BaseFloat lrate_factor)
 
BaseFloat LearningRate () const
 Gets the learning rate of gradient descent. More...
 
BaseFloat MaxChange () const
 Gets per-component max-change value. More...
 
- Public Member Functions inherited from Component
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 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 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 ()
 

Private Member Functions

MatrixStrideType GetStrideType (int32 i) const
 
bool IsUpdatable () const
 

Private Attributes

int32 max_rows_process_
 
std::vector< Component * > components_
 

Additional Inherited Members

- Static Public Member Functions inherited from Component
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...
 
- Protected Member Functions inherited from UpdatableComponent
void InitLearningRatesFromConfig (ConfigLine *cfl)
 
std::string ReadUpdatableCommon (std::istream &is, bool binary)
 
void WriteUpdatableCommon (std::ostream &is, bool binary) const
 
- Protected Attributes inherited from UpdatableComponent
BaseFloat learning_rate_
 learning rate (typically 0.0..0.01) More...
 
BaseFloat learning_rate_factor_
 learning rate factor (normally 1.0, but can be set to another < value so that when < you call SetLearningRate(), that value will be scaled by this factor. More...
 
bool is_gradient_
 True if this component is to be treated as a gradient rather than as parameters. More...
 
BaseFloat max_change_
 configuration value for imposing max-change More...
 

Detailed Description

CompositeComponent is a component representing a sequence of [simple] components.

The config line would be something like the following (imagine this is all on one line):

component name=composite1 type=CompositeComponent max-rows-process=2048 num-components=3 \ component1='type=BlockAffineComponent input-dim=1000 output-dim=10000 num-blocks=100' \ component2='type=RectifiedLinearComponent dim=10000' \ component3='type=BlockAffineComponent input-dim=10000 output-dim=1000 num-blocks=100'

The reason you might want to use this component, instead of directly using the same sequence of components in the config file, is to save GPU memory (at the expense of more compute)– because doing it like this means we have to re-do parts of the forward pass in the backprop phase, but we avoid using much memory for very long (and you can make the memory usage very small by making max-rows-process small). We inherit from UpdatableComponent just in case one or more of the components in the sequence are updatable.

It is an error to nest a CompositeComponent inside a CompositeComponent. The same effect can be accomplished by specifying a smaller max-rows-process in a single CompositeComponent.

Definition at line 2318 of file nnet-simple-component.h.

Constructor & Destructor Documentation

CompositeComponent ( )
inline

Definition at line 2329 of file nnet-simple-component.h.

Referenced by CompositeComponent::Copy().

2329 { } // use Init() or InitFromConfig() to really initialize.
virtual ~CompositeComponent ( )
inlinevirtual

Definition at line 2397 of file nnet-simple-component.h.

References CompositeComponent::components_, and kaldi::DeletePointers().

std::vector< Component * > components_
void DeletePointers(std::vector< A * > *v)
Deletes any non-NULL pointers in the vector v, and sets the corresponding entries of v to NULL...
Definition: stl-utils.h:186

Member Function Documentation

void Add ( BaseFloat  alpha,
const Component other 
)
virtual

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

– a NonlinearComponent it relates to adding stats Otherwise it should do nothing.

Reimplemented from Component.

Definition at line 4714 of file nnet-simple-component.cc.

References CompositeComponent::components_, rnnlm::i, and KALDI_ASSERT.

4714  {
4715  const CompositeComponent *other = dynamic_cast<const CompositeComponent*>(
4716  &other_in);
4717  KALDI_ASSERT(other != NULL && other->components_.size() ==
4718  components_.size() && "Mismatching nnet topologies");
4719  for (size_t i = 0; i < components_.size(); i++)
4720  components_[i]->Add(alpha, *(other->components_[i]));
4721 }
virtual void Add(BaseFloat alpha, const Component &other)
This virtual function when called by – an UpdatableComponent adds the parameters of another updatabl...
std::vector< Component * > components_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
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
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.

Implements Component.

Definition at line 4569 of file nnet-simple-component.cc.

References CompositeComponent::components_, CompositeComponent::GetStrideType(), rnnlm::i, CompositeComponent::InputDim(), KALDI_ASSERT, kaldi::nnet3::kBackpropAdds, kaldi::nnet3::kBackpropNeedsInput, kaldi::nnet3::kBackpropNeedsOutput, kaldi::nnet3::kPropagateAdds, kaldi::kSetZero, kaldi::nnet3::kStoresStats, kaldi::kUndefined, kaldi::nnet3::kUpdatableComponent, kaldi::nnet3::kUsesMemo, CompositeComponent::max_rows_process_, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), CompositeComponent::OutputDim(), CompositeComponent::Properties(), and Component::StoreStats().

4576  {
4577  KALDI_ASSERT(in_value.NumRows() == out_deriv.NumRows() &&
4578  in_value.NumCols() == InputDim() &&
4579  out_deriv.NumCols() == OutputDim());
4580  int32 num_rows = in_value.NumRows(),
4581  num_components = components_.size();
4582  if (max_rows_process_ > 0 && num_rows > max_rows_process_) {
4584  // recurse and process smaller parts of the data, to save memory.
4585  for (int32 row_offset = 0; row_offset < num_rows;
4586  row_offset += max_rows_process_) {
4587  bool have_output_value = (out_value.NumRows() != 0);
4588  int32 this_num_rows = std::min<int32>(max_rows_process_,
4589  num_rows - row_offset);
4590  // out_value_part will only be used if out_value is nonempty; otherwise we
4591  // make it a submatrix of 'out_deriv' to avoid errors in the constructor.
4592  const CuSubMatrix<BaseFloat> out_value_part(have_output_value ? out_value : out_deriv,
4593  row_offset, this_num_rows,
4594  0, out_deriv.NumCols());
4595  // in_deriv_value_part will only be used if in_deriv != NULL; otherwise we
4596  // make it a submatrix of 'in_value' to avoid errors in the constructor.
4597  CuSubMatrix<BaseFloat> in_deriv_part(in_deriv != NULL ? *in_deriv : in_value,
4598  row_offset, this_num_rows,
4599  0, in_value.NumCols());
4600  CuSubMatrix<BaseFloat> in_value_part(in_value, row_offset, this_num_rows,
4601  0, in_value.NumCols());
4602  const CuSubMatrix<BaseFloat> out_deriv_part(out_deriv,
4603  row_offset, this_num_rows,
4604  0, out_deriv.NumCols());
4605  CuMatrix<BaseFloat> empty_mat;
4606  this->Backprop(debug_info, NULL, in_value_part,
4607  (have_output_value ? static_cast<const CuMatrixBase<BaseFloat>&>(out_value_part) :
4608  static_cast<const CuMatrixBase<BaseFloat>&>(empty_mat)),
4609  out_deriv_part, NULL, to_update,
4610  in_deriv != NULL ? &in_deriv_part : NULL);
4611  }
4612  return;
4613  }
4614  // For now, assume all intermediate values and derivatives need to be
4615  // computed. in_value and out_deriv will always be supplied.
4616 
4617  // intermediate_outputs[i] contains the output of component i.
4618  std::vector<CuMatrix<BaseFloat> > intermediate_outputs(num_components);
4619  // intermediate_derivs[i] contains the deriative at the output of component i.
4620  std::vector<CuMatrix<BaseFloat> > intermediate_derivs(num_components - 1);
4621 
4622  KALDI_ASSERT(memo == NULL);
4623  // note: only a very few components use memos, but we need to support them.
4624  std::vector<void*> memos(num_components, NULL);
4625 
4626  int32 num_components_to_propagate = num_components;
4627  if (!(components_[num_components - 1]->Properties() & kUsesMemo)) {
4628  // we only need to propagate the very last component if it uses a memo.
4629  num_components_to_propagate--;
4630  if (num_components > 1) {
4631  // skip the last-but-one component's propagate if the last component's
4632  // backprop doesn't need the input and the last-but-one component's
4633  // backprop doesn't need the output. This is the lowest hanging fruit for
4634  // optimization; other propagates might also be skippable.
4635  int32 properties = components_[num_components - 2]->Properties(),
4636  next_properties = components_[num_components - 1]->Properties();
4637  if (!(properties & (kBackpropNeedsOutput || kUsesMemo)) &&
4638  !(next_properties & kBackpropNeedsInput)) {
4639  num_components_to_propagate--;
4640  }
4641  }
4642  }
4643 
4644 
4645  // Do the propagation again.
4646  for (int32 i = 0; i < num_components_to_propagate; i++) {
4647  MatrixResizeType resize_type =
4648  ((components_[i]->Properties() & kPropagateAdds) ?
4649  kSetZero : kUndefined);
4650  intermediate_outputs[i].Resize(num_rows, components_[i]->OutputDim(),
4651  resize_type, GetStrideType(i));
4652  memos[i] =
4653  components_[i]->Propagate(NULL,
4654  (i == 0 ? in_value : intermediate_outputs[i-1]),
4655  &(intermediate_outputs[i]));
4656  }
4657 
4658  for (int32 i = num_components - 1; i >= 0; i--) {
4659  const CuMatrixBase<BaseFloat> &this_in_value =
4660  (i == 0 ? in_value : intermediate_outputs[i-1]),
4661  &this_out_value =
4662  (i == num_components - 1 ? out_value : intermediate_outputs[i]);
4663 
4664  Component *component_to_update =
4665  (to_update == NULL ? NULL :
4666  dynamic_cast<CompositeComponent*>(to_update)->components_[i]);
4667 
4668  if (component_to_update != NULL &&
4670  component_to_update->StoreStats(this_in_value, this_out_value, memos[i]);
4671 
4672  if (i > 0) {
4673  MatrixResizeType resize_type =
4674  ((components_[i]->Properties() & kBackpropAdds) ?
4675  kSetZero : kUndefined);
4676  intermediate_derivs[i-1].Resize(num_rows, components_[i]->InputDim(),
4677  resize_type, GetStrideType(i - 1));
4678  }
4679  // skip the first component's backprop if it's not updatable and in_deriv is
4680  // not requested. Again, this is the lowest-hanging fruit to optimize.
4681  if (!(i == 0 && !(components_[0]->Properties() & kUpdatableComponent) &&
4682  in_deriv == NULL)) {
4683  components_[i]->Backprop(debug_info, NULL,
4684  this_in_value, this_out_value,
4685  (i + 1 == num_components ? out_deriv : intermediate_derivs[i]),
4686  memos[i], component_to_update,
4687  (i == 0 ? in_deriv : &(intermediate_derivs[i-1])));
4688  }
4689  if (memos[i] != NULL)
4690  components_[i]->DeleteMemo(memos[i]);
4691  }
4692 }
MatrixResizeType
Definition: matrix-common.h:35
MatrixIndexT NumCols() const
Definition: cu-matrix.h:196
virtual int32 Properties() const
Return bitmask of the component's properties.
virtual void Backprop(const std::string &debug_info, const ComponentPrecomputedIndexes *indexes, const CuMatrixBase< BaseFloat > &in_value, const CuMatrixBase< BaseFloat > &, const CuMatrixBase< BaseFloat > &out_deriv, void *memo, Component *to_update, CuMatrixBase< BaseFloat > *in_deriv) const
Backprop function; depending on which of the arguments 'to_update' and 'in_deriv' are non-NULL...
MatrixIndexT NumRows() const
Dimensions.
Definition: cu-matrix.h:195
virtual int32 InputDim() const
Returns input-dimension of this component.
std::vector< Component * > components_
MatrixStrideType GetStrideType(int32 i) const
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
virtual int32 OutputDim() const
Returns output-dimension of this component.
Component * Copy ( ) const
virtual

Copies component (deep copy).

Implements Component.

Definition at line 4858 of file nnet-simple-component.cc.

References CompositeComponent::components_, CompositeComponent::CompositeComponent(), rnnlm::i, CompositeComponent::Init(), and CompositeComponent::max_rows_process_.

4858  {
4859  std::vector<Component*> components(components_.size());
4860  for (size_t i = 0; i < components_.size(); i++)
4861  components[i] = components_[i]->Copy();
4863  ans->Init(components, max_rows_process_);
4864  return ans;
4865 }
virtual Component * Copy() const
Copies component (deep copy).
std::vector< Component * > components_
BaseFloat DotProduct ( const UpdatableComponent other) const
virtual

Computes dot-product between parameters of two instances of a Component.

Can be used for computing parameter-norm of an UpdatableComponent.

Implements UpdatableComponent.

Definition at line 4825 of file nnet-simple-component.cc.

References CompositeComponent::components_, UpdatableComponent::DotProduct(), rnnlm::i, KALDI_ASSERT, kaldi::nnet3::kUpdatableComponent, and CompositeComponent::Properties().

4826  {
4827  const CompositeComponent *other = dynamic_cast<const CompositeComponent*>(
4828  &other_in);
4829  KALDI_ASSERT(other != NULL && other->components_.size() ==
4830  components_.size() && "Mismatching nnet topologies");
4831  BaseFloat ans = 0.0;
4832  for (size_t i = 0.0; i < components_.size(); i++) {
4834  UpdatableComponent *uc =
4835  dynamic_cast<UpdatableComponent*>(components_[i]);
4836  const UpdatableComponent *uc_other =
4837  dynamic_cast<UpdatableComponent*>(other->components_[i]);
4838  KALDI_ASSERT(uc != NULL && uc_other != NULL);
4839  ans += uc->DotProduct(*uc_other);
4840  }
4841  }
4842  return ans;
4843 }
virtual int32 Properties() const
Return bitmask of the component's properties.
float BaseFloat
Definition: kaldi-types.h:29
std::vector< Component * > components_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void FreezeNaturalGradient ( bool  freeze)
virtual

virtual

Reimplemented from UpdatableComponent.

Definition at line 4846 of file nnet-simple-component.cc.

References CompositeComponent::components_, UpdatableComponent::FreezeNaturalGradient(), rnnlm::i, KALDI_ASSERT, kaldi::nnet3::kUpdatableComponent, and CompositeComponent::Properties().

4846  {
4847  for (size_t i = 0; i < components_.size(); i++) {
4849  UpdatableComponent *uc =
4850  dynamic_cast<UpdatableComponent*>(components_[i]);
4851  KALDI_ASSERT(uc != NULL);
4852  uc->FreezeNaturalGradient(freeze);
4853  }
4854  }
4855 }
virtual int32 Properties() const
Return bitmask of the component's properties.
std::vector< Component * > components_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
const Component * GetComponent ( int32  i) const

Gets the ith component in this component.

The ordering is the same as in the config line. The caller does not own the received component.

Definition at line 4924 of file nnet-simple-component.cc.

References CompositeComponent::components_, rnnlm::i, and KALDI_ASSERT.

Referenced by kaldi::nnet3::ConvertRepeatedToBlockAffine(), and kaldi::nnet3::UnitTestConvertRepeatedToBlockAffineComposite().

4924  {
4925  KALDI_ASSERT(static_cast<size_t>(i) < components_.size());
4926  return components_[i];
4927 }
std::vector< Component * > components_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
MatrixStrideType GetStrideType ( int32  i) const
inlineprivate
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 from UpdatableComponent.

Definition at line 4696 of file nnet-simple-component.cc.

References CompositeComponent::components_, rnnlm::i, and CompositeComponent::Type().

4696  {
4697  std::ostringstream stream;
4698  stream << Type() << " ";
4699  for (size_t i = 0; i < components_.size(); i++) {
4700  if (i > 0) stream << ", ";
4701  stream << "sub-component" << (i+1) << " = { "
4702  << components_[i]->Info() << " }";
4703  }
4704  return stream.str();
4705 }
virtual std::string Info() const
Returns some text-form information about this component, for diagnostics.
virtual std::string Type() const
Returns a string such as "SigmoidComponent", describing the type of the object.
std::vector< Component * > components_
void Init ( const std::vector< Component * > &  components,
int32  max_rows_process 
)

Definition at line 4476 of file nnet-simple-component.cc.

References CompositeComponent::components_, kaldi::DeletePointers(), rnnlm::i, CompositeComponent::InputDim(), KALDI_ASSERT, kaldi::nnet3::kSimpleComponent, CompositeComponent::max_rows_process_, CompositeComponent::OutputDim(), and CompositeComponent::Properties().

Referenced by CompositeComponent::Copy(), CompositeComponent::InitFromConfig(), and CompositeComponent::Read().

4477  {
4478  DeletePointers(&components_); // clean up.
4479  components_ = components;
4480  KALDI_ASSERT(!components.empty());
4481  max_rows_process_ = max_rows_process;
4482 
4483  for (size_t i = 0; i < components_.size(); i++) {
4484  // make sure all constituent components are simple.
4486  if (i > 0) {
4487  // make sure all the internal dimensions match up.
4489  components_[i-1]->OutputDim());
4490  }
4491  }
4492 }
virtual int32 Properties() const
Return bitmask of the component's properties.
virtual int32 InputDim() const
Returns input-dimension of this component.
std::vector< Component * > components_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void DeletePointers(std::vector< A * > *v)
Deletes any non-NULL pointers in the vector v, and sets the corresponding entries of v to NULL...
Definition: stl-utils.h:186
virtual int32 OutputDim() const
Returns output-dimension of this component.
void InitFromConfig ( ConfigLine cfl)
virtual

Initialize, from a ConfigLine object.

Parameters
[in]cflA ConfigLine containing any parameters that are needed for initialization. For example: "dim=100 param-stddev=0.1"

Implements Component.

Definition at line 4869 of file nnet-simple-component.cc.

References kaldi::DeletePointers(), ConfigLine::FirstToken(), ConfigLine::GetValue(), ConfigLine::HasUnusedValues(), rnnlm::i, CompositeComponent::Init(), Component::InitFromConfig(), KALDI_ERR, kaldi::nnet3::kRandomComponent, kaldi::nnet3::kSimpleComponent, Component::NewComponentOfType(), ConfigLine::ParseLine(), Component::Properties(), Component::Type(), ConfigLine::UnusedValues(), and ConfigLine::WholeLine().

4869  {
4870  int32 max_rows_process = 4096, num_components = -1;
4871  cfl->GetValue("max-rows-process", &max_rows_process);
4872  if (!cfl->GetValue("num-components", &num_components) ||
4873  num_components < 1)
4874  KALDI_ERR << "Expected num-components to be defined in "
4875  << "CompositeComponent config line '" << cfl->WholeLine() << "'";
4876  std::vector<Component*> components;
4877  for (int32 i = 1; i <= num_components; i++) {
4878  std::ostringstream name_stream;
4879  name_stream << "component" << i;
4880  std::string component_config;
4881  if (!cfl->GetValue(name_stream.str(), &component_config)) {
4882  DeletePointers(&components);
4883  KALDI_ERR << "Expected '" << name_stream.str() << "' to be defined in "
4884  << "CompositeComponent config line '" << cfl->WholeLine() << "'";
4885  }
4886  ConfigLine nested_line;
4887  // note: the nested line may not contain comments.
4888  std::string component_type;
4889  Component *this_component = NULL;
4890  if (!nested_line.ParseLine(component_config) ||
4891  !nested_line.GetValue("type", &component_type) ||
4892  !(this_component = NewComponentOfType(component_type)) ||
4893  nested_line.FirstToken() != "") {
4894  DeletePointers(&components);
4895  KALDI_ERR << "Could not parse config line for '" << name_stream.str()
4896  << "(or undefined or bad component type [type=xxx]), in "
4897  << "CompositeComponent config line '" << cfl->WholeLine() << "'";
4898  }
4899  if(this_component->Type() == "CompositeComponent") {
4900  DeletePointers(&components);
4901  delete this_component;
4902  // This is not allowed. If memory is too much with just one
4903  // CompositeComponent, try decreasing max-rows-process instead.
4904  KALDI_ERR << "Found CompositeComponent nested within CompositeComponent."
4905  << "Nested line: '" << nested_line.WholeLine() << "'\n"
4906  << "Toplevel CompositeComponent line '" << cfl->WholeLine()
4907  << "'";
4908  }
4909  this_component->InitFromConfig(&nested_line);
4910  int32 props = this_component->Properties();
4911  if ((props & kRandomComponent) != 0 ||
4912  (props & kSimpleComponent) == 0) {
4913  KALDI_ERR << "CompositeComponent contains disallowed component type: "
4914  << nested_line.WholeLine();
4915  }
4916  components.push_back(this_component);
4917  }
4918  if (cfl->HasUnusedValues())
4919  KALDI_ERR << "Could not process these elements in initializer: "
4920  << cfl->UnusedValues();
4921  this->Init(components, max_rows_process);
4922 }
#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.
void DeletePointers(std::vector< A * > *v)
Deletes any non-NULL pointers in the vector v, and sets the corresponding entries of v to NULL...
Definition: stl-utils.h:186
void Init(const std::vector< Component * > &components, int32 max_rows_process)
int32 InputDim ( ) const
virtual

Returns input-dimension of this component.

Implements Component.

Definition at line 4383 of file nnet-simple-component.cc.

References CompositeComponent::components_, and KALDI_ASSERT.

Referenced by CompositeComponent::Backprop(), CompositeComponent::Init(), and CompositeComponent::Propagate().

4383  {
4384  KALDI_ASSERT(!components_.empty());
4385  return components_.front()->InputDim();
4386 };
std::vector< Component * > components_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
bool IsUpdatable ( ) const
private
int32 NumComponents ( ) const
inline
int32 NumParameters ( ) const
virtual

The following new virtual function returns the total dimension of the parameters in this class.

Reimplemented from UpdatableComponent.

Definition at line 4777 of file nnet-simple-component.cc.

References CompositeComponent::components_, rnnlm::i, CompositeComponent::IsUpdatable(), KALDI_ASSERT, kaldi::nnet3::kUpdatableComponent, UpdatableComponent::NumParameters(), and CompositeComponent::Properties().

4777  {
4778  KALDI_ASSERT(this->IsUpdatable()); // or should not be called.
4779  int32 ans = 0;
4780  for (size_t i = 0; i < components_.size(); i++) {
4782  UpdatableComponent *uc =
4783  dynamic_cast<UpdatableComponent*>(components_[i]);
4784  ans += uc->NumParameters();
4785  }
4786  }
4787  return ans;
4788 }
virtual int32 Properties() const
Return bitmask of the component's properties.
std::vector< Component * > components_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
int32 OutputDim ( ) const
virtual

Returns output-dimension of this component.

Implements Component.

Definition at line 4389 of file nnet-simple-component.cc.

References CompositeComponent::components_, and KALDI_ASSERT.

Referenced by CompositeComponent::Backprop(), CompositeComponent::Init(), and CompositeComponent::Propagate().

4389  {
4390  KALDI_ASSERT(!components_.empty());
4391  return components_.back()->OutputDim();
4392 };
std::vector< Component * > components_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void PerturbParams ( BaseFloat  stddev)
virtual

This function is to be used in testing.

It adds unit noise times "stddev" to the parameters of the component.

Implements UpdatableComponent.

Definition at line 4724 of file nnet-simple-component.cc.

References CompositeComponent::components_, rnnlm::i, CompositeComponent::IsUpdatable(), KALDI_ASSERT, kaldi::nnet3::kUpdatableComponent, UpdatableComponent::PerturbParams(), and CompositeComponent::Properties().

4724  {
4725  KALDI_ASSERT(this->IsUpdatable()); // or should not be called.
4726  for (size_t i = 0; i < components_.size(); i++) {
4728  UpdatableComponent *uc =
4729  dynamic_cast<UpdatableComponent*>(components_[i]);
4730  uc->PerturbParams(stddev);
4731  }
4732  }
4733 }
virtual int32 Properties() const
Return bitmask of the component's properties.
std::vector< Component * > components_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void * Propagate ( const ComponentPrecomputedIndexes indexes,
const CuMatrixBase< BaseFloat > &  in,
CuMatrixBase< BaseFloat > *  out 
) const
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.

Implements Component.

Definition at line 4429 of file nnet-simple-component.cc.

References CompositeComponent::components_, CompositeComponent::GetStrideType(), rnnlm::i, CompositeComponent::InputDim(), KALDI_ASSERT, kaldi::nnet3::kPropagateAdds, kaldi::kSetZero, kaldi::kUndefined, CompositeComponent::max_rows_process_, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), and CompositeComponent::OutputDim().

4432  {
4433  KALDI_ASSERT(in.NumRows() == out->NumRows() && in.NumCols() == InputDim() &&
4434  out->NumCols() == OutputDim());
4435  int32 num_rows = in.NumRows(),
4436  num_components = components_.size();
4437  if (max_rows_process_ > 0 && num_rows > max_rows_process_) {
4438  // recurse and process smaller parts of the data, to save memory.
4439  for (int32 row_offset = 0; row_offset < num_rows;
4440  row_offset += max_rows_process_) {
4441  int32 this_num_rows = std::min<int32>(max_rows_process_,
4442  num_rows - row_offset);
4443  const CuSubMatrix<BaseFloat> in_part(in, row_offset, this_num_rows,
4444  0, in.NumCols());
4445  CuSubMatrix<BaseFloat> out_part(*out, row_offset, this_num_rows,
4446  0, out->NumCols());
4447  this->Propagate(NULL, in_part, &out_part);
4448  }
4449  return NULL;
4450  }
4451  std::vector<CuMatrix<BaseFloat> > intermediate_outputs(num_components - 1);
4452  for (int32 i = 0; i < num_components; i++) {
4453  if (i + 1 < num_components) {
4454  MatrixResizeType resize_type =
4455  ((components_[i]->Properties() & kPropagateAdds) ?
4456  kSetZero : kUndefined);
4457  intermediate_outputs[i].Resize(num_rows, components_[i]->OutputDim(),
4458  resize_type, GetStrideType(i));
4459  }
4460  const CuMatrixBase<BaseFloat> &this_in = (i == 0 ? in :
4461  intermediate_outputs[i-1]);
4462  CuMatrixBase<BaseFloat> *this_out = (i + 1 == num_components ?
4463  out : &(intermediate_outputs[i]));
4464  void *memo = components_[i]->Propagate(NULL, this_in, this_out);
4465  // we'll re-do the forward propagation in the backprop, and we can
4466  // regenerate any memos there, so no need to keep them.
4467  if (memo != NULL)
4468  components_[i]->DeleteMemo(memo);
4469  if (i > 0)
4470  intermediate_outputs[i-1].Resize(0, 0);
4471  }
4472  return NULL;
4473 }
MatrixResizeType
Definition: matrix-common.h:35
MatrixIndexT NumCols() const
Definition: cu-matrix.h:196
MatrixIndexT NumRows() const
Dimensions.
Definition: cu-matrix.h:195
virtual int32 InputDim() const
Returns input-dimension of this component.
virtual void * Propagate(const ComponentPrecomputedIndexes *indexes, const CuMatrixBase< BaseFloat > &in, CuMatrixBase< BaseFloat > *out) const
Propagate function.
std::vector< Component * > components_
MatrixStrideType GetStrideType(int32 i) const
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
virtual int32 OutputDim() const
Returns output-dimension of this component.
int32 Properties ( ) const
virtual

Return bitmask of the component's properties.

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

Implements Component.

Definition at line 4395 of file nnet-simple-component.cc.

References CompositeComponent::components_, CompositeComponent::IsUpdatable(), KALDI_ASSERT, kaldi::nnet3::kBackpropAdds, kaldi::nnet3::kBackpropNeedsInput, kaldi::nnet3::kBackpropNeedsOutput, kaldi::nnet3::kInputContiguous, kaldi::nnet3::kOutputContiguous, kaldi::nnet3::kPropagateAdds, kaldi::nnet3::kSimpleComponent, kaldi::nnet3::kStoresStats, and kaldi::nnet3::kUpdatableComponent.

Referenced by CompositeComponent::Backprop(), CompositeComponent::DotProduct(), CompositeComponent::FreezeNaturalGradient(), CompositeComponent::GetStrideType(), CompositeComponent::Init(), CompositeComponent::NumParameters(), CompositeComponent::PerturbParams(), CompositeComponent::SetActualLearningRate(), CompositeComponent::SetAsGradient(), CompositeComponent::SetUnderlyingLearningRate(), CompositeComponent::UnVectorize(), and CompositeComponent::Vectorize().

4395  {
4396  KALDI_ASSERT(!components_.empty());
4397  int32 last_component_properties = components_.back()->Properties(),
4398  first_component_properties = components_.front()->Properties();
4399  // We always assume backprop needs the input, as this would be necessary to
4400  // get the activations at intermediate layers, if these were not needed in
4401  // backprop, there would be no reason to use a CompositeComponent.
4402  int32 ans = kSimpleComponent | kBackpropNeedsInput |
4403  (last_component_properties &
4405  (first_component_properties &
4407  (IsUpdatable() ? kUpdatableComponent : 0);
4408  // note, we don't return the kStoresStats property because that function is
4409  // not implemented; instead, for efficiency, we call StoreStats() on any
4410  // sub-components as part of the backprop phase.
4411  if (last_component_properties & kStoresStats)
4412  ans |= kBackpropNeedsOutput;
4413  return ans;
4414 };
std::vector< Component * > components_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void Read ( std::istream &  is,
bool  binary 
)
virtual

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.

Implements Component.

Definition at line 4495 of file nnet-simple-component.cc.

References kaldi::nnet3::ExpectToken(), rnnlm::i, CompositeComponent::Init(), UpdatableComponent::is_gradient_, KALDI_ERR, UpdatableComponent::learning_rate_, UpdatableComponent::learning_rate_factor_, kaldi::ReadBasicType(), Component::ReadNew(), kaldi::ReadToken(), and UpdatableComponent::ReadUpdatableCommon().

4495  {
4496  // Because we didn't previously write out the learning rate,
4497  // we need some temporary code.
4498  int32 max_rows_process;
4499  if (false) {
4500  ReadUpdatableCommon(is, binary);
4501  ExpectToken(is, binary, "<MaxRowsProcess>");
4502  ReadBasicType(is, binary, &max_rows_process);
4503  } else { // temporary code.
4504  std::string token;
4505  ReadToken(is, binary, &token);
4506  if (token == "<CompositeComponent>") {
4507  // if the first token is the opening tag, then
4508  // ignore it and get the next tag.
4509  ReadToken(is, binary, &token);
4510  }
4511  if (token == "<LearningRateFactor>") {
4512  ReadBasicType(is, binary, &learning_rate_factor_);
4513  ReadToken(is, binary, &token);
4514  } else {
4515  learning_rate_factor_ = 1.0;
4516  }
4517  if (token == "<IsGradient>") {
4518  ReadBasicType(is, binary, &is_gradient_);
4519  ReadToken(is, binary, &token);
4520  } else {
4521  is_gradient_ = false;
4522  }
4523  if (token == "<LearningRate>") {
4524  ReadBasicType(is, binary, &learning_rate_);
4525  ReadToken(is, binary, &token);
4526  }
4527  if (token != "<MaxRowsProcess>") {
4528  KALDI_ERR << "Expected token <MaxRowsProcess>, got "
4529  << token;
4530  }
4531  ReadBasicType(is, binary, &max_rows_process);
4532  }
4533  ExpectToken(is, binary, "<NumComponents>");
4534  int32 num_components;
4535  ReadBasicType(is, binary, &num_components); // Read dimension.
4536  if (num_components < 0 || num_components > 100000)
4537  KALDI_ERR << "Bad num-components";
4538  std::vector<Component*> components(num_components);
4539  for (int32 i = 0; i < num_components; i++)
4540  components[i] = ReadNew(is, binary);
4541  Init(components, max_rows_process);
4542  ExpectToken(is, binary, "</CompositeComponent>");
4543 }
void ReadBasicType(std::istream &is, bool binary, T *t)
ReadBasicType is the name of the read function for bool, integer types, and floating-point types...
Definition: io-funcs-inl.h:55
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
static void ExpectToken(const std::string &token, const std::string &what_we_are_parsing, const std::string **next_token)
BaseFloat learning_rate_
learning rate (typically 0.0..0.01)
std::string ReadUpdatableCommon(std::istream &is, bool binary)
#define KALDI_ERR
Definition: kaldi-error.h:127
static Component * ReadNew(std::istream &is, bool binary)
Read component from stream (works out its type). Dies on error.
BaseFloat learning_rate_factor_
learning rate factor (normally 1.0, but can be set to another < value so that when < you call SetLear...
bool is_gradient_
True if this component is to be treated as a gradient rather than as parameters.
void Init(const std::vector< Component * > &components, int32 max_rows_process)
void Scale ( BaseFloat  scale)
virtual

This virtual function when called by.

by "scale" when called by an UpdatableComponent. stores stats, like BatchNormComponent– it relates to scaling activation stats, not parameters.

Reimplemented from Component.

Definition at line 4708 of file nnet-simple-component.cc.

References CompositeComponent::components_, and rnnlm::i.

4708  {
4709  for (size_t i = 0; i < components_.size(); i++)
4710  components_[i]->Scale(scale);
4711 }
std::vector< Component * > components_
virtual void Scale(BaseFloat scale)
This virtual function when called by.
void SetActualLearningRate ( BaseFloat  lrate)
virtual

Sets the learning rate directly, bypassing learning_rate_factor_.

Reimplemented from UpdatableComponent.

Definition at line 4751 of file nnet-simple-component.cc.

References CompositeComponent::components_, rnnlm::i, CompositeComponent::IsUpdatable(), KALDI_ASSERT, kaldi::nnet3::kUpdatableComponent, CompositeComponent::Properties(), and UpdatableComponent::SetActualLearningRate().

4751  {
4752  KALDI_ASSERT(this->IsUpdatable()); // or should not be called.
4754  for (size_t i = 0; i < components_.size(); i++) {
4756  UpdatableComponent *uc =
4757  dynamic_cast<UpdatableComponent*>(components_[i]);
4758  uc->SetActualLearningRate(lrate);
4759  }
4760  }
4761 }
virtual int32 Properties() const
Return bitmask of the component's properties.
std::vector< Component * > components_
virtual void SetActualLearningRate(BaseFloat lrate)
Sets the learning rate directly, bypassing learning_rate_factor_.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void SetAsGradient ( )
virtual

Sets is_gradient_ to true and sets learning_rate_ to 1, ignoring learning_rate_factor_.

Reimplemented from UpdatableComponent.

Definition at line 4764 of file nnet-simple-component.cc.

References CompositeComponent::components_, rnnlm::i, CompositeComponent::IsUpdatable(), KALDI_ASSERT, kaldi::nnet3::kUpdatableComponent, CompositeComponent::Properties(), and UpdatableComponent::SetAsGradient().

4764  {
4765  KALDI_ASSERT(this->IsUpdatable()); // or should not be called.
4767  for (size_t i = 0; i < components_.size(); i++) {
4769  UpdatableComponent *uc =
4770  dynamic_cast<UpdatableComponent*>(components_[i]);
4771  uc->SetAsGradient();
4772  }
4773  }
4774 }
virtual int32 Properties() const
Return bitmask of the component's properties.
std::vector< Component * > components_
virtual void SetAsGradient()
Sets is_gradient_ to true and sets learning_rate_ to 1, ignoring learning_rate_factor_.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void SetComponent ( int32  i,
Component component 
)

Sets the ith component.

After this call, CompositeComponent owns the reference to the argument component. Frees the previous ith component.

Definition at line 4929 of file nnet-simple-component.cc.

References CompositeComponent::components_, rnnlm::i, and KALDI_ASSERT.

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

4929  {
4930  KALDI_ASSERT(static_cast<size_t>(i) < components_.size());
4931  delete components_[i];
4932  components_[i] = component;
4933 }
std::vector< Component * > components_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void SetUnderlyingLearningRate ( BaseFloat  lrate)
virtual

Sets the learning rate of gradient descent- gets multiplied by learning_rate_factor_.

Reimplemented from UpdatableComponent.

Definition at line 4735 of file nnet-simple-component.cc.

References CompositeComponent::components_, rnnlm::i, CompositeComponent::IsUpdatable(), KALDI_ASSERT, kaldi::nnet3::kUpdatableComponent, UpdatableComponent::LearningRate(), CompositeComponent::Properties(), and UpdatableComponent::SetUnderlyingLearningRate().

4735  {
4736  KALDI_ASSERT(this->IsUpdatable()); // or should not be called.
4738 
4739  // apply any learning-rate-factor that's set at this level (ill-advised, but
4740  // we'll do it.)
4741  BaseFloat effective_lrate = LearningRate();
4742  for (size_t i = 0; i < components_.size(); i++) {
4744  UpdatableComponent *uc =
4745  dynamic_cast<UpdatableComponent*>(components_[i]);
4746  uc->SetUnderlyingLearningRate(effective_lrate);
4747  }
4748  }
4749 }
virtual int32 Properties() const
Return bitmask of the component's properties.
BaseFloat LearningRate() const
Gets the learning rate of gradient descent.
float BaseFloat
Definition: kaldi-types.h:29
std::vector< Component * > components_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
virtual void SetUnderlyingLearningRate(BaseFloat lrate)
Sets the learning rate of gradient descent- gets multiplied by learning_rate_factor_.
virtual std::string Type ( ) const
inlinevirtual

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

Implements Component.

Definition at line 2335 of file nnet-simple-component.h.

Referenced by CompositeComponent::Info().

2335 { return "CompositeComponent"; }
void UnVectorize ( const VectorBase< BaseFloat > &  params)
virtual

Converts the parameters from vector form.

Reimplemented from UpdatableComponent.

Definition at line 4808 of file nnet-simple-component.cc.

References CompositeComponent::components_, VectorBase< Real >::Dim(), rnnlm::i, CompositeComponent::IsUpdatable(), KALDI_ASSERT, kaldi::nnet3::kUpdatableComponent, UpdatableComponent::NumParameters(), CompositeComponent::Properties(), and UpdatableComponent::UnVectorize().

4808  {
4809  int32 cur_offset = 0;
4810  KALDI_ASSERT(this->IsUpdatable()); // or should not be called.
4811  for (size_t i = 0; i < components_.size(); i++) {
4813  UpdatableComponent *uc =
4814  dynamic_cast<UpdatableComponent*>(components_[i]);
4815  int32 this_size = uc->NumParameters();
4816  SubVector<BaseFloat> params_range(params, cur_offset, this_size);
4817  uc->UnVectorize(params_range);
4818  cur_offset += this_size;
4819  }
4820  }
4821  KALDI_ASSERT(cur_offset == params.Dim());
4822 }
virtual int32 Properties() const
Return bitmask of the component's properties.
std::vector< Component * > components_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:62
void Vectorize ( VectorBase< BaseFloat > *  params) const
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 4791 of file nnet-simple-component.cc.

References CompositeComponent::components_, VectorBase< Real >::Dim(), rnnlm::i, CompositeComponent::IsUpdatable(), KALDI_ASSERT, kaldi::nnet3::kUpdatableComponent, UpdatableComponent::NumParameters(), CompositeComponent::Properties(), and UpdatableComponent::Vectorize().

4791  {
4792  int32 cur_offset = 0;
4793  KALDI_ASSERT(this->IsUpdatable()); // or should not be called.
4794  for (size_t i = 0; i < components_.size(); i++) {
4796  UpdatableComponent *uc =
4797  dynamic_cast<UpdatableComponent*>(components_[i]);
4798  int32 this_size = uc->NumParameters();
4799  SubVector<BaseFloat> params_range(*params, cur_offset, this_size);
4800  uc->Vectorize(&params_range);
4801  cur_offset += this_size;
4802  }
4803  }
4804  KALDI_ASSERT(cur_offset == params->Dim());
4805 }
virtual int32 Properties() const
Return bitmask of the component's properties.
std::vector< Component * > components_
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:62
void Write ( std::ostream &  os,
bool  binary 
) const
virtual

Write component to stream.

Implements Component.

Definition at line 4555 of file nnet-simple-component.cc.

References CompositeComponent::components_, rnnlm::i, CompositeComponent::max_rows_process_, kaldi::WriteBasicType(), kaldi::WriteToken(), and UpdatableComponent::WriteUpdatableCommon().

4555  {
4556  WriteUpdatableCommon(os, binary); // Write opening tag and learning rate.
4557  WriteToken(os, binary, "<MaxRowsProcess>");
4558  WriteBasicType(os, binary, max_rows_process_);
4559  WriteToken(os, binary, "<NumComponents>");
4560  int32 num_components = components_.size();
4561  WriteBasicType(os, binary, num_components);
4562  for (int32 i = 0; i < num_components; i++)
4563  components_[i]->Write(os, binary);
4564  WriteToken(os, binary, "</CompositeComponent>");
4565 }
void WriteUpdatableCommon(std::ostream &is, bool binary) const
std::vector< Component * > components_
void WriteToken(std::ostream &os, bool binary, const char *token)
The WriteToken functions are for writing nonempty sequences of non-space characters.
Definition: io-funcs.cc:134
virtual void Write(std::ostream &os, bool binary) const
Write component to stream.
void WriteBasicType(std::ostream &os, bool binary, T t)
WriteBasicType is the name of the write function for bool, integer types, and floating-point types...
Definition: io-funcs-inl.h:34
void ZeroStats ( )
virtual

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 from Component.

Definition at line 4546 of file nnet-simple-component.cc.

References CompositeComponent::components_, and rnnlm::i.

4546  {
4547  // we call ZeroStats() on all components without checking their flags; this
4548  // will do nothing if the component doesn't store stats. (components like
4549  // ReLU and sigmoid and tanh store stats on activations).
4550  for (size_t i = 0; i < components_.size(); i++)
4551  components_[i]->ZeroStats();
4552 }
virtual void ZeroStats()
Components that provide an implementation of StoreStats should also provide an implementation of Zero...
std::vector< Component * > components_

Member Data Documentation


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