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

#include <nnet-general-component.h>

Inheritance diagram for BackpropTruncationComponent:
Collaboration diagram for BackpropTruncationComponent:

Public Member Functions

 BackpropTruncationComponent (int32 dim, BaseFloat scale, BaseFloat clipping_threshold, BaseFloat zeroing_threshold, int32 zeroing_interval, int32 recurrence_interval)
 
 BackpropTruncationComponent ()
 
virtual int32 InputDim () const
 Returns input-dimension of this component. More...
 
virtual int32 OutputDim () const
 Returns output-dimension of this component. More...
 
virtual void InitFromConfig (ConfigLine *cfl)
 Initialize, from a ConfigLine object. More...
 
void Init (int32 dim, BaseFloat scale, BaseFloat clipping_threshold, BaseFloat zeroing_threshold, int32 zeroing_interval, int32 recurrence_interval)
 
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 ZeroStats ()
 Components that provide an implementation of StoreStats should also provide an implementation of ZeroStats(), to set those stats to zero. More...
 
virtual ComponentCopy () const
 Copies component (deep copy). 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 > &, 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
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 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 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 std::string Info () const
 Returns some text-form information about this component, for diagnostics. More...
 
virtual ~BackpropTruncationComponent ()
 
- 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 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 ()
 

Protected Attributes

double num_clipped_
 
double num_zeroed_
 
double count_
 
double count_zeroing_boundaries_
 

Private Member Functions

BackpropTruncationComponentoperator= (const BackpropTruncationComponent &other)
 

Private Attributes

int32 dim_
 
BaseFloat scale_
 
BaseFloat clipping_threshold_
 
BaseFloat zeroing_threshold_
 
int32 zeroing_interval_
 
int32 recurrence_interval_
 
std::string debug_info_
 

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

Detailed Description

Definition at line 453 of file nnet-general-component.h.

Constructor & Destructor Documentation

BackpropTruncationComponent ( int32  dim,
BaseFloat  scale,
BaseFloat  clipping_threshold,
BaseFloat  zeroing_threshold,
int32  zeroing_interval,
int32  recurrence_interval 
)
inline

Definition at line 455 of file nnet-general-component.h.

References BackpropTruncationComponent::Init().

460  {
461  Init(dim, scale, clipping_threshold, zeroing_threshold,
462  zeroing_interval, recurrence_interval);}
void Init(int32 dim, BaseFloat scale, BaseFloat clipping_threshold, BaseFloat zeroing_threshold, int32 zeroing_interval, int32 recurrence_interval)

Definition at line 464 of file nnet-general-component.h.

Referenced by BackpropTruncationComponent::Copy().

virtual ~BackpropTruncationComponent ( )
inlinevirtual

Definition at line 510 of file nnet-general-component.h.

510  {
511  }

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 1189 of file nnet-general-component.cc.

References BackpropTruncationComponent::count_, BackpropTruncationComponent::count_zeroing_boundaries_, KALDI_ASSERT, BackpropTruncationComponent::num_clipped_, and BackpropTruncationComponent::num_zeroed_.

1190  {
1191  const BackpropTruncationComponent *other =
1192  dynamic_cast<const BackpropTruncationComponent*>(&other_in);
1193  KALDI_ASSERT(other != NULL);
1194  count_ += alpha * other->count_;
1195  count_zeroing_boundaries_ += alpha * other->count_zeroing_boundaries_;
1196  num_clipped_ += alpha * other->num_clipped_;
1197  num_zeroed_ += alpha * other->num_zeroed_;
1198 }
#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 1098 of file nnet-general-component.cc.

