📄 approx_cont_mgau.c
字号:
/* ==================================================================== * Copyright (c) 1999-2004 Carnegie Mellon University. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * This work was supported in part by funding from the Defense Advanced * Research Projects Agency and the National Science Foundation of the * United States of America, and the CMU Sphinx Speech Consortium. * * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ==================================================================== * *//* * approx_cont_mgau.c * * ********************************************** * CMU ARPA Speech Project * * Copyright (c) 2003 Carnegie Mellon University. * ALL RIGHTS RESERVED. * ********************************************** * * HISTORY * * 23-Jan-2004 Arthur Chan (archan@cs.cmu.edu) * started */#include "approx_cont_mgau.h"#include "s3types.h"#include "gs.h"#include "mdef.h"#include <stdlib.h> int32 most_recent_best_cid=-1;#define DEBUG_GSCORE 1 /** \file approx_cont_mgau.c * \brief Implementation detail of approx_cont_mgau \warning You need to have some knowledge in fast GMM computation in order to modifed this function. *//** Decide whether this frame should be skip or not. */int32 approx_isskip(int32 frame, fast_gmm_t* fg, int32 best_cid){ int32 ds_ratio; int32 cond_ds; int32 dist_ds; int32 isSameBestIdx; int32 *skip_count; ds_ratio=fg->downs->ds_ratio; cond_ds=fg->downs->cond_ds; dist_ds=fg->downs->dist_ds; isSameBestIdx=(fg->gaus->rec_bstcid==best_cid); skip_count=&(fg->downs->skip_count); assert(fg->downs->ds_ratio!=0); assert(!(cond_ds>0 && dist_ds>0)); /*Consider cond_ds first if specified*/ if(cond_ds>0) { if(isSameBestIdx){ if(*skip_count<ds_ratio-1){ *skip_count++; return 1; }else{ *skip_count=0; return 0; } } else return 0; } if(dist_ds>0){ } /*Consider the effect of ds_ratio*/ if(frame%ds_ratio==0) return 0; else return 1;}/** Update the senone score given index, return the number of gaussians compute, This took care of Gaussian level of optimization. This will called Feature Level Optimization routine Gaussian Level: ^^^^^^^^^^^^^^^ Shortlist of Gaussians was determined using Gaussian-Selection (Bochierri 93) in gs_mgau_shortlist or Sub-VQ-based Gaussian Selection (Ravi 98) in subvq_mgau_shortlist. Note that the term "shortlist" was also used in (P. Douglas 99) which is basically are variant of (Bochierri 93) with a clever scheme which resolves the back-off problem. We have plans to further enhance schemes of Gaussian Selection by combining them using machine learning techniques. Feature Component Level: ^^^^^^^^^^^^^^^^^^^^^^^^ SVQ is used for feature level optimization only if svq4svq is set to 1. This use the sum of sub-vector scores will be used as the gaussian scores. Safe Guarding abnomal scores: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ We discover that even using our Gaussian Selection routine, the code can break because of some gaussian score is extremely low, we tried to detect them and avoid them by asserting the score and checked them at the end of a routines. */int32 approx_mgau_eval (gs_t* gs, subvq_t* svq, mgau_model_t* g, fast_gmm_t * fastgmm, int32 s, /*senone index*/ int32 *senscr, float32 *feat, int32 best_cid, int32 svq_beam ) { int32 ng=0; int32 *mgau_sl;#if _DEBUG_GSCORE_ int32 i;#endif if(gs&&fastgmm->gs4gs){ /* If GS is used, make sure best_cid > 0*/ assert(best_cid>0); ng = gs_mgau_shortlist (gs, s, mgau_n_comp(g,s),feat,best_cid); mgau_sl=gs->mgau_sl; }else if (svq){ ng = subvq_mgau_shortlist (svq, s, mgau_n_comp(g,s), svq_beam); mgau_sl=svq->mgau_sl; }else{ ng = mgau_n_comp (g, s); mgau_sl=NULL; }#if _DEBUG_GSCORE_ for(i=0;i<mgau_veclen(g);i++){ fprintf(stderr,"%f ",feat[i]); } fprintf(stderr,"\n"); fflush(stderr); E_INFO("Full computation: Idx %d using subvq, Senscr %d ng %d\n",s,senscr[s],ng); senscr[s] = mgau_eval (g, s, NULL, feat); E_INFO("Full computationIdx %d using normal, Senscr %d ng %d\n",s,senscr[s],ng); senscr[s] = subvq_mgau_eval(g, svq, s, mgau_n_comp(g,s),mgau_sl); E_INFO("Partial Computation: Idx %d using subvq, Senscr %d ng %d\n",s,senscr[s],ng); senscr[s] = mgau_eval (g, s, mgau_sl, feat); E_INFO("Partial Computation: Idx %d using normal, Senscr %d ng %d\n",s,senscr[s],ng)#endif /* This safe guard the algorithmic error of other 3rd party converter*/ if(ng==0){#if _DEBUG_GSCORE_ E_INFO("short list has 0 element, turn to compute all, please check the Gaussian Selection algorithm\n");#endif mgau_sl=NULL; ng=mgau_n_comp(g,s); } if(svq&&fastgmm->svq4svq) senscr[s] = subvq_mgau_eval(g, svq, s, mgau_n_comp(g,s),mgau_sl); else senscr[s] = mgau_eval (g, s, mgau_sl, feat); /*This routine safe guard the computation such that no abnomality will occur */ if(senscr[s] < S3_LOGPROB_ZERO+100000){ /* a range of value which recomputation is necessary , 100000 is a magic number tuned by using the Communicator, WSK5k and ICSI tasks. It is a reasonable magic :-) */ if(mgau_sl==NULL){#if _DEBUG_GSCORE_ E_INFO("WARNING!! Score is S3_LOGPROB_ZERO even computing full gaussians! %d\n",s);#endif } else{ mgau_sl=NULL; ng+=mgau_n_comp(g,s); if(svq&&fastgmm->svq4svq) senscr[s] = subvq_mgau_eval(g, svq, s, mgau_n_comp(g,s),NULL); else senscr[s] = mgau_eval (g, s, NULL, feat); } } return ng;}int32 *ci;int intcmp(const void *v1, const void *v2){ return (ci[*(int32*) v2 ] - ci[*(int32*)v1]);}/** This function compute the dynamic beam using histogram-based CI senone evaluation. This will probably be another paper on speed up. */int32 approx_compute_dyn_ci_pbeam(mdef_t* mdef, fast_gmm_t *fastgmm, mgau_model_t *g, int32* ci_occ, int32* sen_active, int32* cache_ci_senscr, s3senid_t *cd2cisen ){ int s; int32* idx; int32 pbest; int32 total; int32 is_ciphone;
ci=cache_ci_senscr;
idx= fastgmm->gmms->idx; for( s = 0 ; s <g->n_mgau ;s++){ is_ciphone= mdef_is_cisenone(mdef,s);
if(is_ciphone) { /*Initialize the ci_occ in the fast_gmm_struct */ ci_occ[s]=0; }else{ if(!sen_active || sen_active[s]){ ci_occ[cd2cisen[s]]++; } } } for(s=0 ; s< mdef->n_ci_sen ; s++) idx[s]=s; /* ARCHAN: we only have around 200 ci phones so it should be fine for sorting. How about Chinese then? Hmm. We'll think about that later...... */ qsort(idx,mdef->n_ci_sen,sizeof(int32), intcmp); total=0; pbest=cache_ci_senscr[idx[0]]; fastgmm->gmms->dyn_ci_pbeam = fastgmm->gmms->ci_pbeam; for(s=0; s< mdef-> n_ci_sen && cache_ci_senscr[idx[s]] > pbest + fastgmm->gmms->ci_pbeam ;s++){ total+=ci_occ[idx[s]]; if(total > fastgmm->gmms->max_cd){ fastgmm->gmms->dyn_ci_pbeam = cache_ci_senscr[idx[s]] - pbest; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -