GeneralDropoutComponent implements dropout, including a continuous variant where the thing we multiply is not just zero or one, but may be a continuous value. More...
#include <nnet-general-component.h>
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... | |
GeneralDropoutComponent () | |
GeneralDropoutComponent (const GeneralDropoutComponent &other) | |
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 > &, 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 | 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... | |
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 | 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 Component * | Copy () const |
Copies component (deep copy). More... | |
void | SetDropoutProportion (BaseFloat p) |
Public Member Functions inherited from RandomComponent | |
void | ResetGenerator () |
void | SetTestMode (bool test_mode) |
RandomComponent () | |
RandomComponent (const RandomComponent &other) | |
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 | 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 void | Scale (BaseFloat scale) |
This virtual function when called on – an UpdatableComponent scales the parameters by "scale" when called by an UpdatableComponent. More... | |
virtual void | Add (BaseFloat alpha, const Component &other) |
This virtual function when called by – an UpdatableComponent adds the parameters of another updatable component, times some constant, to the current parameters. More... | |
virtual void | ConsolidateMemory () |
This virtual function relates to memory management, and avoiding fragmentation. More... | |
Component () | |
virtual | ~Component () |
Private Member Functions | |
CuMatrix< BaseFloat > * | GetMemo (int32 num_mask_rows) const |
const GeneralDropoutComponent & | operator= (const GeneralDropoutComponent &other) |
Private Attributes | |
int32 | dim_ |
int32 | block_dim_ |
int32 | time_period_ |
BaseFloat | dropout_proportion_ |
BaseFloat | specaugment_max_proportion_ |
int32 | specaugment_max_regions_ |
bool | continuous_ |
Additional Inherited Members | |
Static Public Member Functions inherited from Component | |
static Component * | ReadNew (std::istream &is, bool binary) |
Read component from stream (works out its type). Dies on error. More... | |
static Component * | NewComponentOfType (const std::string &type) |
Returns a new Component of the given type e.g. More... | |
Protected Attributes inherited from RandomComponent | |
CuRand< BaseFloat > | random_generator_ |
bool | test_mode_ |
GeneralDropoutComponent implements dropout, including a continuous variant where the thing we multiply is not just zero or one, but may be a continuous value.
It is intended for the case where you want to either share the dropout mask across all of time, or across groups of 't' values (e.g. the first block of 10 values gets one dropout mask, the second block of 10 gets another one, and so on).
It also has support for the frequency component of SpecAugment.
Configuration values accepted on the command line, with defaults:
dim Dimension of the input and output of this component, e.g. 512
block-dim Block size if you want the dropout mask to repeat, e.g. if dim=512 and you sent block-dim=128, there will be a mask of dimension 128 repeated 4 times. This can be useful in convolutional setups. If not specified, block-dim defaults to 'dim'; if specified, it must be a divisor of 'dim'.
dropout-proportion=0.5 For conventional dropout, this is the proportion of mask values that (in expectation) are zero; it would normally be between 0 and 0.5. The nonzero mask values will be given values 1.0 / dropout_proportion, so that the expected value is 1.0. This behavior is different from DropoutComponent and DropoutMaskComponent.
For continuous dropout (continuous==true), the dropout scales will have values (1.0 + 2 * dropout-proportion * Uniform[-1,1]). This might seem like a strange choice, but it means that dropout-proportion=0.5 gives us a kind of 'extremal' case where the dropout scales are distributed as Uniform[0, 2] and we can pass in the dropout scale as if it were a conventional dropout scale.
time-period=0 This determines how the dropout mask interacts with the time index (t). In all cases, different sequences (different 'n' values) get different dropout masks. If time-period==0, then the dropout mask is shared across all time values. If you set time-period > 0, then the dropout mask is shared across blocks of time values: for instance if time-period==10, then we'll use one dropout mask for t values 0 through 9, another for 10 through 19, and so on. In all cases, the dropout mask will be shared across all 'x' values, although in most setups the x values are just zero so this isn't very interesting. If you set time-period==1 it would be similar to regular dropout, and it would probably make more sense to just use the normal DropoutComponent.
specaugment-max-proportion=0 If nonzero, causes this component to implement SpecAugment. (Note: you probably would want this after a batch-norm component so the average at input is zero), and the input dim will be interpreted as some kind of frequency space, e.g. linear or mel. specaugment-max-proportion will be the maximum proportion of the frequency space that this component might zero out (so multiply this by by input dim to get the maximum columns that might be zeroed out); the actual number of columns zeroed out for each sequence will be randomly chosen between zero and the maximum. Note: the non-zeroed frequencies won't be multiplied by a constant more than one as we would in the normal dropout mode.
specaugment-max-regions=1 This can be set to a value greater than one (e.g., 2) to implement a variant of SpecAugment where instead of zeroing out a single region of the frequency spectrum we zero out a randomly chosen number of regions, from one to this number. The maximum proportion of the frequency spectrum that we remove is unaffected.
Definition at line 875 of file nnet-general-component.h.
Definition at line 1545 of file nnet-general-component.cc.
Referenced by GeneralDropoutComponent::Copy().
GeneralDropoutComponent | ( | const GeneralDropoutComponent & | other | ) |
Definition at line 1552 of file nnet-general-component.cc.
|
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.
[in] | debug_info | The component name, to be printed out in any warning messages. |
[in] | indexes | A 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_value | The matrix that was given as input to the Propagate function. Will be ignored (and may be empty) if Properties()&kBackpropNeedsInput == 0. |
[in] | out_value | The matrix that was output from the Propagate function. Will be ignored (and may be empty) if Properties()&kBackpropNeedsOutput == 0 |
[in] | out_deriv | The derivative at the output of this component. |
[in] | memo | This 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_update | If 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_deriv | The 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 1596 of file nnet-general-component.cc.
References GeneralDropoutComponent::block_dim_, CuMatrixBase< Real >::CopyFromMat(), CuMatrixBase< Real >::Data(), GeneralDropoutComponent::dim_, GeneralDropoutComponent::dropout_proportion_, GeneralDropoutComponentPrecomputedIndexes::indexes, KALDI_ASSERT, CuMatrixBase< Real >::MulRows(), CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), NVTX_RANGE, kaldi::SameDim(), GeneralDropoutComponent::specaugment_max_proportion_, CuMatrixBase< Real >::Stride(), and RandomComponent::test_mode_.
|
virtual |
Copies component (deep copy).
Implements Component.
Definition at line 1699 of file nnet-general-component.cc.
References GeneralDropoutComponent::GeneralDropoutComponent().
|
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 from Component.
Definition at line 907 of file nnet-general-component.h.
References DistributeComponent::Copy(), DistributeComponent::PrecomputeIndexes(), DistributeComponent::Read(), and DistributeComponent::Write().
Definition at line 1739 of file nnet-general-component.cc.
References CuMatrixBase< Real >::Add(), CuMatrixBase< Real >::ApplyHeaviside(), GeneralDropoutComponent::block_dim_, GeneralDropoutComponent::continuous_, CuMatrixBase< Real >::CopyFromMat(), GeneralDropoutComponent::dropout_proportion_, rnnlm::i, KALDI_ASSERT, kaldi::kUndefined, rnnlm::n, kaldi::RandInt(), RandomComponent::random_generator_, kaldi::RandUniform(), CuMatrixBase< Real >::Scale(), MatrixBase< Real >::Set(), GeneralDropoutComponent::specaugment_max_proportion_, GeneralDropoutComponent::specaugment_max_regions_, kaldi::swap(), and RandomComponent::test_mode_.
Referenced by GeneralDropoutComponent::Propagate().
|
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 1529 of file nnet-general-component.cc.
References DropoutMaskComponent::continuous_, DropoutMaskComponent::dropout_proportion_, and DropoutMaskComponent::Type().
|
virtual |
Initialize, from a ConfigLine object.
[in] | cfl | A ConfigLine containing any parameters that are needed for initialization. For example: "dim=100 param-stddev=0.1" |
Implements Component.
Definition at line 1703 of file nnet-general-component.cc.
References GeneralDropoutComponent::block_dim_, GeneralDropoutComponent::continuous_, GeneralDropoutComponent::dim_, GeneralDropoutComponent::dropout_proportion_, ConfigLine::GetValue(), KALDI_ASSERT, KALDI_ERR, GeneralDropoutComponent::specaugment_max_proportion_, GeneralDropoutComponent::specaugment_max_regions_, RandomComponent::test_mode_, and GeneralDropoutComponent::time_period_.
|
inlinevirtual |
Returns input-dimension of this component.
Implements Component.
Definition at line 877 of file nnet-general-component.h.
|
private |
|
inlinevirtual |
Returns output-dimension of this component.
Implements Component.
Definition at line 879 of file nnet-general-component.h.
References Component::Info(), and DistributeComponent::InitFromConfig().
|
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.
[in] | misc_info | This 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_indexes | A 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_indexes | A 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_backprop | True 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. |
Reimplemented from Component.
Definition at line 1810 of file nnet-general-component.cc.
References GeneralDropoutComponent::block_dim_, CuArray< T >::CopyFromVec(), GeneralDropoutComponent::dim_, kaldi::DivideRoundingDown(), rnnlm::i, GeneralDropoutComponentPrecomputedIndexes::indexes, rnnlm::j, KALDI_ASSERT, rnnlm::n, GeneralDropoutComponentPrecomputedIndexes::num_mask_rows, and GeneralDropoutComponent::time_period_.
|
virtual |
Propagate function.
[in] | indexes | A 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 | The input to this component. Num-columns == InputDim(). |
[out] | out | The 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. |
Implements Component.
Definition at line 1562 of file nnet-general-component.cc.
References GeneralDropoutComponent::block_dim_, CuMatrixBase< Real >::CopyFromMat(), CuMatrixBase< Real >::Data(), GeneralDropoutComponent::dim_, GeneralDropoutComponent::dropout_proportion_, GeneralDropoutComponent::GetMemo(), GeneralDropoutComponentPrecomputedIndexes::indexes, KALDI_ASSERT, CuMatrixBase< Real >::MulRows(), GeneralDropoutComponentPrecomputedIndexes::num_mask_rows, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), kaldi::SameDim(), GeneralDropoutComponent::specaugment_max_proportion_, CuMatrixBase< Real >::Stride(), and RandomComponent::test_mode_.
|
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 890 of file nnet-general-component.h.
References DistributeComponent::Backprop(), kaldi::nnet3::kBackpropInPlace, kaldi::nnet3::kInputContiguous, kaldi::nnet3::kOutputContiguous, kaldi::nnet3::kPropagateInPlace, kaldi::nnet3::kRandomComponent, kaldi::nnet3::kUsesMemo, and DistributeComponent::Propagate().
|
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 1636 of file nnet-general-component.cc.
References GeneralDropoutComponent::block_dim_, GeneralDropoutComponent::continuous_, GeneralDropoutComponent::dim_, GeneralDropoutComponent::dropout_proportion_, kaldi::ExpectOneOrTwoTokens(), kaldi::nnet3::ExpectToken(), kaldi::PeekToken(), kaldi::ReadBasicType(), GeneralDropoutComponent::specaugment_max_proportion_, GeneralDropoutComponent::specaugment_max_regions_, RandomComponent::test_mode_, and GeneralDropoutComponent::time_period_.
|
inline |
Definition at line 922 of file nnet-general-component.h.
Referenced by kaldi::nnet3::ReadEditConfig(), and kaldi::nnet3::SetDropoutProportion().
|
inlinevirtual |
Returns a string such as "SigmoidComponent", describing the type of the object.
Implements Component.
Definition at line 889 of file nnet-general-component.h.
Referenced by SpecAugmentTimeMaskComponent::Info().
|
virtual |
Write component to stream.
Implements Component.
Definition at line 1674 of file nnet-general-component.cc.
References GeneralDropoutComponent::block_dim_, GeneralDropoutComponent::continuous_, GeneralDropoutComponent::dim_, GeneralDropoutComponent::dropout_proportion_, GeneralDropoutComponent::specaugment_max_proportion_, GeneralDropoutComponent::specaugment_max_regions_, RandomComponent::test_mode_, GeneralDropoutComponent::time_period_, kaldi::WriteBasicType(), and kaldi::WriteToken().
|
private |
Definition at line 937 of file nnet-general-component.h.
Referenced by GeneralDropoutComponent::Backprop(), GeneralDropoutComponent::GetMemo(), GeneralDropoutComponent::InitFromConfig(), GeneralDropoutComponent::PrecomputeIndexes(), GeneralDropoutComponent::Propagate(), GeneralDropoutComponent::Read(), and GeneralDropoutComponent::Write().
|
private |
Definition at line 951 of file nnet-general-component.h.
Referenced by GeneralDropoutComponent::GetMemo(), GeneralDropoutComponent::InitFromConfig(), GeneralDropoutComponent::Read(), and GeneralDropoutComponent::Write().
|
private |
Definition at line 934 of file nnet-general-component.h.
Referenced by GeneralDropoutComponent::Backprop(), SpecAugmentTimeMaskComponent::Info(), GeneralDropoutComponent::InitFromConfig(), GeneralDropoutComponent::PrecomputeIndexes(), GeneralDropoutComponent::Propagate(), GeneralDropoutComponent::Read(), and GeneralDropoutComponent::Write().
|
private |
Definition at line 945 of file nnet-general-component.h.
Referenced by GeneralDropoutComponent::Backprop(), GeneralDropoutComponent::GetMemo(), GeneralDropoutComponent::InitFromConfig(), GeneralDropoutComponent::Propagate(), GeneralDropoutComponent::Read(), and GeneralDropoutComponent::Write().
|
private |
Definition at line 947 of file nnet-general-component.h.
Referenced by GeneralDropoutComponent::Backprop(), GeneralDropoutComponent::GetMemo(), GeneralDropoutComponent::InitFromConfig(), GeneralDropoutComponent::Propagate(), GeneralDropoutComponent::Read(), and GeneralDropoutComponent::Write().
|
private |
Definition at line 949 of file nnet-general-component.h.
Referenced by GeneralDropoutComponent::GetMemo(), GeneralDropoutComponent::InitFromConfig(), GeneralDropoutComponent::Read(), and GeneralDropoutComponent::Write().
|
private |
Definition at line 943 of file nnet-general-component.h.
Referenced by GeneralDropoutComponent::InitFromConfig(), GeneralDropoutComponent::PrecomputeIndexes(), GeneralDropoutComponent::Read(), and GeneralDropoutComponent::Write().