References CuMatrixBase< Real >::Add(), CuVectorBase< Real >::AddDiagMat2(), CuMatrixBase< Real >::ApplyHeaviside(), BackpropTruncationComponent::clipping_threshold_, CuMatrixBase< Real >::CopyFromMat(), BackpropTruncationComponent::count_, BackpropTruncationComponent::count_zeroing_boundaries_, CuVectorBase< Real >::Dim(), KALDI_ASSERT, kaldi::kNoTrans, CuVectorBase< Real >::MulElements(), CuMatrixBase< Real >::MulElements(), CuMatrixBase< Real >::MulRowsVec(), BackpropTruncationComponent::num_clipped_, BackpropTruncationComponent::num_zeroed_, CuMatrixBase< Real >::NumRows(), CuMatrixBase< Real >::Scale(), BackpropTruncationComponent::scale_, CuMatrixBase< Real >::Set(), CuMatrixBase< Real >::Sum(), BackpropTruncationComponentPrecomputedIndexes::zeroing, BackpropTruncationComponentPrecomputedIndexes::zeroing_sum, and BackpropTruncationComponent::zeroing_threshold_.

1106  {
1107  const BackpropTruncationComponentPrecomputedIndexes *indexes =
1108  dynamic_cast<const BackpropTruncationComponentPrecomputedIndexes*>(
1109  indexes_in);
1110  KALDI_ASSERT(indexes->zeroing.Dim() == out_deriv.NumRows());
1111  // the following statement will do nothing if in_deriv and out_deriv have same
1112  // memory.
1113  in_deriv->CopyFromMat(out_deriv);
1114  if (scale_ != 1.0)
1115  in_deriv->Scale(scale_);
1116 
1117  BackpropTruncationComponent *to_update =
1118  dynamic_cast<BackpropTruncationComponent*>(to_update_in);
1119 
1120  // computes clipping_scales
1121  BaseFloat clipping_threshold =
1122  (clipping_threshold_ <= 0.0 ? 1.0e+10 : clipping_threshold_);
1123  // each row in the derivative matrix, which corresponds to one sample in
1124  // the mini-batch, is scaled to have a max-norm of clipping_threshold_
1125  CuVector<BaseFloat> clipping_scales(in_deriv->NumRows());
1126  clipping_scales.AddDiagMat2(pow(clipping_threshold, -2), *in_deriv,
1127  kNoTrans, 0.0);
1128  // now clipping_scales contains the squared (norm of each row divided by
1129  // clipping_threshold)
1130  int32 num_not_scaled = clipping_scales.ApplyFloor(1.0);
1131  // now clipping_scales contains min(1, squared-(norm/clipping_threshold))
1132  clipping_scales.ApplyPow(-0.5);
1133  // now clipping_scales contains max(1, clipping_threshold/vector_norm)
1134  if (to_update != NULL) {
1135  to_update->num_clipped_ += (clipping_scales.Dim() - num_not_scaled);
1136  to_update->count_ += clipping_scales.Dim();
1137  }
1138 
1139  // computes zeroing_scales
1140  BaseFloat zeroing_threshold =
1141  (zeroing_threshold_ <= 0.0 ? 1.0e+10 : zeroing_threshold_);
1142  // zeroing_scales_vec is actually a 1-row matrix. (the ApplyHeaviside
1143  // function isn't defined for vectors).
1144  CuMatrix<BaseFloat> zeroing_scales(1, in_deriv->NumRows());
1145  CuSubVector<BaseFloat> zeroing_scales_vec(zeroing_scales, 0);
1146  zeroing_scales_vec.Set(-pow(zeroing_threshold, 2));
1147  // now zeroing_scales_vec contains -(squared zeroing_threshold)
1148  zeroing_scales_vec.AddDiagMat2(1.0, *in_deriv, kNoTrans, 1.0);
1149  // now zeroing_scales_vec contains squared norm of each row -
1150  // squared zeroing_threshold
1151  zeroing_scales.ApplyHeaviside();
1152  // now the element of zeroing_scales_vec is 1.0 if its corresponding
1153  // sample's norm exceeds zero_threshold, and 0.0 otherwise
1154  zeroing_scales_vec.MulElements(indexes->zeroing);
1155  // now the element of zeroing_scales_vec is -1.0 if we want to zero its
1156  // corresponding sample's gradient, and 0.0 otherwise
1157  if (to_update != NULL) {
1158  to_update->num_zeroed_ -= zeroing_scales_vec.Sum(); // since it is negative
1159  to_update->count_zeroing_boundaries_ += indexes->zeroing_sum;
1160  }
1161  zeroing_scales_vec.Add(1.0);
1162  // now the element of zeroing_scales_vec is 0.0 if we want to zero its
1163  // corresponding sample's gradient, and 1.0 otherwise
1164 
1165  // combines clipping_scales and zeroing_scales and applies combined_scales
1166  // to in_deriv all at once
1167  CuVector<BaseFloat> combined_scales(clipping_scales);
1168  combined_scales.MulElements(zeroing_scales_vec);
1169  in_deriv->MulRowsVec(combined_scales);
1170 }
void Scale(Real value)
Definition: cu-matrix.cc:608
void CopyFromMat(const MatrixBase< OtherReal > &src, MatrixTransposeType trans=kNoTrans)
Definition: cu-matrix.cc:337
void MulRowsVec(const CuVectorBase< Real > &scale)
scale i'th row by scale[i]
Definition: cu-matrix.cc:777
float BaseFloat
Definition: kaldi-types.h:29
MatrixIndexT NumRows() const
Dimensions.
Definition: cu-matrix.h:195
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
Component * Copy ( ) const
virtual

