26 const std::vector<NnetExample> &validation_set,
32 Nnet nnet_scaled(nnet);
35 Nnet nnet_gradient(nnet);
36 bool is_gradient =
true;
37 nnet_gradient.
SetZero(is_gradient);
40 int32 batch_size = 1024;
46 BaseFloat tot_count = validation_set.size();
55 (*gradient)(
i) = dotprod * scale_params(i);
67 const std::vector<NnetExample> &validation_set,
75 double objf, initial_objf;
80 lbfgs_options.
m = dim;
93 KALDI_VLOG(2) <<
"log-scale = " << log_scale <<
", objf = " << objf
94 <<
", gradient = " << gradient;
95 if (
i == 0) initial_objf = objf;
97 lbfgs.
DoStep(objf, gradient);
100 log_scale.CopyFromVec(lbfgs.
GetValue(&objf));
104 KALDI_LOG <<
"Shrinking nnet, validation objf per frame changed from " 105 << initial_objf <<
" to " << objf <<
", scale factors per layer are " This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
const Component & GetComponent(int32 c) const
void DoStep(Real function_value, const VectorBase< Real > &gradient)
The user calls this function to provide the class with the function and gradient info at the point Ge...
void ApplyExp()
Apply exponential to each value in vector.
int32 NumUpdatableComponents() const
Returns the number of updatable components.
double ComputeNnetGradient(const Nnet &nnet, const std::vector< NnetExample > &validation_set, int32 batch_size, Nnet *gradient)
ComputeNnetGradient is mostly used to compute gradients on validation sets; it divides the example in...
const VectorBase< Real > & GetValue(Real *objf_value=NULL) const
This returns the value of the variable x that has the best objective function so far, and the corresponding objective function value if requested.
int32 NumComponents() const
Returns number of components– think of this as similar to # of layers, but e.g.
Configuration class that controls neural net "shrinkage" which is actually a scaling on the parameter...
void SetZero(bool treat_as_gradient)
virtual BaseFloat DotProduct(const UpdatableComponent &other) const =0
Here, "other" is a component of the same specific type.
void ShrinkNnet(const NnetShrinkConfig &shrink_config, const std::vector< NnetExample > &validation_set, Nnet *nnet)
MatrixIndexT Dim() const
Returns the dimension of the vector.
void ScaleComponents(const VectorBase< BaseFloat > &scales)
Scales the parameters of each of the updatable components.
#define KALDI_ASSERT(cond)
This is an implementation of L-BFGS.
const VectorBase< Real > & GetProposedValue() const
This returns the value at which the function wants us to compute the objective function and gradient...
Class UpdatableComponent is a Component which has trainable parameters and contains some global param...
static BaseFloat ComputeObjfAndGradient(const std::vector< NnetExample > &validation_set, const Vector< double > &scale_params, const Nnet &orig_nnet, const Nnet &direction, Vector< double > *gradient)