📄 beam.c
字号:
#endif if (r->config->successive.enabled) { /* short-pause segmentation mode */ /* 呵姜フレ〖ムに荒った呵络スコアの帽胳 */ /* it should be the best trellis word on the last frame */ if (maxscore < tmp->backscore) { maxscore = tmp->backscore; best = tmp; } } else { /* not segmentation mode */ /* 呵姜帽胳は winfo->tail_silwid に盖年 */ /* it is fixed to the tail silence model (winfo->tail_silwid) */ if (tmp->wid == winfo->tail_silwid && maxscore < tmp->backscore) { maxscore = tmp->backscore; best = tmp; break; } } } if (maxscore != LOG_ZERO) break; } if (last_time < 0) { /* not found */ jlog("WARNING: %02d %s: no tail silence word survived on the last frame, search failed\n", r->config->id, r->config->name); r->result.status = J_RESULT_STATUS_FAIL; //callback_exec(CALLBACK_RESULT, r); return; } } if (r->lmtype == LM_DFA) { for (last_time = framelen - 1; last_time >= 0; last_time--) { /* 琐萨に荒った帽胳の面で呵络スコアの帽胳(cp_endは蝗脱しない) */ /* the best trellis word on the last frame (not use cp_end[]) */ maxscore = LOG_ZERO; for (i=0;i<backtrellis->num[last_time];i++) { tmp = backtrellis->rw[last_time][i];#ifdef WORD_GRAPH /* treat only words on a graph path */ if (!tmp->within_context) continue;#endif /* if (dfa->cp_end[winfo->wton[tmp->wid]] == TRUE) {*/ if (maxscore < tmp->backscore) { maxscore = tmp->backscore; best = tmp; } /* }*/ } if (maxscore != LOG_ZERO) break; } if (last_time < 0) { /* not found */ jlog("WARNING: %02d %s: no sentence-end word survived on last beam\n", r->config->id, r->config->name); r->result.status = J_RESULT_STATUS_FAIL; //callback_exec(CALLBACK_RESULT, r); return; } } /* traceback word trellis from the best word */ total_lscore = trace_backptr(wordseq, &wordlen, best, r->lm->winfo);#ifdef SPSEGMENT_NAIST if (r->config->successive.enabled) { /* on segmentation mode, recognition result that only consists of short-pause words will be treated as recognition rejection */ ok_p = FALSE; for(i=0;i<wordlen;i++) { if (! is_sil(wordseq[i], r)) ok_p = TRUE; } if (ok_p == FALSE) { r->result.status = J_RESULT_STATUS_ONLY_SILENCE; return; } }#endif /* just flush last progress output */ /* if (recog->jconf->output.progout_flag) { recog->result.status = 1; recog->result.num_frame = last_time; recog->result.pass1.word = wordseq; recog->result.pass1.word_num = wordlen; recog->result.pass1.score = best->backscore; recog->result.pass1.score_lm = total_lscore; recog->result.pass1.score_am = best->backscore - total_lscore; //callback_exec(CALLBACK_RESULT_PASS1_INTERIM, recog); }*/ /* output 1st pass result */ if (verbose_flag || ! r->config->output.progout_flag) { r->result.status = J_RESULT_STATUS_SUCCESS; r->result.num_frame = framelen; for(i=0;i<wordlen;i++) r->result.pass1.word[i] = wordseq[i]; r->result.pass1.word_num = wordlen; r->result.pass1.score = best->backscore; r->result.pass1.score_lm = total_lscore; r->result.pass1.score_am = best->backscore - total_lscore; //callback_exec(CALLBACK_RESULT_PASS1, r); } /* store the result to global val (notice: in reverse order) */ for(i=0;i<wordlen;i++) r->pass1_wseq[i] = wordseq[i]; r->pass1_wnum = wordlen; r->pass1_score = best->backscore;#ifdef WORD_GRAPH /* 帽胳トレリスから·ラティスを栏喇する */ /* generate word graph from the word trellis */ r->peseqlen = backtrellis->framelen; r->result.wg1 = NULL; generate_lattice(last_time, r); link_lattice_by_time(r->result.wg1); if (r->lmtype == LM_PROB) re_compute_lattice_lm(r->result.wg1, r->wchmm); r->result.wg1_num = wordgraph_sort_and_annotate_id(&(r->result.wg1), r); /* compute graph CM by forward-backward processing */ graph_forward_backward(r->result.wg1, r); //callback_exec(CALLBACK_RESULT_PASS1_GRAPH, r); //wordgraph_clean(&(r->result.wg1));#endif}/** * <JA> * トレリス帽胳をスコアでソ〖トするqsort簇眶. * * @param x1 [in] 妥燎1へのポインタ * @param x2 [in] 妥燎2へのポインタ * * @return qsort の猛 * </JA> * <EN> * qsort function to sort trellis words by their score. * * @param x1 [in] pointer to element #1 * @param x2 [in] pointer to element #2 * * @return value required for qsort. * </EN> */static intcompare_backscore(TRELLIS_ATOM **x1, TRELLIS_ATOM **x2){ return((*x2)->backscore - (*x1)->backscore);}/** * <JA> * find_1pass_result() の帽胳千急モ〖ド惹. 帽胳千急モ〖ドでは妈1パスで * 千急を姜位するので·评られた铬输は奶撅の妈2パスと票じ眷疥に呈羌する. * * @param framelen [in] 妈1パスで借妄が毗茫したフレ〖ム眶 * @param r [i/o] 千急借妄インスタンス * * </JA> * <EN> * Isolated word recognition version of find_1pass_result(). * Since Julius executes only the 1st pass on Isolated word recognition * mode, the result candidate will be stored as the final result. * * @param framelen [in] frame length that has been processed * @param r [i/o] recognition process instance * * </EN> */static voidfind_1pass_result_word(int framelen, RecogProcess *r){ BACKTRELLIS *bt; TRELLIS_ATOM *best, *tmp; int last_time; Sentence *s;#ifdef CONFIDENCE_MEASURE LOGPROB sum;#endif LOGPROB maxscore; int i; TRELLIS_ATOM **idx; int num; if (r->lmvar != LM_DFA_WORD) return; bt = r->backtrellis; for (last_time = framelen - 1; last_time >= 0; last_time--) { maxscore = LOG_ZERO; for (i=0;i<bt->num[last_time];i++) { tmp = bt->rw[last_time][i];#ifdef WORD_GRAPH /* treat only words on a graph path */ if (!tmp->within_context) continue;#endif if (maxscore < tmp->backscore) { maxscore = tmp->backscore; best = tmp; } } if (maxscore != LOG_ZERO) break; } if (last_time < 0) { /* not found */ jlog("WARNING: %02d %s: no word survived on the last frame, search failed\n", r->config->id, r->config->name); r->result.status = J_RESULT_STATUS_FAIL; //callback_exec(CALLBACK_RESULT, r); return; }#ifdef CONFIDENCE_MEASURE sum = 0.0; for (i=0;i<bt->num[last_time];i++) { tmp = bt->rw[last_time][i];#ifdef WORD_GRAPH /* treat only words on a graph path */ if (!tmp->within_context) continue;#endif sum += pow(10, r->config->annotate.cm_alpha * (tmp->backscore - maxscore)); }#endif /* set recognition result status to normal */ r->result.status = J_RESULT_STATUS_SUCCESS; if (r->config->output.output_hypo_maxnum > 1) { /* more than one candidate is requested */ /* get actual number of candidates to output */ num = r->config->output.output_hypo_maxnum; if (num > bt->num[last_time]) { num = bt->num[last_time]; } /* prepare result storage */ result_sentence_malloc(r, num); r->result.sentnum = num; /* sort by score */ idx = (TRELLIS_ATOM **)mymalloc(sizeof(TRELLIS_ATOM *)*bt->num[last_time]); for (i=0;i<bt->num[last_time];i++) { idx[i] = bt->rw[last_time][i]; } qsort(idx, bt->num[last_time], sizeof(TRELLIS_ATOM *), (int (*)(const void *,const void *))compare_backscore); /* store to result storage */ for(i=0;i<r->result.sentnum;i++) { s = &(r->result.sent[i]); tmp = idx[i]; s->word_num = 1; s->word[0] = tmp->wid;#ifdef CONFIDENCE_MEASURE s->confidence[0] = pow(10, r->config->annotate.cm_alpha * (tmp->backscore - maxscore)) / sum;#endif s->score = tmp->backscore; s->score_lm = 0.0; s->score_am = tmp->backscore; if (multigram_get_all_num(r->lm) > 0) { s->gram_id = multigram_get_gram_from_wid(s->word[0], r->lm); } else { s->gram_id = 0; } } /* free work area for sort */ free(idx); } else { /* only max is needed */ /* prepare result storage */ result_sentence_malloc(r, 1); r->result.sentnum = 1; s = &(r->result.sent[0]); s->word_num = 1; s->word[0] = best->wid;#ifdef CONFIDENCE_MEASURE s->confidence[0] = 1.0 / sum;#endif s->score = best->backscore; s->score_lm = 0.0; s->score_am = best->backscore; if (multigram_get_all_num(r->lm) > 0) { s->gram_id = multigram_get_gram_from_wid(s->word[0], r->lm); } else { s->gram_id = 0; } } /* copy as 1st pass result */ memcpy(&(r->result.pass1), &(r->result.sent[0]), sizeof(Sentence)); r->result.pass1.align = NULL; //callback_exec(CALLBACK_RESULT, r); //free(r->result.sent);}#ifdef DETERMINE/** * <JA> * 妈1パスの庞面デ〖タから玲袋澄年材墙かどうか冉年する∈悸赋∷. tremax が * NULL のときは介袋步する. 澄年箕は r->have_determine を TRUE にする. * * @param r [i/o] 不兰千急借妄インスタンス * @param t [in] フレ〖ム * @param tremax [in] 附哼のフレ〖ム惧で呵锑のトレリス帽胳 * @param thres [in] 澄年脱のスコア镧猛 * @param countthres [in] 澄年脱の积鲁フレ〖ム眶の镧猛 * * @return 澄年箕は tremax を手す. 踏澄年箕は NULL を手す. * </JA> * <EN> * Try to Determine a word hypothesis before end of input on isolated * word recognition mode (EXPERIMENT). Initialize if tremax is NULL. * Set r->have_determine to TRUE if determined. * * @param r [i/o] recognition process instance * @param t [in] current frame * @param tremax [in] maximum scored trellis word on the current frame * @param thres [in] score threshold for determinization * @param countthres [in] frame duration threshold for determinization * * @return the tremax if determined, or NULL if not determined yet., * </EN> */static TRELLIS_ATOM *determine_word(RecogProcess *r, int t, TRELLIS_ATOM *tremax, LOGPROB thres, int countthres){ TRELLIS_ATOM *ret; WORD_ID w; //LOGPROB sum; //LOGPROB cm; int j; FSBeam *d; TOKEN2 *tk; if (tremax == NULL) { /* initialize */ r->determine_count = 0; r->determine_maxnodescore = LOG_ZERO; r->determined = FALSE; r->determine_last_wid = WORD_INVALID; r->have_determine = FALSE; return NULL; } ret = NULL; /* get confidence score of the maximum word hypothesis *//* * sum = 0.0; * tre = recog->backtrellis->list; * while (tre != NULL && tre->endtime == t) { * sum += pow(10, recog->jconf->annotate.cm_alpha * (tre->backscore - tremax->backscore)); * tre = tre->next; * } * cm = 1.0 / sum; */ /* determinization decision */ w = tremax->wid; r->have_determine = FALSE; /* determine by score threshold from maximum node score to maximum word end node score */ if (r->determine_last_wid == w && r->determine_maxnodescore - tremax->backscore <= thres) { r->determine_count++; if (r->determine_count > countthres) { if (r->determined == FALSE) { ret = tremax; r->determined = TRUE; r->have_determine = TRUE; } } } else { r->determine_count = 0; } //printf("determine: %d: %s: cm=%f, relscore=%f, count=%d, phase=%d\n", t, recog->model->winfo->woutput[w], cm, determine_maxnodescore - tremax->backscore, count, phase); r->determine_last_wid = w; /* update maximum node score here for next call, since the word path determination is always one frame later */ d = &(r->pass1); r->determine_maxnodescore = LOG_ZERO; for (j = d->n_start; j <= d->n_end; j++) { tk = &(d->tlist[d->tn][d->tindex[d->tn][j]]); if (r->determine_maxnodescore < tk->score) r->determine_maxnodescore = tk->score; } return(ret);}/** * <JA> * 帽胳千急箕に·妈1パスの借妄面に玲袋澄年する∈悸赋∷. 澄年できた眷圭·
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -