22 #ifndef KALDI_NNET3_NNET_COMPONENT_ITF_H_ 23 #define KALDI_NNET3_NNET_COMPONENT_ITF_H_ 100 virtual void Write(std::ostream &os,
bool binary)
const = 0;
101 virtual void Read(std::istream &os,
bool binary) = 0;
102 virtual std::string
Type()
const = 0;
106 const std::string &cpi_type);
164 virtual void Backprop(
const std::string &debug_info,
219 const Index &output_index,
220 std::vector<Index> *desired_indexes)
const;
250 const Index &output_index,
252 std::vector<Index> *used_inputs)
const;
273 std::vector<Index> *output_indexes)
const {}
304 const std::vector<Index> &input_indexes,
305 const std::vector<Index> &output_indexes,
306 bool need_backprop)
const {
return NULL; }
311 virtual std::string
Type()
const = 0;
317 virtual void InitFromConfig(
ConfigLine *cfl) = 0;
320 virtual int32 InputDim()
const = 0;
323 virtual int32 OutputDim()
const = 0;
328 virtual int32 Properties()
const = 0;
338 static Component *NewComponentOfType(
const std::string &type);
343 virtual void Read(std::istream &is,
bool binary) = 0;
346 virtual void Write(std::ostream &os,
bool binary)
const = 0;
351 virtual std::string Info()
const;
420 test_mode_(other.test_mode_) {}
462 l2_regularize_(0.0), is_gradient_(false),
479 learning_rate_ = lrate * learning_rate_factor_;
493 learning_rate_factor_ = lrate_factor;
526 virtual std::string Info()
const;
544 void InitLearningRatesFromConfig(
ConfigLine *cfl);
552 std::string ReadUpdatableCommon(std::istream &is,
bool binary);
557 void WriteUpdatableCommon(std::ostream &is,
bool binary)
const;
628 virtual void Read(std::istream &is,
bool binary);
630 virtual void ZeroStats();
632 virtual std::string Info()
const;
635 virtual void Write(std::ostream &os,
bool binary)
const;
647 double Count()
const {
return count_; }
650 enum { kUnsetThreshold = -1000 };
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
CuVector< double > oderiv_sumsq_
BaseFloat self_repair_scale_
virtual void Read(std::istream &os, bool binary)=0
void SetTestMode(bool test_mode)
Abstract base-class for neural-net components.
An abstract representation of a set of Indexes.
virtual int32 NumParameters() const
The following new virtual function returns the total dimension of the parameters in this class...
virtual ~ComponentPrecomputedIndexes()
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.
#define KALDI_DISALLOW_COPY_AND_ASSIGN(type)
virtual int32 OutputDim() const
Returns output-dimension of this component.
CuVector< double > deriv_sum_
virtual void DeleteMemo(void *memo) const
This virtual function only needs to be overwritten by Components that return a non-NULL memo from the...
virtual void Vectorize(VectorBase< BaseFloat > *params) const
Turns the parameters into vector form.
virtual ComponentPrecomputedIndexes * Copy() const =0
struct Index is intended to represent the various indexes by which we number the rows of the matrices...
virtual int32 InputDim() const
Returns input-dimension of this component.
RandomComponent(const RandomComponent &other)
virtual void Scale(BaseFloat scale)
This virtual function when called on – an UpdatableComponent scales the parameters by "scale" when c...
virtual BaseFloat LearningRateFactor()
virtual void FreezeNaturalGradient(bool freeze)
freezes/unfreezes NaturalGradient updates, if applicable (to be overriden by components that use Natu...
BaseFloat MaxChange() const
Returns the per-component max-change value, which is interpreted as the maximum change (in l2 norm) i...
virtual void ZeroStats()
Components that provide an implementation of StoreStats should also provide an implementation of Zero...
BaseFloat L2Regularization() const
Returns the l2 regularization constant, which may be set in any updatable component (usually from the...
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...
virtual void ReorderIndexes(std::vector< Index > *input_indexes, std::vector< Index > *output_indexes) const
This function only does something interesting for non-simple Components.
double num_dims_self_repaired_
void SetL2Regularization(BaseFloat a)
BaseFloat learning_rate_
learning rate (typically 0.0..0.01)
virtual void Write(std::ostream &os, bool binary) const =0
CuVector< double > value_sum_
const CuVector< double > & ValueSum() const
BaseFloat learning_rate_factor_
learning rate factor (normally 1.0, but can be set to another < value so that when < you call SetLear...
virtual void SetActualLearningRate(BaseFloat lrate)
Sets the learning rate directly, bypassing learning_rate_factor_.
BaseFloat DotProduct(const Nnet &nnet1, const Nnet &nnet2)
Returns dot product between two networks of the same structure (calls the DotProduct functions of the...
virtual ~UpdatableComponent()
BaseFloat self_repair_lower_threshold_
virtual void SetAsGradient()
Sets is_gradient_ to true and sets learning_rate_ to 1, ignoring learning_rate_factor_.
Class UpdatableComponent is a Component which has trainable parameters; it extends the interface of C...
static ComponentPrecomputedIndexes * ReadNew(std::istream &is, bool binary)
virtual void SetLearningRateFactor(BaseFloat lrate_factor)
BaseFloat self_repair_upper_threshold_
Matrix for CUDA computing.
virtual std::string Type() const =0
void ConsolidateMemory(Nnet *nnet)
This just calls ConsolidateMemory() on all the components of the nnet.
virtual void UnVectorize(const VectorBase< BaseFloat > ¶ms)
Converts the parameters from vector form.
double num_dims_processed_
This class is responsible for parsing input like hi-there xx=yyy a=b c empty= f-oo=Append(bar, sss) ba_z=123 bing='a b c' baz="a b c d='a b' e" and giving you access to the fields, in this case.
#define KALDI_ASSERT(cond)
virtual void ConsolidateMemory()
This virtual function relates to memory management, and avoiding fragmentation.
void PerturbParams(BaseFloat stddev, Nnet *nnet)
Calls PerturbParams (with the given stddev) on all updatable components of the nnet.
const CuVector< double > & DerivSum() const
void SetMaxChange(BaseFloat max_change)
Provides a vector abstraction class.
virtual void SetUnderlyingLearningRate(BaseFloat lrate)
Sets the learning rate of gradient descent- gets multiplied by learning_rate_factor_.
virtual void Add(BaseFloat alpha, const Component &other)
This virtual function when called by – an UpdatableComponent adds the parameters of another updatabl...
static ComponentPrecomputedIndexes * NewComponentPrecomputedIndexesOfType(const std::string &cpi_type)
CuRand< BaseFloat > random_generator_
BaseFloat LearningRate() const
Gets the learning rate to be used in gradient descent.