40 Nnet *nnet_to_update = NULL);
67 Nnet *nnet_to_update):
71 KALDI_ERR <<
"Feature dimension is " << dim <<
" but network expects " 79 int32 num_rows = left_context + input_feats.
NumRows() + right_context;
83 input.
Resize(num_rows, dim);
85 0, dim).CopyFromMat(input_feats);
86 for (
int32 i = 0;
i < left_context;
i++)
87 input.
Row(
i).CopyFromVec(input_feats.
Row(0));
89 for (
int32 i = 0;
i < right_context;
i++)
90 input.
Row(num_rows -
i - 1).CopyFromVec(input_feats.
Row(last_row));
103 keep_last_output = will_do_backprop &&
106 if (!keep_last_output)
116 double tot_objf = 0.0, tot_weight = 0.0;
119 num_pdfs = last_layer_output.
NumCols();
120 KALDI_ASSERT(pdf_post.size() ==
static_cast<size_t>(num_frames));
121 deriv->
Resize(num_frames, num_pdfs);
123 for (
size_t j = 0;
j < pdf_post[
i].size();
j++) {
124 int32 label = pdf_post[
i][
j].first;
127 BaseFloat this_prob = last_layer_output(
i, label);
129 tot_objf += weight *
Log(this_prob);
130 tot_weight += weight;
131 (*deriv)(
i, label) += weight / this_prob;
135 KALDI_VLOG(4) <<
"Objective function is " << (tot_objf/tot_weight) <<
136 " per frame over " << tot_weight <<
" samples.";
152 &output_deriv = *tmp_deriv;
155 component_to_update, &input_deriv);
156 *tmp_deriv = input_deriv;
164 NnetComputer nnet_computer(nnet, input, pad_input, NULL);
179 num_rows = left_context + input.
NumRows() + right_context;
180 full_input.
Resize(num_rows, dim);
182 0, dim).CopyFromMat(input);
183 for (
int32 i = 0;
i < left_context;
i++)
184 full_input.
Row(
i).CopyFromVec(input.
Row(0));
186 for (
int32 i = 0;
i < right_context;
i++)
187 full_input.
Row(num_rows -
i - 1).CopyFromVec(input.
Row(last_row));
189 for (
int32 i = 0;
i < num_chunks;
i++) {
190 int32 index =
i * chunk_size,
191 offset = std::min(num_rows - chunk_size *
i,
192 left_context + chunk_size + right_context);
198 NnetComputer nnet_computer(nnet, cu_chunk_input,
false, NULL);
203 cu_chunk_output.NumCols());
212 Nnet *nnet_to_update) {
213 NnetComputer nnet_computer(nnet, input, pad_input, nnet_to_update);
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...
void Backprop(CuMatrix< BaseFloat > *tmp_deriv)
const CuSubVector< Real > Row(MatrixIndexT i) const
Abstract class, basic element of the network, it is a box with defined inputs, outputs, and tranformation functions interface.
virtual bool BackpropNeedsInput() const
CuSubMatrix< Real > Range(const MatrixIndexT row_offset, const MatrixIndexT num_rows, const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
void NnetComputationChunked(const Nnet &nnet, const CuMatrixBase< BaseFloat > &input, int32 chunk_size, CuMatrixBase< BaseFloat > *output)
Does the basic neural net computation, on a sequence of data (e.g.
std::vector< CuMatrix< BaseFloat > > forward_data_
This class represents a matrix that's stored on the GPU if we have one, and in memory if not...
void NnetComputation(const Nnet &nnet, const CuMatrixBase< BaseFloat > &input, bool pad_input, CuMatrixBase< BaseFloat > *output)
Does the basic neural net computation, on a sequence of data (e.g.
int32 NumComponents() const
Returns number of components– think of this as similar to # of layers, but e.g.
std::vector< std::vector< std::pair< int32, BaseFloat > > > Posterior
Posterior is a typedef for storing acoustic-state (actually, transition-id) posteriors over an uttera...
BaseFloat NnetGradientComputation(const Nnet &nnet, const CuMatrixBase< BaseFloat > &input, bool pad_input, const Posterior &pdf_post, Nnet *nnet_to_update)
int32 RightContext() const
Returns the right-context summed over all the Components...
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 =...
NnetComputer(const Nnet &nnet, const CuMatrixBase< BaseFloat > &input_feats, bool pad, Nnet *nnet_to_update=NULL)
This class is used for a piece of a CuMatrix.
void Propagate()
The forward-through-the-layers part of the computation.
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.
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Dimensions.
BaseFloat ComputeLastLayerDeriv(const Posterior &pdf_post, CuMatrix< BaseFloat > *deriv) const
Computes objf derivative at last layer, and returns objective function summed over labels and multipl...
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(...
virtual bool BackpropNeedsOutput() const
void Resize(MatrixIndexT rows, MatrixIndexT cols, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Allocate the memory.
int32 InputDim() const
Dimension of the input features, e.g.
std::vector< ChunkInfo > chunk_info_
CuMatrixBase< BaseFloat > & GetOutput()