29 const std::vector<NnetExample> &examples,
37 void FormatInput(
const std::vector<NnetExample> &data,
60 KALDI_ASSERT(data[0].input_frames.NumRows() == num_splice);
62 int32 feat_dim = data[0].input_frames.NumCols(),
63 spk_dim = data[0].spk_info.Dim(),
64 tot_dim = feat_dim + spk_dim;
67 int32 num_chunks = data.size();
69 input->
Resize(num_splice * num_chunks,
71 for (
int32 chunk = 0; chunk < num_chunks; chunk++) {
73 chunk * num_splice, num_splice,
79 chunk * num_splice, num_splice,
106 KALDI_ERR <<
"This type of nonlinear component is not handled: index " << c;
112 else if (c == last_c)
130 KALDI_ERR <<
"This type of nonlinear component is not handled: index " << c;
144 int32 num_iters = 10;
147 ones(rows, cols), in_deriv(rows, cols);
150 nc.
Propagate(in_info, out_info, cur_data, next_data);
151 nc.
Backprop(in_info, out_info, cur_data, *next_data, ones, NULL, &in_deriv);
153 cur_avg_deriv = in_deriv.
Sum() / (rows * cols);
154 orig_avg_deriv = cur_avg_deriv;
155 for (
int32 iter = 0; iter < num_iters; iter++) {
158 cur_data.CopyFromMat(*cur_data_in);
160 nc.
Propagate(in_info, out_info, cur_data, next_data);
161 nc.
Backprop(in_info, out_info, cur_data, *next_data, ones, NULL, &in_deriv);
162 BaseFloat next_avg_deriv = in_deriv.
Sum() / (rows * cols);
168 BaseFloat proposed_change = (target_avg_deriv - cur_avg_deriv) / gradient;
169 KALDI_VLOG(2) <<
"cur_avg_deriv = " << cur_avg_deriv <<
", target_avg_deriv = " 170 << target_avg_deriv <<
", gradient = " << gradient
171 <<
", proposed_change " << proposed_change;
175 (proposed_change > 0.0 ? 1.0 : -1.0);
176 cur_scaling += proposed_change;
178 cur_data.CopyFromMat(*cur_data_in);
179 cur_data.Scale(cur_scaling);
180 nc.
Propagate(in_info, out_info, cur_data, next_data);
181 nc.
Backprop(in_info, out_info, cur_data, *next_data, ones, NULL, &in_deriv);
182 cur_avg_deriv = in_deriv.
Sum() / (rows * cols);
189 uc->
Scale(cur_scaling);
192 KALDI_LOG <<
"For component " << c <<
", scaling parameters by " 193 << cur_scaling <<
"; average " 194 <<
"derivative changed from " << orig_avg_deriv <<
" to " 195 << cur_avg_deriv <<
"; target was " << target_avg_deriv;
214 cur_data.
Swap(&next_data);
219 const std::vector<NnetExample> &examples,
void CopyFromMat(const MatrixBase< OtherReal > &src, MatrixTransposeType trans=kNoTrans)
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
const Component & GetComponent(int32 c) const
int32 LeftContext() const
Returns the left-context summed over all the Components...
This kind of Component is a base-class for things like sigmoid and softmax.
const std::vector< NnetExample > & examples_
void RescaleComponent(int32 c, int32 num_chunks, CuMatrixBase< BaseFloat > *cur_data_in, CuMatrix< BaseFloat > *next_data)
virtual void Scale(BaseFloat scale)=0
This new virtual function scales the parameters by this amount.
Abstract class, basic element of the network, it is a box with defined inputs, outputs, and tranformation functions interface.
void FormatInput(const std::vector< NnetExample > &data, CuMatrix< BaseFloat > *input)
takes the input and formats as a single matrix, in forward_data_[0].
This class represents a matrix that's stored on the GPU if we have one, and in memory if not...
void CopyRowsFromVec(const CuVectorBase< Real > &v)
This function has two modes of operation.
void RescaleNnet(const NnetRescaleConfig &rescale_config, const std::vector< NnetExample > &examples, Nnet *nnet)
int32 NumComponents() const
Returns number of components– think of this as similar to # of layers, but e.g.
BaseFloat GetTargetAvgDeriv(int32 c)
void Swap(Matrix< Real > *mat)
NnetRescaler(const NnetRescaleConfig &config, const std::vector< NnetExample > &examples, Nnet *nnet)
int32 RightContext() const
Returns the right-context summed over all the Components...
const NnetRescaleConfig & config_
ChunkInfo is a class whose purpose is to describe the structure of matrices holding features...
std::vector< ChunkInfo > chunk_info_out_
BaseFloat target_last_layer_avg_deriv
virtual void Backprop(const ChunkInfo &in_info, const ChunkInfo &out_info, const CuMatrixBase< BaseFloat > &in_value, const CuMatrixBase< BaseFloat > &out_value, const CuMatrixBase< BaseFloat > &out_deriv, Component *to_update, CuMatrix< BaseFloat > *in_deriv) const =0
Perform backward pass propagation of the derivative, and also either update the model (if to_update =...
This class is used for a piece of a CuMatrix.
Matrix for CUDA computing.
MatrixIndexT NumCols() const
virtual void Propagate(const ChunkInfo &in_info, const ChunkInfo &out_info, const CuMatrixBase< BaseFloat > &in, CuMatrixBase< BaseFloat > *out) const =0
Perform forward pass propagation Input->Output.
BaseFloat target_avg_deriv
#define KALDI_ASSERT(cond)
void ComputeRelevantIndexes()
BaseFloat target_first_layer_avg_deriv
MatrixIndexT NumRows() const
Dimensions.
void ComputeChunkInfo(int32 input_chunk_size, int32 num_chunks, std::vector< ChunkInfo > *chunk_info_out) const
Uses the output of the Context() functions of the network, to compute a vector of size NumComponents(...
void Resize(MatrixIndexT rows, MatrixIndexT cols, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Allocate the memory.
std::set< int32 > relevant_indexes_
Class UpdatableComponent is a Component which has trainable parameters and contains some global param...
int32 InputDim() const
Dimension of the input features, e.g.