📄 search_bestfirst_v1.c
字号:
} }#ifndef GRAPHOUT_PRECISE_BOUNDARY if (r->graphout) { if (now->tail_g_score != LOG_ZERO) { if (now->prevgraph != NULL) { (now->prevgraph)->leftscore = now->tail_g_score; } } }#endif /* 肌搀のために now->last_ph を构糠 */ /* update 'now->last_ph' for future scan_word() */ if (back_rescan) { now->last_ph = dwrk->phmmseq[0]; } else { now->last_ph = winfo->wseq[word][0]; } if (enable_iwsp && hmminfo->multipath) { now->last_ph_sp_attached = dwrk->has_sp[0]; } }#ifdef GRAPHOUT_PRECISE_BOUNDARY if (! hmminfo->multipath) { if (r->graphout) { /* 肌搀の next_word 脱に董肠攫鼠を拇腊 */ /* proceed word boundary for one step for next_word */ now->wordend_frame[peseqlen-1] = now->wordend_frame[0]; now->wordend_gscore[peseqlen-1] = now->wordend_gscore[0]; for (t=0;t<peseqlen-1;t++) { now->wordend_frame[t] = now->wordend_frame[t+1]; now->wordend_gscore[t] = now->wordend_gscore[t+1]; } } }#endif /* free work area */ free_hmm(whmm);#ifdef TCD if (hmminfo->multipath) { if (ccd_flag) { jlog("DEBUG: last_ph = %s", (now->last_ph)->name); if (now->last_ph_sp_attached) jlog(" (sp attached)"); jlog("\n"); } } else { jlog("DEBUG: last_ph = %s\n", (now->last_ph)->name); }#endif}/**************************************************************************//*** 糠簿棱の鸥倡とヒュ〖リスティックを芬いだ链挛スコアを纷换 ***//*** Expand new hypothesis and compute the total score (with heuristic) ***//**************************************************************************//** * <JA> * 鸥倡傅簿棱に肌帽胳を儡鲁して糠しい簿棱を栏喇する. 肌帽胳の帽胳トレリス惧の * スコアから呵锑儡鲁爬を滇め·簿棱スコアを纷换する. * * @param now [in] 鸥倡傅簿棱 * @param new [out] 糠たに栏喇された簿棱が呈羌される * @param nword [in] 儡鲁する肌帽胳の攫鼠 * @param param [in] 掐蜗パラメ〖タ误 * @param r [in] 千急借妄インスタンス * * </JA> * <EN> * Connect a new word to generate a next hypothesis. The optimal connection * point and new sentence score of the new hypothesis will be estimated by * looking up the corresponding words on word trellis. * * @param now [in] source hypothesis * @param new [out] pointer to save the newly generated hypothesis * @param nword [in] next word to be connected * @param param [in] input parameter vector * @param r [in] recognition process instance * * </EN> * @callgraph * @callergraph */voidnext_word(NODE *now, NODE *new, NEXTWORD *nword, HTK_Param *param, RecogProcess *r){ int t; HMM_Logical *newphone; int lastword; int i; LOGPROB tmpp; LOGPROB a_value; int startt; int word; LOGPROB totalscore; TRELLIS_ATOM *tre; BACKTRELLIS *backtrellis; WORD_INFO *winfo; HTK_HMM_INFO *hmminfo; int peseqlen; boolean ccd_flag; backtrellis = r->backtrellis; winfo = r->lm->winfo; hmminfo = r->am->hmminfo; peseqlen = r->peseqlen; ccd_flag = r->ccd_flag; new->score = LOG_ZERO; word = nword->id; lastword=now->seq[now->seqnum-1]; /* 帽胳事び、DFA觉轮戎规、咐胳スコアを费镜ˇ构糠 */ /* inherit and update word sequence, DFA state and total LM score */ for (i=0;i< now->seqnum;i++){ new->seq[i] = now->seq[i];#ifdef CM_SEARCH#ifdef CM_MULTIPLE_ALPHA memcpy(new->cmscore[i], now->cmscore[i], sizeof(LOGPROB) * r->config->annotate.cm_alpha_num);#else new->cmscore[i] = now->cmscore[i];#endif#endif /* CM_SEARCH */ } new->seq[i] = word; new->seqnum = now->seqnum+1; new->state = nword->next_state; new->totallscore = now->totallscore + nword->lscore; if (hmminfo->multipath) new->final_g = now->final_g; if (ccd_flag) { /* 鸥倡帽胳の儡鲁爬の不燎HMMをnewphoneにセットする. 傅簿棱 now との帽胳粗の不燎茨董巴赂拉を雇胃する */ /* set the triphone at the connection point to 'newphone', considering cross-word context dependency to 'now' */ newphone = get_right_context_HMM(winfo->wseq[word][winfo->wlen[word]-1], now->last_ph->name, hmminfo); if (newphone == NULL) { /* triphone not found */ /* fallback to the original bi/mono-phone */ /* error if the original is pseudo phone (not explicitly defined in hmmdefs/hmmlist) */ /* exception: word with 1 phone (triphone may exist in the next expansion */ if (winfo->wlen[word] > 1 && winfo->wseq[word][winfo->wlen[word]-1]->is_pseudo){ error_missing_right_triphone(winfo->wseq[word][winfo->wlen[word]-1], now->last_ph->name); } newphone = winfo->wseq[word][winfo->wlen[word]-1]; } /* 傅簿棱をscanした箕の琐眉不燎HMM -> 糠簿棱の木涟不燎HMM */ /* inherit last_ph */ new->last_ph = now->last_ph; if (hmminfo->multipath) { new->last_ph_sp_attached = now->last_ph_sp_attached; } /* backscan脱儡鲁ポイントのスコア g_prev[] をコピ〖 */ /* copy g_prev[] that are scores at backscan connection point */ for (t=0;t<peseqlen;t++) { new->g_prev[t] = now->g_prev[t]; } } else { /* not triphone */ /* 鸥倡帽胳の儡鲁(=姜眉)の不燎HMMをnewphoneにセット */ /* set the phone at the connection point to 'newphone' */ newphone = winfo->wseq[word][winfo->wlen[word]-1]; } if (r->lmtype == LM_PROB) { new->lscore = nword->lscore; } else if (r->lmtype == LM_DFA) { new->lscore = 0.0; } if (! hmminfo->multipath) { /* a_value: 儡鲁爬の莲败澄唯 */ /* a_value: transition probability of connection point */ i = hmm_logical_state_num(newphone); a_value = (hmm_logical_trans(newphone))->a[i-2][i-1]; } /***************************************************************************/ /* 涟羹き(妈2パス),稿ろ羹き(妈1パス)トレリスを儡鲁し呵锑儡鲁爬を斧つける */ /* connect forward/backward trellis to look for the best connection time */ /***************************************************************************/ if (hmminfo->multipath) { startt = peseqlen-1; } else { startt = peseqlen-2; new->g[startt+1] = LOG_ZERO; } /*-----------------------------------------------------------------*/ /* 帽胳トレリスを玫して, 肌帽胳の呵锑儡鲁爬を券斧する */ /* determine the best connection time of the new word, seeking the word trellis */ /*-----------------------------------------------------------------*/ /* update new->g[t] */ if (hmminfo->multipath) { for(t=startt;t>=0;t--) { new->g[t] = now->g[t] + nword->lscore; } } else { for(t=startt;t>=0;t--) { new->g[t] = now->g[t+1] + a_value + nword->lscore; } } new->tre = NULL; if (r->lmtype == LM_DFA && !r->config->pass2.looktrellis_flag) { /* すべてのフレ〖ムにわたって呵锑を玫す */ /* search for best trellis word throughout all frame */ for(t = startt; t >= 0; t--) { tre = bt_binsearch_atom(backtrellis, t, (WORD_ID) word); if (tre == NULL) continue; totalscore = new->g[t] + tre->backscore; if (! hmminfo->multipath) { if (newphone->is_pseudo) { tmpp = outprob_cd(&(r->am->hmmwrk), t, &(newphone->body.pseudo->stateset[newphone->body.pseudo->state_num-2]), param); } else { tmpp = outprob_state(&(r->am->hmmwrk), t, newphone->body.defined->s[newphone->body.defined->state_num-2], param); } totalscore += tmpp; } if (new->score < totalscore) { new->score = totalscore; new->bestt = t; new->estimated_next_t = tre->begintime - 1; new->tre = tre; } } return; } /* この鸥倡帽胳のトレリス惧の姜眉箕粗の涟稿のみスキャンする 涟稿に息鲁して赂哼するフレ〖ムについてのみ纷换 */ /* search for best trellis word only around the estimated time */ /* 1. search forward */ for(t = (nword->tre)->endtime; t >= 0; t--) { tre = bt_binsearch_atom(backtrellis, t, (WORD_ID) word); if (tre == NULL) break; /* go to 2 if the trellis word disappear */ totalscore = new->g[t] + tre->backscore; if (! hmminfo->multipath) { if (newphone->is_pseudo) { tmpp = outprob_cd(&(r->am->hmmwrk), t, &(newphone->body.pseudo->stateset[newphone->body.pseudo->state_num-2]), param); } else { tmpp = outprob_state(&(r->am->hmmwrk), t, newphone->body.defined->s[newphone->body.defined->state_num-2], param); } totalscore += tmpp; } if (new->score < totalscore) { new->score = totalscore; new->bestt = t; new->estimated_next_t = tre->begintime - 1; new->tre = tre; } } /* 2. search backward */ for(t = (nword->tre)->endtime + 1; t <= startt; t++) { tre = bt_binsearch_atom(backtrellis, t, (WORD_ID) word); if (tre == NULL) break; /* end if the trellis word disapper */ totalscore = new->g[t] + tre->backscore; if (! hmminfo->multipath) { if (newphone->is_pseudo) { tmpp = outprob_cd(&(r->am->hmmwrk), t, &(newphone->body.pseudo->stateset[newphone->body.pseudo->state_num-2]), param); } else { tmpp = outprob_state(&(r->am->hmmwrk), t, newphone->body.defined->s[newphone->body.defined->state_num-2], param); } totalscore += tmpp; } if (new->score < totalscore) { new->score = totalscore; new->bestt = t; new->estimated_next_t = tre->begintime - 1; new->tre = tre; } }}/**********************************************************************//********** 介袋簿棱の栏喇 ****************************//********** Generate an initial hypothesis ****************************//**********************************************************************//** * <JA> * 涂えられた帽胳から介袋簿棱を栏喇する. * * @param new [out] 糠たに栏喇された簿棱が呈羌される * @param nword [in] 介袋簿棱帽胳の攫鼠 * @param param [in] 掐蜗パラメ〖タ误 * @param r [in] 千急借妄インスタンス * * </JA> * <EN> * Generate an initial hypothesis from given word. * * @param new [out] pointer to save the newly generated hypothesis * @param nword [in] words of the first candidates * @param param [in] input parameter vector * @param r [in] recognition process instance * * </EN> * @callgraph * @callergraph */voidstart_word(NODE *new, NEXTWORD *nword, HTK_Param *param, RecogProcess *r){ HMM_Logical *newphone; WORD_ID word; LOGPROB tmpp; int t; TRELLIS_ATOM *tre = NULL; BACKTRELLIS *backtrellis; WORD_INFO *winfo; int peseqlen; boolean ccd_flag; backtrellis = r->backtrellis; winfo = r->lm->winfo; peseqlen = r->peseqlen; ccd_flag = r->ccd_flag; /* initialize data */ word = nword->id; new->score = LOG_ZERO; new->seqnum = 1; new->seq[0] = word; new->state = nword->next_state; new->totallscore = nword->lscore; /* cross-word triphone handling is not needed on startup */ newphone = winfo->wseq[word][winfo->wlen[word]-1]; if (ccd_flag) { new->last_ph = NULL; new->last_ph_sp_attached = FALSE; } new->lscore = nword->lscore; if (r->lmtype == LM_PROB) { new->g[peseqlen-1] = nword->lscore; } else if (r->lmtype == LM_DFA) { new->g[peseqlen-1] = 0; } for (t=peseqlen-1; t>=0; t--) { tre = bt_binsearch_atom(backtrellis, t, word); if (tre != NULL) { if (r->graphout) { new->bestt = peseqlen-1; } else { new->bestt = t; } new->score = new->g[peseqlen-1] + tre->backscore; if (! r->am->hmminfo->multipath) { if (newphone->is_pseudo) { tmpp = outprob_cd(&(r->am->hmmwrk), peseqlen-1, &(newphone->body.pseudo->stateset[newphone->body.pseudo->state_num-2]), param); } else { tmpp = outprob_state(&(r->am->hmmwrk), peseqlen-1, newphone->body.defined->s[newphone->body.defined->state_num-2], param); } new->score += tmpp; } new->estimated_next_t = tre->begintime - 1; new->tre = tre; break; } } if (tre == NULL) { /* no word in backtrellis */ new->score = LOG_ZERO; }}/** * <JA> * 姜眉借妄¨姜眉まで茫した矢簿棱の呵姜弄なスコアをセットする. * * @param now [in] 姜眉まで茫した簿棱 * @param new [out] 呵姜弄な矢簿棱のスコアを呈羌する眷疥へのポインタ * @param param [in] 掐蜗パラメ〖タ误 * @param r [in] 千急借妄インスタンス * * </JA> * <EN> * Hypothesis termination: set the final sentence scores of hypothesis * that has already reached to the end. * * @param now [in] hypothesis that has already reached to the end * @param new [out] pointer to save the final sentence information * @param param [in] input parameter vectors * @param r [in] recognition process instance * * </EN> * @callgraph * @callergraph */voidlast_next_word(NODE *now, NODE *new, HTK_Param *param, RecogProcess *r){ cpy_node(new, now); /* 呵姜スコアを肋年 */ /* update the final score */ if (r->am->hmminfo->multipath) { new->score = now->final_g; } else { new->score = now->g[0]; }}#endif /* PASS2_STRICT_IWCD *//* end of file */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -