49 std::vector<T> hyp_h(dim), ref_h(dim);
57 (*correct)(ref_h[
i]) += w(
i) * (hyp_h[
i] == ref_h[
i] ? 1.0 : 0.0);
97 diff->
AddMat(-1.0, targets);
138 double progress_value =
144 double elapsed_hours = time_now / 3600;
150 << static_cast<int>(
frames_.
Sum()/100/3600) <<
"h]: " 151 << progress_value <<
" (Xent)" 153 << std::setprecision(3)
154 <<
", elapsed " << elapsed_hours <<
"h";
185 std::ostringstream oss;
186 oss <<
"AvgLoss: " << loss_value <<
" (Xent), " 191 oss <<
"progress: [";
193 std::ostream_iterator<float>(oss,
" "));
194 oss <<
"]" << std::endl;
197 oss <<
"FRAME_ACCURACY >> " << frame_accuracy <<
"% <<" << std::endl;
204 std::ostringstream oss;
205 oss <<
"PER-CLASS PERFORMANCE:" << std::endl;
206 oss <<
"@@@ Frames per-class:" <<
frames_;
215 oss <<
"@@@ Loss per-class:" << loss;
219 frm_accu.
Scale(100.0);
220 oss <<
"@@@ Frame-accuracy per-class:" << frm_accu;
241 int32 num_frames = frame_weights.
Sum();
249 diff->
AddMat(-1.0, target);
256 double mean_square_error = 0.5 * diff_pow_2_.Sum();
261 loss_ += mean_square_error;
267 loss_progress_ += mean_square_error;
271 << static_cast<int>(
frames_/100/3600) <<
"h]: " 277 loss_progress_ = 0.0;
288 num_nn_outputs = net_out.
NumCols();
301 int32 num_tgt = diff_pow_2_.NumCols();
304 std::ostringstream oss;
305 oss <<
"AvgLoss: " << loss_/
frames_ <<
" (Mse), " 306 <<
"[RMS " << root_mean_square <<
", frames " 307 <<
frames_ <<
"]" << std::endl;
308 oss <<
"progress: [";
310 std::ostream_iterator<float>(oss,
" "));
311 oss <<
"]" << std::endl;
319 std::vector<std::string> v;
326 std::vector<std::string>::iterator it(v.begin()+1);
327 for ( ; it != v.end(); ++it) {
331 }
else if (*it ==
"mse") {
334 KALDI_ERR <<
"Unknown objective function code : " << *it;
340 KALDI_ERR <<
"Cannot convert 'dim' " << *it <<
" to integer!";
342 loss_dim_.push_back(dim);
347 KALDI_ERR <<
"Cannot convert 'weight' " << *it <<
" to integer!";
350 loss_weights_.push_back(weight);
354 loss_dim_offset_.resize(loss_dim_.size()+1, 0);
355 for (
int32 i = 1;
i <= loss_dim_.size();
i++) {
356 loss_dim_offset_[
i] = loss_dim_offset_[
i-1] + loss_dim_[
i-1];
370 num_output = net_out.
NumCols();
378 diff->
Resize(num_frames, num_output);
383 std::vector<Vector<BaseFloat> > frmwei_have_tgt;
388 int32 loss_beg = loss_dim_offset_[l];
389 int32 loss_end = loss_dim_offset_[l+1];
390 for (
int32 f = 0; f < num_frames; f++) {
391 bool tgt_defined =
false;
392 for (
int32 p = 0; p < post[f].size(); p++) {
393 if (post[f][p].first >= loss_beg && post[f][p].first < loss_end) {
399 frmwei_have_tgt[l](f) = 0.0;
408 net_out.
ColRange(loss_dim_offset_[l], loss_dim_[l]),
409 tgt_mat_.ColRange(loss_dim_offset_[l], loss_dim_[l]),
412 diff_aux.Scale(loss_weights_[l]);
414 diff->
ColRange(loss_dim_offset_[l], loss_dim_[l]).CopyFromMat(diff_aux);
422 std::vector<BaseFloat> loss_values;
428 std::ostringstream oss;
429 oss <<
"MultiTaskLoss, with " <<
loss_vec_.size()
430 <<
" parallel loss functions." << std::endl;
433 oss <<
"Loss " <<
i+1 <<
", " <<
loss_vec_[
i]->Report() << std::endl;
437 oss <<
"Loss (OVERALL), " 438 <<
"AvgLoss: " << overall_loss <<
" (MultiTaskLoss), " 439 <<
"weights " << loss_weights_ <<
", " 440 <<
"values " << loss_values << std::endl;
450 KALDI_WARN <<
"Loss " <<
i+1 <<
", has bad objective function value '" 451 << val <<
"', using 0.0 instead.";
void MulElements(const CuVectorBase< Real > &v)
double xentropy_progress_
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
bool ConvertStringToInteger(const std::string &str, Int *out)
Converts a string into an integer via strtoll and returns false if there was any kind of problem (i...
BaseFloat AvgLoss()
Get loss value (frame average),.
CuVector< double > frames_
std::string Report()
Generate string with error report.
void CopyToVec(std::vector< T > *dst) const
This function resizes *dst if needed.
CuMatrix< BaseFloat > frames_aux_
CuVector< BaseFloat > target_sum_
#define KALDI_ISFINITE(x)
std::vector< float > loss_vec_
CuVector< double > xentropy_
void AddMat(Real alpha, const CuMatrixBase< Real > &A, MatrixTransposeType trans=kNoTrans)
*this += alpha * A
This class represents a matrix that's stored on the GPU if we have one, and in memory if not...
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
void PosteriorToMatrix(const Posterior &post, const int32 post_dim, CuMatrix< Real > *mat)
Wrapper of PosteriorToMatrix with CuMatrix argument.
CuMatrix< BaseFloat > tgt_mat_
CuMatrix< BaseFloat > entropy_aux_
CuArray< int32 > max_id_out_
void CountCorrectFramesWeighted(const CuArray< T > &hyp, const CuArray< T > &ref, const CuVectorBase< BaseFloat > &weights, Vector< double > *correct)
Helper function of Xent::Eval, calculates number of matching elemente in 'hyp', 'ref' weighted by 'we...
Vector< double > correct_
std::string Report()
Generate string with error report.
BaseFloat AvgLoss()
Get loss value (frame average),.
std::vector< std::vector< std::pair< int32, BaseFloat > > > Posterior
Posterior is a typedef for storing acoustic-state (actually, transition-id) posteriors over an uttera...
void Eval(const VectorBase< BaseFloat > &frame_weights, const CuMatrixBase< BaseFloat > &net_out, const CuMatrixBase< BaseFloat > &target, CuMatrix< BaseFloat > *diff)
Evaluate mean square error using target-matrix,.
int32 loss_report_frames
Report loss value every 'report_interval' frames,.
CuVector< double > entropy_
void Eval(const VectorBase< BaseFloat > &frame_weights, const CuMatrixBase< BaseFloat > &net_out, const CuMatrixBase< BaseFloat > &target, CuMatrix< BaseFloat > *diff)
Evaluate cross entropy using target-matrix (supports soft labels),.
void SplitStringToVector(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< std::string > *out)
Split a string using any of the single character delimiters.
void MulElements(const CuMatrixBase< Real > &A)
Multiply two matrices elementwise: C = C .* A.
CuVector< BaseFloat > frame_weights_
std::string Report()
Generate string with error report,.
void Eval(const VectorBase< BaseFloat > &frame_weights, const CuMatrixBase< BaseFloat > &net_out, const CuMatrixBase< BaseFloat > &target, CuMatrix< BaseFloat > *diff)
Evaluate mean square error using target-matrix,.
void Resize(MatrixIndexT dim, MatrixResizeType t=kSetZero)
Allocate the memory.
bool ConvertStringToReal(const std::string &str, T *out)
ConvertStringToReal converts a string into either float or double and returns false if there was any ...
void ApplyPow(Real power)
MatrixIndexT Dim() const
Returns the dimension of the vector.
Real Sum() const
Returns sum of the elements.
CuMatrix< BaseFloat > xentropy_aux_
void FindRowMaxId(CuArray< int32 > *id) const
Find the id of the maximal element for each row (resizes the 'id' array to the appropriate size)...
void AddVec(Real alpha, const CuVectorBase< Real > &vec, Real beta=1.0)
CuSubMatrix< Real > ColRange(const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
Matrix for CUDA computing.
MatrixIndexT NumCols() const
CuArray< int32 > max_id_tgt_
Class CuArray represents a vector of an integer or struct of type T.
#define KALDI_ASSERT(cond)
std::string ReportPerClass()
Generate string with per-class error report,.
MatrixIndexT NumRows() const
Dimensions.
Provides a vector abstraction class.
MatrixIndexT Dim() const
Return the vector dimension.
double Elapsed() const
Returns time in seconds.
void CopyToVec(VectorBase< OtherReal > *dst) const
void MulRowsVec(const CuVectorBase< Real > &scale)
scale i'th row by scale[i]
void Resize(MatrixIndexT rows, MatrixIndexT cols, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Allocate the memory.
void InitFromString(const std::string &s)
Initialize from string, the format for string 's' is : 'multitask,<type1>,<dim1>,<weight1>,...,<typeN>,<dimN>,<weightN>'.
void AddRowSumMat(Real alpha, const CuMatrixBase< Real > &mat, Real beta=1.0)
Sum the rows of the matrix, add to vector.
MatrixIndexT Dim() const
Dimensions.
Vector for CUDA computing.