Copies component (deep copy).

Implements Component.

Definition at line 1035 of file nnet-general-component.cc.

References BackpropTruncationComponent::BackpropTruncationComponent(), BackpropTruncationComponent::clipping_threshold_, BackpropTruncationComponent::count_, BackpropTruncationComponent::count_zeroing_boundaries_, BackpropTruncationComponent::dim_, BackpropTruncationComponent::num_clipped_, BackpropTruncationComponent::num_zeroed_, BackpropTruncationComponent::recurrence_interval_, BackpropTruncationComponent::scale_, BackpropTruncationComponent::zeroing_interval_, and BackpropTruncationComponent::zeroing_threshold_.

1035  {
1037  ans->dim_ = dim_;
1038  ans->scale_ = scale_;
1039  ans->clipping_threshold_ = clipping_threshold_;
1040  ans->zeroing_threshold_ = zeroing_threshold_;
1041  ans->zeroing_interval_ = zeroing_interval_;
1042  ans->recurrence_interval_ = recurrence_interval_;
1043  ans->num_clipped_ = num_clipped_;
1044  ans->num_zeroed_ = num_zeroed_;
1045  ans->count_ = count_;
1046  ans->count_zeroing_boundaries_ = count_zeroing_boundaries_;
1047  return ans;
1048 }
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 Component.

Definition at line 974 of file nnet-general-component.cc.

References BackpropTruncationComponent::clipping_threshold_, BackpropTruncationComponent::count_, BackpropTruncationComponent::count_zeroing_boundaries_, BackpropTruncationComponent::dim_, BackpropTruncationComponent::num_clipped_, BackpropTruncationComponent::num_zeroed_, BackpropTruncationComponent::recurrence_interval_, BackpropTruncationComponent::scale_, BackpropTruncationComponent::Type(), BackpropTruncationComponent::zeroing_interval_, and BackpropTruncationComponent::zeroing_threshold_.

