backtrellis.c
来自「julius version 4.12.about sound recognit」· C语言 代码 · 共 589 行 · 第 1/2 页
C
589 行
{ LOGPROB maxscore; int i,t; BACKTRELLIS *bt; bt = r->backtrellis; if (bt->num == NULL) return; maxscore = LOG_ZERO; /* find last frame where a word exists */ for(t=bt->framelen-1;t>=0;t--) { if (bt->num[t] > 0) break; } /* get maximum word hypothesis at that frame */ for(i=0;i<bt->num[t];i++) { if (maxscore < (bt->rw[t][i])->backscore) { maxscore = (bt->rw[t][i])->backscore; r->sp_break_2_begin_word = (bt->rw[t][i])->wid; } } maxscore = LOG_ZERO; /* find first frame where a word exists */ for(t=0;t<bt->framelen;t++) { if (bt->num[t] > 0) break; } /* get maximum word hypothesis at that frame */ for(i=0;i<bt->num[t];i++) { if (maxscore < (bt->rw[t][i])->backscore) { maxscore = (bt->rw[t][i])->backscore; r->sp_break_2_end_word = (bt->rw[t][i])->wid; } }#ifdef SP_BREAK_DEBUG jlog("DEBUG: 2nd pass begin word: %s\n", (r->sp_break_2_begin_word == WORD_INVALID) ? "WORD_INVALID" : r->lm->winfo->wname[r->sp_break_2_begin_word]); jlog("DEBUG: 2nd pass end word: %s\n", (r->sp_break_2_end_word == WORD_INVALID) ? "WORD_INVALID" : r->lm->winfo->wname[r->sp_break_2_end_word]);#endif}/* the outprob on the trellis connection point should be discounted *//** * <JA> * 妈1パス姜位稿, 妈2パスでのトレリス浩儡鲁纷换のために· * 链箕粗に畔って称トレリス帽胳の姜眉の呵姜觉轮の叫蜗锑刨を浩纷换し, * それを芜姥から汗し苞いておく. 妈2パスでは·簿棱儡鲁箕には * 儡鲁簿棱を雇胃して儡鲁爬の觉轮の锑刨が浩纷换される. * * @param wchmm [in] 腾菇陇步辑今 * @param bt [in] 帽胳トレリス菇陇挛 * @param param [in] 掐蜗パラメ〖タ攫鼠 * </JA> * <EN> * Discount the output probabilities of the last state from the accumulated * score on word edge for all trellis words survived on the 1st pass, * for the acoustic re-computation on the 2nd pass. * The acousitic likelihood of the word edge state will be re-computed * when the next word hypotheses are expanded on the next 2nd pass. * * @param wchmm [in] tree lexicon * @param bt [in] word trellis structure * @param param [in] input parameter * </EN> * * @callergraph * @callgraph * */voidbt_discount_pescore(WCHMM_INFO *wchmm, BACKTRELLIS *bt, HTK_Param *param){ int t,i; TRELLIS_ATOM *tre; if (bt->num == NULL) return; for (t=0; t<bt->framelen; t++) { for (i=0; i<bt->num[t]; i++) { tre = bt->rw[t][i]; /* On normal version, both language score and the output prob. score at the connection point should removed on the trellis for the later connection. On multi-path mode, removing only the language score is enough. */ tre->backscore -= outprob_style(wchmm, wchmm->wordend[tre->wid], tre->last_tre->wid, t, param); } }}/** * <EN> * Subtract 2-gram scores at each trellis word for the 2nd pass. * </EN> * <JA> * 妈2パスのために2-gramスコアをトレリス惧の帽胳から汗し苞く. * </JA> * * @param bt [in] word trellis * * @callergraph * @callgraph * */voidbt_discount_lm(BACKTRELLIS *bt){ int t,i; TRELLIS_ATOM *tre; if (bt->num == NULL) return; /* the LM score of the last word should be subtracted, because their LM will be assigned by 3-gram on the 2nd pass. */ for (t=0; t<bt->framelen; t++) { for (i=0; i<bt->num[t]; i++) { tre = bt->rw[t][i]; tre->backscore -= tre->lscore; } }}/** * <JA> * bt_sort_rw()脱のqsortコ〖ルバック. * * @param a [in] 妥燎1 * @param b [in] 妥燎2 * * @return 竞界ソ〖トに涩妥な猛 * </JA> * <EN> * qsort callback for bt_sort_rw(). * * @param a [in] first element * @param b [in] second element * * @return a value needed to do upward sort. * </EN> * * */static intcompare_wid(TRELLIS_ATOM **a, TRELLIS_ATOM **b){ if ((*a)->wid > (*b)->wid) return 1; if ((*a)->wid < (*b)->wid) return -1; return 0;}/** * <JA> * bt_relocate_rw() 姜位稿, 光庐アクセスのために * バックトレリス菇陇挛柒のトレリス帽胳をフレ〖ムごとに * 帽胳IDでソ〖トしておく. * * @param bt [i/o] 帽胳トレリス菇陇挛 * * </JA> * <EN> * Sort the trellis words in the backtrellis by the word IDs per each frame, * for rapid access on the 2nd pass. This should be called just after * bt_relocate_rw() was called. * * @param bt [i/o] word trellis structure * * </EN> * @callergraph * @callgraph * */voidbt_sort_rw(BACKTRELLIS *bt){ int t; if (bt->num == NULL) return; for (t=0;t<bt->framelen;t++) { qsort(bt->rw[t], bt->num[t], sizeof(TRELLIS_ATOM *), (int (*)(const void *,const void *))compare_wid); }}/* 笆布の簇眶は祸涟にbt_sort_rw() が钙ばれていること(妈2パス脱) *//* functions below should be called after bt_sort_rw() *//** * <JA> * 帽胳トレリス柒の回年箕癸フレ〖ム惧に·回年帽胳の姜眉があるかどうかを * 浮瑚する. * * @param bt [in] 帽胳トレリス菇陇挛 * @param t [in] 浮瑚する姜眉箕癸∈フレ〖ム∷ * @param wkey [in] 浮瑚する帽胳の帽胳ID * * @return 斧つかった眷圭そのトレリス帽胳へのポインタ·斧つからなければ NULL. * </JA> * <EN> * Search a word on the specified frame in a word trellis data. * * @param bt [in] word trellis structure * @param t [in] word end frame on which to search * @param wkey [in] word ID to search * * @return pointer to the found trellis word, or NULL if not found. * </EN> * * @callergraph * @callgraph * */TRELLIS_ATOM *bt_binsearch_atom(BACKTRELLIS *bt, int t, WORD_ID wkey){ /* do binary search */ /* assume rw are ordered by wid */ int left, right, mid; TRELLIS_ATOM *tmp;#ifdef WPAIR int i; LOGPROB maxscore; TRELLIS_ATOM *maxtre;#endif if (bt->num[t] == 0) return(NULL); left = 0; right = bt->num[t] - 1; while (left < right) { mid = (left + right) / 2; if ((bt->rw[t][mid])->wid < wkey) { left = mid + 1; } else { right = mid; } } tmp = bt->rw[t][left]; if (tmp->wid == wkey) {#ifdef WPAIR /* same word with different context will be found: most likely one will be returned */ maxscore = LOG_ZERO; maxtre = NULL; i = left; while (i >= 0) { tmp = bt->rw[t][i]; if (tmp->wid != wkey) break;#ifdef WORD_GRAPH /* only words on a graph path should be counted */ if (!tmp->within_wordgraph) { i--; continue; }#endif if (maxscore < tmp->backscore) { maxscore = tmp->backscore; maxtre = tmp; } i--; } i = left; while (i < bt->num[t]) { tmp = bt->rw[t][i]; if (tmp->wid != wkey) break;#ifdef WORD_GRAPH /* only words on a graph path should be counted */ if (!tmp->within_wordgraph) { i++; continue; }#endif if (maxscore < tmp->backscore) { maxscore = tmp->backscore; maxtre = tmp; } i++; } tmp = maxtre;#else#ifdef WORD_GRAPH /* treat only words on a graph path */ if (! tmp->within_wordgraph) { return NULL; }#endif#endif /* WPAIR */ return(tmp); } else { return(NULL); }}/* end of file */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?