974  {
975  std::ostringstream stream;
976  stream << Type() << ", dim=" << dim_
977  << ", scale=" << scale_
978  << ", count=" << std::setprecision(3) << count_ << std::setprecision(6)
979  << ", recurrence-interval=" << recurrence_interval_
980  << ", clipping-threshold=" << clipping_threshold_
981  << ", clipped-proportion="
982  << (count_ > 0.0 ? num_clipped_ / count_ : 0)
983  << ", zeroing-threshold=" << zeroing_threshold_
984  << ", zeroing-interval=" << zeroing_interval_
985  << ", zeroed-proportion="
986  << (count_zeroing_boundaries_ > 0.0 ?
988  << ", count-zeroing-boundaries="
989  << static_cast<int32>(count_zeroing_boundaries_);
990  return stream.str();
991 }
virtual std::string Type() const
Returns a string such as "SigmoidComponent", describing the type of the object.
void Init ( int32  dim,
BaseFloat  scale,
BaseFloat  clipping_threshold,
BaseFloat  zeroing_threshold,
int32  zeroing_interval,
int32  recurrence_interval 
)

Definition at line 993 of file nnet-general-component.cc.

References BackpropTruncationComponent::clipping_threshold_, BackpropTruncationComponent::count_, BackpropTruncationComponent::count_zeroing_boundaries_, BackpropTruncationComponent::dim_, KALDI_ASSERT, BackpropTruncationComponent::num_clipped_, BackpropTruncationComponent::num_zeroed_, BackpropTruncationComponent::recurrence_interval_, BackpropTruncationComponent::scale_, BackpropTruncationComponent::zeroing_interval_, and BackpropTruncationComponent::zeroing_threshold_.

Referenced by BackpropTruncationComponent::BackpropTruncationComponent(), and BackpropTruncationComponent::InitFromConfig().

996  {
997  KALDI_ASSERT(clipping_threshold >= 0 && zeroing_threshold >= 0 &&
998  scale > 0.0 && zeroing_interval > 0 &&
999  recurrence_interval > 0 && dim > 0);
1000  dim_ = dim;
1001  scale_ = scale;
1002  clipping_threshold_ = clipping_threshold;
1003  zeroing_threshold_ = zeroing_threshold;
1004  zeroing_interval_ = zeroing_interval;
1005  recurrence_interval_ = recurrence_interval;
1006  num_clipped_ = 0.0;
1007  num_zeroed_ = 0.0;
1008  count_ = 0.0;
1010 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
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 1013 of file nnet-general-component.cc.

References ConfigLine::GetValue(), ConfigLine::HasUnusedValues(), BackpropTruncationComponent::Init(), KALDI_ERR, BackpropTruncationComponent::Type(), and ConfigLine::WholeLine().

1013  {
1014  int32 dim = 0;
1015  bool ok = cfl->GetValue("dim", &dim);
1016  BaseFloat scale = 1.0,
1017  clipping_threshold = 30.0,
1018  zeroing_threshold = 15.0;
1019  int32 zeroing_interval = 20, recurrence_interval = 1;
1020  cfl->GetValue("scale", &scale);
1021  cfl->GetValue("clipping-threshold", &clipping_threshold);
1022  cfl->GetValue("zeroing-threshold", &zeroing_threshold);
1023  cfl->GetValue("zeroing-interval", &zeroing_interval);
1024  cfl->GetValue("recurrence-interval", &recurrence_interval);
1025  if (!ok || cfl->HasUnusedValues() ||
1026  clipping_threshold < 0 || zeroing_threshold < 0 || zeroing_interval < 1 ||
1027  recurrence_interval < 1 || dim <= 0)
1028  KALDI_ERR << "Invalid initializer for layer of type "
1029  << Type() << ": \"" << cfl->WholeLine() << "\"";
1030  Init(dim, scale, clipping_threshold, zeroing_threshold,
1031  zeroing_interval, recurrence_interval);
1032 }
void Init(int32 dim, BaseFloat scale, BaseFloat clipping_threshold, BaseFloat zeroing_threshold, int32 zeroing_interval, int32 recurrence_interval)
virtual std::string Type() const
Returns a string such as "SigmoidComponent", describing the type of the object.
float BaseFloat
Definition: kaldi-types.h:29
#define KALDI_ERR
Definition: kaldi-error.h:127
virtual int32 InputDim ( ) const
inlinevirtual

Returns input-dimension of this component.

Implements Component.

Definition at line 468 of file nnet-general-component.h.

References BackpropTruncationComponent::dim_.

BackpropTruncationComponent& operator= ( const BackpropTruncationComponent other)
private
virtual int32 OutputDim ( ) const
inlinevirtual

Returns output-dimension of this component.

Implements Component.

Definition at line 469 of file nnet-general-component.h.

References BackpropTruncationComponent::dim_.

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

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

Definition at line 1052 of file nnet-general-component.cc.

References kaldi::DivideRoundingDown(), rnnlm::i, KALDI_ASSERT, BackpropTruncationComponent::recurrence_interval_, VectorBase< Real >::Sum(), BackpropTruncationComponentPrecomputedIndexes::zeroing, BackpropTruncationComponent::zeroing_interval_, and BackpropTruncationComponentPrecomputedIndexes::zeroing_sum.

1056  {
1057  int32 num_input_indexes = input_indexes.size(),
1058  num_output_indexes = output_indexes.size();
1059  KALDI_ASSERT(num_input_indexes == num_output_indexes);
1060  Vector<BaseFloat> zeroing_cpu(num_output_indexes);
1061 
1062  for (int32 i = 0; i < num_output_indexes; i++) {
1063  const int32 output_n = output_indexes[i].n;
1064  const int32 output_t = output_indexes[i].t;
1065  // checks if output_t crosses a boundary that is a multiple of
1066  // zeroing_interval_. Note that frame (output_t - recurrence_interval_) is
1067  // right before frame output_t in RNNs. If the range
1068  // [output_t - recurrence_interval_, output_t] contains a multiple of
1069  // zeroing_interval_, then frame output_t crosses the boundary.
1070  // output_n is used to shift where we put the boundary, so that
1071  // we don't always zero out gradients on frame 0. It will help avoid
1072  // learning utterance-boundary effects.
1073  if (DivideRoundingDown(output_t - output_n, zeroing_interval_) !=
1074  DivideRoundingDown(output_t - recurrence_interval_ - output_n,
1076  zeroing_cpu(i) = -1.0;
1077  }
1078 
1079  BackpropTruncationComponentPrecomputedIndexes *ans = new
1080  BackpropTruncationComponentPrecomputedIndexes();
1081  ans->zeroing = zeroing_cpu;
1082  ans->zeroing_sum = -zeroing_cpu.Sum();
1083  return ans;
1084 }
static int32 DivideRoundingDown(int32 a, int32 b)
Returns a / b, rounding towards negative infinity in all cases.
Definition: kaldi-math.h:284
#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 1087 of file nnet-general-component.cc.

References CuMatrixBase< Real >::CopyFromMat(), CuMatrixBase< Real >::Scale(), and BackpropTruncationComponent::scale_.

1090  {
1091  out->CopyFromMat(in);
1092  if (scale_ != 1.0)
1093  out->Scale(scale_);
1094  return NULL;
1095 }
void Scale(Real value)
Definition: cu-matrix.cc:608
void CopyFromMat(const MatrixBase< OtherReal > &src, MatrixTransposeType trans=kNoTrans)
Definition: cu-matrix.cc:337
virtual int32 Properties ( ) const
inlinevirtual

Return bitmask of the component's properties.

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

Implements Component.

Definition at line 477 of file nnet-general-component.h.

References kaldi::nnet3::kBackpropInPlace, kaldi::nnet3::kLinearInInput, and kaldi::nnet3::kPropagateInPlace.

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 891 of file nnet-general-component.cc.

References BackpropTruncationComponent::clipping_threshold_, BackpropTruncationComponent::count_, BackpropTruncationComponent::count_zeroing_boundaries_, BackpropTruncationComponent::dim_, kaldi::nnet3::ExpectOneOrTwoTokens(), kaldi::nnet3::ExpectToken(), KALDI_ASSERT, BackpropTruncationComponent::num_clipped_, BackpropTruncationComponent::num_zeroed_, kaldi::ReadBasicType(), kaldi::ReadToken(), BackpropTruncationComponent::recurrence_interval_, BackpropTruncationComponent::scale_, BackpropTruncationComponent::zeroing_interval_, and BackpropTruncationComponent::zeroing_threshold_.

891  {
892  // might not see the "<NaturalGradientAffineComponent>" part because
893  // of how ReadNew() works.
894  ExpectOneOrTwoTokens(is, binary, "<BackpropTruncationComponent>",
895  "<Dim>");
896  ReadBasicType(is, binary, &dim_);
897  std::string tok;
898  ReadToken(is, binary, &tok);
899  if (tok == "<Scale>") {
900  ReadBasicType(is, binary, &scale_);
901  ReadToken(is, binary, &tok);
902  } else {
903  scale_ = 1.0;
904  }
905  KALDI_ASSERT(tok == "<ClippingThreshold>");
906  ReadBasicType(is, binary, &clipping_threshold_);
907  ExpectToken(is, binary, "<ZeroingThreshold>");
908  ReadBasicType(is, binary, &zeroing_threshold_);
909  ExpectToken(is, binary, "<ZeroingInterval>");
910  ReadBasicType(is, binary, &zeroing_interval_);
911  ExpectToken(is, binary, "<RecurrenceInterval>");
912  ReadBasicType(is, binary, &recurrence_interval_);
913  ExpectToken(is, binary, "<NumElementsClipped>");
914  ReadBasicType(is, binary, &num_clipped_);
915  ExpectToken(is, binary, "<NumElementsZeroed>");
916  ReadBasicType(is, binary, &num_zeroed_);
917  ExpectToken(is, binary, "<NumElementsProcessed>");
918  ReadBasicType(is, binary, &count_);
919  ExpectToken(is, binary, "<NumZeroingBoundaries>");
921  ExpectToken(is, binary, "</BackpropTruncationComponent>");
922 }
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 ExpectOneOrTwoTokens(std::istream &is, bool binary, const std::string &token1, const std::string &token2)
This function is like ExpectToken but for two tokens, and it will either accept token1 and then token...
Definition: nnet-parse.cc:224
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)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
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 1181 of file nnet-general-component.cc.

References BackpropTruncationComponent::count_, BackpropTruncationComponent::count_zeroing_boundaries_, BackpropTruncationComponent::num_clipped_, and BackpropTruncationComponent::num_zeroed_.

virtual std::string Type ( ) const
inlinevirtual

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

Implements Component.

Definition at line 475 of file nnet-general-component.h.

Referenced by BackpropTruncationComponent::Info(), and BackpropTruncationComponent::InitFromConfig().

475 { return "BackpropTruncationComponent"; }
void Write ( std::ostream &  os,
bool  binary 
) const
virtual

Write component to stream.

Implements Component.

Definition at line 925 of file nnet-general-component.cc.

References BackpropTruncationComponent::clipping_threshold_, BackpropTruncationComponent::count_, BackpropTruncationComponent::count_zeroing_boundaries_, BackpropTruncationComponent::dim_, BackpropTruncationComponent::num_clipped_, BackpropTruncationComponent::num_zeroed_, BackpropTruncationComponent::recurrence_interval_, BackpropTruncationComponent::scale_, kaldi::WriteBasicType(), kaldi::WriteToken(), BackpropTruncationComponent::zeroing_interval_, and BackpropTruncationComponent::zeroing_threshold_.

925  {
926  WriteToken(os, binary, "<BackpropTruncationComponent>");
927  WriteToken(os, binary, "<Dim>");
928  WriteBasicType(os, binary, dim_);
929  WriteToken(os, binary, "<Scale>");
930  WriteBasicType(os, binary, scale_);
931  WriteToken(os, binary, "<ClippingThreshold>");
932  WriteBasicType(os, binary, clipping_threshold_);
933  WriteToken(os, binary, "<ZeroingThreshold>");
934  WriteBasicType(os, binary, zeroing_threshold_);
935  WriteToken(os, binary, "<ZeroingInterval>");
936  WriteBasicType(os, binary, zeroing_interval_);
937  WriteToken(os, binary, "<RecurrenceInterval>");
939  WriteToken(os, binary, "<NumElementsClipped>");
940  WriteBasicType(os, binary, num_clipped_);
941  WriteToken(os, binary, "<NumElementsZeroed>");
942  WriteBasicType(os, binary, num_zeroed_);
943  WriteToken(os, binary, "<NumElementsProcessed>");
944  WriteBasicType(os, binary, count_);
945  WriteToken(os, binary, "<NumZeroingBoundaries>");
947  WriteToken(os, binary, "</BackpropTruncationComponent>");
948 }
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
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 1173 of file nnet-general-component.cc.

References BackpropTruncationComponent::count_, BackpropTruncationComponent::count_zeroing_boundaries_, BackpropTruncationComponent::num_clipped_, and BackpropTruncationComponent::num_zeroed_.

Member Data Documentation

std::string debug_info_
private

Definition at line 539 of file nnet-general-component.h.


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