diff options
author | lnetsch | 2011-05-13 17:00:05 -0500 |
---|---|---|
committer | lnetsch | 2011-05-13 17:00:05 -0500 |
commit | f5386b799c146f6328e23caec486f5397006eea7 (patch) | |
tree | 15bd4448c1dd47fca3181312b647c170b80424d7 | |
parent | f424c4355d0ee01a762fc3348a4d68f63e7b6128 (diff) | |
download | tiesr-f5386b799c146f6328e23caec486f5397006eea7.tar.gz tiesr-f5386b799c146f6328e23caec486f5397006eea7.tar.xz tiesr-f5386b799c146f6328e23caec486f5397006eea7.zip |
[#1354] Merge r75 changes from cm_mods branch to trunk to implement a penalty for repeated non-silence HMM loop transitions.
git-svn-id: https://gforge.ti.com/svn/tiesr/trunk@76 469fd053-429d-4955-9e4c-93c0d7a8ff27
-rw-r--r-- | TIesrEngine/src/gmhmm.h | 9 | ||||
-rwxr-xr-x | TIesrEngine/src/search.cpp | 167 |
2 files changed, 115 insertions, 61 deletions
diff --git a/TIesrEngine/src/gmhmm.h b/TIesrEngine/src/gmhmm.h index d88909f..45b76e0 100644 --- a/TIesrEngine/src/gmhmm.h +++ b/TIesrEngine/src/gmhmm.h | |||
@@ -78,7 +78,8 @@ Now in tiesrcommonmacros.h | |||
78 | 78 | ||
79 | #define PRUNE_COEFF -3 /* default pruning */ | 79 | #define PRUNE_COEFF -3 /* default pruning */ |
80 | #define WIP 0 /* default word insertion penalty */ | 80 | #define WIP 0 /* default word insertion penalty */ |
81 | 81 | #define TRAN_DUR_BIAS -100 | |
82 | //#define TRAN_DUR_BIAS 0 | ||
82 | #define NSYM 2 /* hash code nbr */ | 83 | #define NSYM 2 /* hash code nbr */ |
83 | 84 | ||
84 | //#define MAX_STATE_CELL 20000 /* these 4 const define search space */ | 85 | //#define MAX_STATE_CELL 20000 /* these 4 const define search space */ |
@@ -106,7 +107,7 @@ Now in tiesrcommonmacros.h | |||
106 | 107 | ||
107 | /* From search.cpp */ | 108 | /* From search.cpp */ |
108 | #define UNDEF_CELL 0xffff | 109 | #define UNDEF_CELL 0xffff |
109 | #define UNDEFINEDTIME (-1) | 110 | #define UNDEFINEDTIME 0xfff |
110 | 111 | ||
111 | 112 | ||
112 | /* --------------------------------------------------------------------------- | 113 | /* --------------------------------------------------------------------------- |
@@ -249,6 +250,10 @@ typedef enum CompensationType { | |||
249 | (time_idx) ? ((base) + (pos)) : \ | 250 | (time_idx) ? ((base) + (pos)) : \ |
250 | ((base) + max_state_cell - (pos) - n_state) | 251 | ((base) + max_state_cell - (pos) - n_state) |
251 | 252 | ||
253 | #define STATE_FRM( frm ) ( frm & 0xfff) | ||
254 | #define STATE_DUR( frm ) ( (frm >> 12) & 0xf ) | ||
255 | #define STATE_CAT( dur, frm ) ( ((dur & 0xf) << 12 ) | (frm & 0xfff) ) | ||
256 | |||
252 | /* was: ((base) + MAX_STATE_CELL - 1 - (pos) - n_state) */ | 257 | /* was: ((base) + MAX_STATE_CELL - 1 - (pos) - n_state) */ |
253 | 258 | ||
254 | #define SYM_CELL(base,pos,time_idx,max_sym_cell2) \ | 259 | #define SYM_CELL(base,pos,time_idx,max_sym_cell2) \ |
diff --git a/TIesrEngine/src/search.cpp b/TIesrEngine/src/search.cpp index e23b93b..e3d3c0a 100755 --- a/TIesrEngine/src/search.cpp +++ b/TIesrEngine/src/search.cpp | |||
@@ -374,7 +374,7 @@ static void coloring_beam(unsigned short cur_time_index, gmhmm_type *gv) | |||
374 | unsigned short q, b_index, cont, c_bm_cnt = 0; | 374 | unsigned short q, b_index, cont, c_bm_cnt = 0; |
375 | short depth; | 375 | short depth; |
376 | 376 | ||
377 | if (cur_time_index == USHRT_MAX) return ; /* no beam cell has this time (no sym was collected at this time) */ | 377 | if (cur_time_index == UNDEFINEDTIME) return ; /* no beam cell has this time (no sym was collected at this time) */ |
378 | for (q = gv->time_base[cur_time_index].beam_idx; NOT_END_IX_CELL(q,gv->max_beam_cell); q = beam_base[q].next) { | 378 | for (q = gv->time_base[cur_time_index].beam_idx; NOT_END_IX_CELL(q,gv->max_beam_cell); q = beam_base[q].next) { |
379 | bm = beam_base + q; | 379 | bm = beam_base + q; |
380 | depth=0; | 380 | depth=0; |
@@ -574,7 +574,7 @@ grow_beam_cell(unsigned short sym, StateCell *p_cell, short first_time, unsigned | |||
574 | /* previous frame sym, starting frame, last frame*/ | 574 | /* previous frame sym, starting frame, last frame*/ |
575 | 575 | ||
576 | gv->beam_base[idx].idx_flag = (p_cell->sym == USHRT_MAX)? gv->max_beam_cell //zlook | 576 | gv->beam_base[idx].idx_flag = (p_cell->sym == USHRT_MAX)? gv->max_beam_cell //zlook |
577 | : find_beam_index(p_cell->sym, p_cell->frm, gv, last_frm); //previous stats' symble and starting frame. | 577 | : find_beam_index(p_cell->sym, STATE_FRM(p_cell->frm), gv, last_frm); //previous stats' symble and starting frame. |
578 | 578 | ||
579 | 579 | ||
580 | #ifdef _MONOPHONE_NET | 580 | #ifdef _MONOPHONE_NET |
@@ -587,7 +587,7 @@ grow_beam_cell(unsigned short sym, StateCell *p_cell, short first_time, unsigned | |||
587 | 587 | ||
588 | gv->beam_count=0; | 588 | gv->beam_count=0; |
589 | gv->next_time = next_time_cell(gv); | 589 | gv->next_time = next_time_cell(gv); |
590 | if (gv->next_time == USHRT_MAX) | 590 | if (gv->next_time == USHRT_MAX) |
591 | return eTIesrEngineTimeCellOverflow; | 591 | return eTIesrEngineTimeCellOverflow; |
592 | gv->time_base[gv->next_time].frm = frm_cnt; | 592 | gv->time_base[gv->next_time].frm = frm_cnt; |
593 | gv->time_base[gv->next_time].beam_idx = idx; /* this was changed from address to index */ | 593 | gv->time_base[gv->next_time].beam_idx = idx; /* this was changed from address to index */ |
@@ -724,13 +724,14 @@ static void init_search_last_syms( gmhmm_type * gv) | |||
724 | ---------------------------------------------------------------------- */ | 724 | ---------------------------------------------------------------------- */ |
725 | 725 | ||
726 | static void | 726 | static void |
727 | within_model_path(HmmType *hmm, StateCell *p_prev, StateCell *p_cur, gmhmm_type *gv, short prune) | 727 | within_model_path(unsigned short hmmcode, HmmType *hmm, StateCell *p_prev, StateCell *p_cur, gmhmm_type *gv, short prune) |
728 | { | 728 | { |
729 | long cur_prob; | 729 | long cur_prob; |
730 | short *trnprob; | 730 | short *trnprob; |
731 | short i, j; | 731 | short i, j; |
732 | StateCell *state_cell, *pprev; | 732 | StateCell *state_cell, *pprev; |
733 | short n_state, n1; | 733 | short n_state, n1; |
734 | short tprob, dur; | ||
734 | 735 | ||
735 | n_state = NBR_STATES(hmm,gv->base_tran); | 736 | n_state = NBR_STATES(hmm,gv->base_tran); |
736 | trnprob = gv->base_tran + hmm->tran + n_state; | 737 | trnprob = gv->base_tran + hmm->tran + n_state; |
@@ -740,18 +741,49 @@ within_model_path(HmmType *hmm, StateCell *p_prev, StateCell *p_cur, gmhmm_typ | |||
740 | 741 | ||
741 | if ( pprev->scr > prune ) { /*if a possible start -- within model prune*/ | 742 | if ( pprev->scr > prune ) { /*if a possible start -- within model prune*/ |
742 | 743 | ||
743 | for (j = 0; j < n1; j++) { /*for all target states within model*/ | 744 | /*for all target states within model*/ |
744 | 745 | for (j = 0; j < n1; j++) { | |
745 | if ( trnprob[j] > BAD_SCR ) { /* there exist i to j jump. note transprob is updated above with i */ | 746 | |
747 | /* Add duration penalty to transition probability | ||
748 | if not silence HMM and is a loop transition */ | ||
749 | if( hmmcode != 0 && i == j ) | ||
750 | { | ||
751 | dur = STATE_DUR(pprev->frm); | ||
752 | tprob = LONG2SHORT( (long)trnprob[j] + (long)dur*TRAN_DUR_BIAS ); | ||
753 | } | ||
754 | else | ||
755 | { | ||
756 | tprob = trnprob[j]; | ||
757 | } | ||
758 | |||
759 | /* there exist i to j jump. note transprob is updated above with i */ | ||
760 | if ( tprob > BAD_SCR ) { | ||
746 | 761 | ||
747 | state_cell = p_cur + j; | 762 | state_cell = p_cur + j; |
748 | cur_prob = (long) pprev->scr + (long) trnprob[j]; | 763 | cur_prob = (long) pprev->scr + (long) tprob; |
749 | 764 | ||
750 | if ( cur_prob > (long) state_cell->scr ) { //viterbi on transition prob. | 765 | /* Viterbi decoding done here on transition probability */ |
766 | if ( cur_prob > (long) state_cell->scr ) { | ||
751 | state_cell->scr = (short) cur_prob; | 767 | state_cell->scr = (short) cur_prob; |
752 | state_cell->sym = pprev->sym; /* propogate prev sym & frm */ | 768 | |
753 | state_cell->frm = pprev->frm; /*starting time, B*/ | 769 | /* propogate previous symbol */ |
770 | state_cell->sym = pprev->sym; | ||
771 | |||
772 | /* Propagate previous symbol frame, and state duration */ | ||
773 | if( hmmcode != 0 && i == j ) | ||
774 | { | ||
775 | /* loop transition in non-silence HMM */ | ||
776 | dur++; | ||
777 | dur = MIN( dur, 15 ); | ||
778 | state_cell->frm = STATE_CAT( dur, pprev->frm ); | ||
779 | } | ||
780 | else | ||
781 | { | ||
782 | /* Set last frame count only, which clears duration count */ | ||
783 | state_cell->frm = STATE_FRM(pprev->frm); | ||
784 | } | ||
754 | } | 785 | } |
786 | |||
755 | } | 787 | } |
756 | } | 788 | } |
757 | } | 789 | } |
@@ -842,14 +874,18 @@ cross_model_path(short exit_scr, unsigned short v_sym, unsigned short t_sym, | |||
842 | start_scr >= (long) start_cell->scr, gv); | 874 | start_scr >= (long) start_cell->scr, gv); |
843 | } | 875 | } |
844 | #endif | 876 | #endif |
845 | if ( start_scr >= (long) start_cell->scr ) { | 877 | |
846 | /* Viterbi, for the winner, | 878 | /* Viterbi decoding is done here in transitioning from the exit state |
847 | remember the frame index and the symbol where we are from */ | 879 | of the prior symbol's HMM into a state of a next grammar symbol HMM. |
848 | start_cell->scr = (short) start_scr; | 880 | Store the frame index and the symbol that started evaluation of this |
849 | start_cell->frm = starttime; //frm_cnt - 1; // this is true for HMM backtrace. not word based backtrace. | 881 | next HMM. Depending on the type of search (WORD or HMM) the symbol |
850 | start_cell->sym = v_sym; // word sym | 882 | that started evaluation may be the prior symbol or prior |
851 | 883 | word-ending symbol. */ | |
884 | if ( start_scr >= (long) start_cell->scr ) { | ||
852 | 885 | ||
886 | start_cell->scr = (short) start_scr; | ||
887 | start_cell->frm = STATE_FRM(starttime); | ||
888 | start_cell->sym = v_sym; | ||
853 | } | 889 | } |
854 | #ifdef USE_NBEST | 890 | #ifdef USE_NBEST |
855 | if (gv->bUseNBest) nb_uniq_nbest(gv->ptr_nbest_tmp->pNBestCells, uBeamIdx, start_cell, gv); | 891 | if (gv->bUseNBest) nb_uniq_nbest(gv->ptr_nbest_tmp->pNBestCells, uBeamIdx, start_cell, gv); |
@@ -945,7 +981,7 @@ path_propagation(short cur_idx, short prev_idx, unsigned short frm_cnt, gmhmm_ty | |||
945 | } | 981 | } |
946 | 982 | ||
947 | /*label all the within model path, if score is OK, prune is OK, */ | 983 | /*label all the within model path, if score is OK, prune is OK, */ |
948 | within_model_path(hmm, p_prev, p_cur, gv, prune); /*hmm, last state cell, new allocated state cell, ...*/ | 984 | within_model_path(hmmcode, hmm, p_prev, p_cur, gv, prune); /*hmm, last state cell, new allocated state cell, ...*/ |
949 | 985 | ||
950 | exit_prob = p_prev[ n_state - 1 ].scr; | 986 | exit_prob = p_prev[ n_state - 1 ].scr; |
951 | 987 | ||
@@ -973,7 +1009,7 @@ path_propagation(short cur_idx, short prev_idx, unsigned short frm_cnt, gmhmm_ty | |||
973 | 1009 | ||
974 | } | 1010 | } |
975 | else // p_prev->sym will be the word info of last sym | 1011 | else // p_prev->sym will be the word info of last sym |
976 | { starttime = p_prev[ n_state - 1 ].frm; | 1012 | { starttime = STATE_FRM(p_prev[ n_state - 1 ].frm); |
977 | status = cross_model_path(exit_prob + gv->tranwgt, p_prev[n_state -1].sym, t_sym, hmm_dlt, sym_dlt, cur_idx, frm_cnt,gv, sym_prev->depth,starttime); | 1013 | status = cross_model_path(exit_prob + gv->tranwgt, p_prev[n_state -1].sym, t_sym, hmm_dlt, sym_dlt, cur_idx, frm_cnt,gv, sym_prev->depth,starttime); |
978 | 1014 | ||
979 | if ( status != eTIesrEngineSuccess ) | 1015 | if ( status != eTIesrEngineSuccess ) |
@@ -1035,15 +1071,16 @@ static short | |||
1035 | 1071 | ||
1036 | long scr; | 1072 | long scr; |
1037 | StateCell *max_exit_state = NULL, *state_cell, *start_cell; | 1073 | StateCell *max_exit_state = NULL, *state_cell, *start_cell; |
1038 | unsigned short last_SYM = USHRT_MAX, last_FRM = USHRT_MAX; | 1074 | unsigned short last_SYM = USHRT_MAX, last_FRM = UNDEFINEDTIME; |
1039 | unsigned short bestdepth = 0, n_actsym=0,sumdepth=0, maxdepth=0; | 1075 | unsigned short bestdepth = 0, n_actsym=0,sumdepth=0, maxdepth=0; |
1076 | unsigned short frm; | ||
1040 | 1077 | ||
1041 | #ifdef SHOW_DIAGONISIS | 1078 | #ifdef SHOW_DIAGONISIS |
1042 | if (sttnode!=3) sttnode=0; | 1079 | if (sttnode!=3) sttnode=0; |
1043 | #endif | 1080 | #endif |
1044 | 1081 | ||
1045 | #ifdef USE_CONFIDENCE | 1082 | #ifdef USE_CONFIDENCE |
1046 | short *p_scr_anti, *pScrAnti = cm_antiscr((ConfType*)gv->pConf, frm_cnt); | 1083 | short *p_scr_anti, *pScrAnti = cm_antiscr((ConfType*)gv->pConf, frm_cnt); |
1047 | short /* for cache */ | 1084 | short /* for cache */ |
1048 | cm_prev_scr = LZERO; | 1085 | cm_prev_scr = LZERO; |
1049 | if (((ConfType*)gv->pConf)->bNeedUpdate == FALSE) | 1086 | if (((ConfType*)gv->pConf)->bNeedUpdate == FALSE) |
@@ -1131,19 +1168,19 @@ static short | |||
1131 | 1168 | ||
1132 | #ifdef USE_CONFIDENCE | 1169 | #ifdef USE_CONFIDENCE |
1133 | if ((gs > cm_prev_scr) && (pScrAnti != NULL)){ | 1170 | if ((gs > cm_prev_scr) && (pScrAnti != NULL)){ |
1134 | p_scr_anti = pScrAnti; | 1171 | p_scr_anti = pScrAnti; |
1135 | 1172 | ||
1136 | if (p_scr_anti){ | 1173 | if (p_scr_anti){ |
1137 | *p_scr_anti = gs; | 1174 | *p_scr_anti = gs; |
1138 | } | 1175 | } |
1139 | 1176 | ||
1140 | cm_prev_scr = gs; | 1177 | cm_prev_scr = gs; |
1141 | } | 1178 | } |
1142 | #endif | 1179 | #endif |
1143 | 1180 | ||
1144 | scr = (long) state_cell->scr + (long) gs; //gauss_obs_score_f(sObs?sObs:mfcc_feature, pdf_idx, gv); | 1181 | scr = (long) state_cell->scr + (long) gs; //gauss_obs_score_f(sObs?sObs:mfcc_feature, pdf_idx, gv); |
1182 | |||
1145 | 1183 | ||
1146 | |||
1147 | //if (sym_cell->depth *1.5 - gv->frm_cnt>0) scr-= 500; // soft prune | 1184 | //if (sym_cell->depth *1.5 - gv->frm_cnt>0) scr-= 500; // soft prune |
1148 | //if ( sym_cell->depth > (gv->bestdepth +9) || sym_cell->depth < (gv->bestdepth -10) ) scr-=500; | 1185 | //if ( sym_cell->depth > (gv->bestdepth +9) || sym_cell->depth < (gv->bestdepth -10) ) scr-=500; |
1149 | scr -= (long) gv->best_prev_scr; | 1186 | scr -= (long) gv->best_prev_scr; |
@@ -1154,14 +1191,15 @@ static short | |||
1154 | /* coloring pending states (including exit states): | 1191 | /* coloring pending states (including exit states): |
1155 | * mark active beam cells for active pending states | 1192 | * mark active beam cells for active pending states |
1156 | */ | 1193 | */ |
1157 | if (state_cell->frm != USHRT_MAX) | 1194 | frm = STATE_FRM( state_cell->frm ); |
1158 | if ((state_cell->frm != last_FRM) || (state_cell->sym != last_SYM)) { //if it is from a new search node (frame/sym pair) | 1195 | if ( frm != UNDEFINEDTIME ) |
1196 | if ( (frm != last_FRM) || (state_cell->sym != last_SYM)) { //if it is from a new search node (frame/sym pair) | ||
1159 | /*pass best frame/sym to this state so far*/ | 1197 | /*pass best frame/sym to this state so far*/ |
1160 | if (gv->need_compact==TRUE ) //|| gv->word_backtrace==FALSE) //if (gv->evalstat.beam.cur_pos > 1000) //if (gv->frm_cnt==14) | 1198 | if (gv->need_compact==TRUE ) //|| gv->word_backtrace==FALSE) //if (gv->evalstat.beam.cur_pos > 1000) //if (gv->frm_cnt==14) |
1161 | { | 1199 | { |
1162 | mark_cells_state(state_cell->frm, state_cell->sym, gv, last_frm); | 1200 | mark_cells_state( frm, state_cell->sym, gv, last_frm); |
1163 | } | 1201 | } |
1164 | last_FRM = state_cell->frm; last_SYM = state_cell->sym; | 1202 | last_FRM = frm; last_SYM = state_cell->sym; |
1165 | } | 1203 | } |
1166 | } | 1204 | } |
1167 | 1205 | ||
@@ -1175,11 +1213,13 @@ static short | |||
1175 | #ifdef MODEL_LEVEL_PRUNE | 1213 | #ifdef MODEL_LEVEL_PRUNE |
1176 | mlp_update(gv, hmmcode , scr); | 1214 | mlp_update(gv, hmmcode , scr); |
1177 | #endif | 1215 | #endif |
1178 | 1216 | /* Check if there is a transition to the exit state. */ | |
1179 | if ( *trnprob > BAD_SCR ) { /* exit? */ | 1217 | if ( *trnprob > BAD_SCR ) { |
1180 | 1218 | ||
1181 | scr = (long) state_cell->scr + (long) *trnprob; | 1219 | scr = (long) state_cell->scr + (long) *trnprob; |
1182 | 1220 | ||
1221 | /* Viterbi decode here for the highest likelihood state transition | ||
1222 | to the exit state.*/ | ||
1183 | if ( scr > (long) max_exit_scr) { | 1223 | if ( scr > (long) max_exit_scr) { |
1184 | max_exit_scr = (short) scr; | 1224 | max_exit_scr = (short) scr; |
1185 | max_exit_state = state_cell; | 1225 | max_exit_state = state_cell; |
@@ -1192,11 +1232,14 @@ static short | |||
1192 | else { /* exit state */ | 1232 | else { /* exit state */ |
1193 | sumdepth+=sym_cell->depth; n_actsym++; | 1233 | sumdepth+=sym_cell->depth; n_actsym++; |
1194 | maxdepth=sym_cell->depth> maxdepth?sym_cell->depth: maxdepth; | 1234 | maxdepth=sym_cell->depth> maxdepth?sym_cell->depth: maxdepth; |
1195 | 1235 | ||
1236 | /* If a valid transition to the exit state exists, update the exit | ||
1237 | state cell with the information corresponding to the highest | ||
1238 | likelihood exit transition. */ | ||
1196 | if ( max_exit_scr > BAD_SCR ) { | 1239 | if ( max_exit_scr > BAD_SCR ) { |
1197 | state_cell->scr = max_exit_scr; | 1240 | state_cell->scr = max_exit_scr; |
1198 | state_cell->sym = max_exit_state->sym; | 1241 | state_cell->sym = max_exit_state->sym; |
1199 | state_cell->frm = max_exit_state->frm; | 1242 | state_cell->frm = STATE_FRM(max_exit_state->frm); |
1200 | 1243 | ||
1201 | /*if end of sym, put it in the beam cell list*/ | 1244 | /*if end of sym, put it in the beam cell list*/ |
1202 | // word end label, grow beam cell | 1245 | // word end label, grow beam cell |
@@ -1257,7 +1300,7 @@ init_search(short mfcc_feature[], short cur_idx, gmhmm_type *gv, unsigned short | |||
1257 | short status, n_state, pdf_idx, *startprob, *trnprob, first_time_call = TRUE; | 1300 | short status, n_state, pdf_idx, *startprob, *trnprob, first_time_call = TRUE; |
1258 | EvalIdx *eval_idx = gv->eval+cur_idx; | 1301 | EvalIdx *eval_idx = gv->eval+cur_idx; |
1259 | 1302 | ||
1260 | 1303 | ||
1261 | #ifdef SHOW_DIAGONISIS | 1304 | #ifdef SHOW_DIAGONISIS |
1262 | sttnode=0; | 1305 | sttnode=0; |
1263 | global_count=0; | 1306 | global_count=0; |
@@ -1309,10 +1352,13 @@ init_search(short mfcc_feature[], short cur_idx, gmhmm_type *gv, unsigned short | |||
1309 | return eTIesrEngineEvalCellOverflow; | 1352 | return eTIesrEngineEvalCellOverflow; |
1310 | } | 1353 | } |
1311 | 1354 | ||
1312 | for (j = 0; j < n_state - 1; j++) { /* for all emit states . */ | 1355 | /* For all emitting states */ |
1313 | 1356 | for (j = 0; j < n_state - 1; j++) { | |
1314 | if ( startprob[ j ] > BAD_SCR ) { /* locate inititial stateS */ | 1357 | |
1358 | /* Check if state has initial entry probability */ | ||
1359 | if ( startprob[ j ] > BAD_SCR ) { | ||
1315 | 1360 | ||
1361 | /* Determine initial state likelihood score */ | ||
1316 | pdf_idx = hmm->pdf_idx[ j ]; | 1362 | pdf_idx = hmm->pdf_idx[ j ]; |
1317 | 1363 | ||
1318 | /* if (gv->obs_scr[ pdf_idx ] == 0 ) // a cache in computing. | 1364 | /* if (gv->obs_scr[ pdf_idx ] == 0 ) // a cache in computing. |
@@ -1329,15 +1375,16 @@ init_search(short mfcc_feature[], short cur_idx, gmhmm_type *gv, unsigned short | |||
1329 | else state_cell[ j ].scr = (short) scr; | 1375 | else state_cell[ j ].scr = (short) scr; |
1330 | 1376 | ||
1331 | if ( scr > (long) gv->best_cur_scr ) | 1377 | if ( scr > (long) gv->best_cur_scr ) |
1332 | { | 1378 | { |
1333 | gv->best_cur_scr = (short) scr; /*first frame only*/ | 1379 | gv->best_cur_scr = (short) scr; /*first frame only*/ |
1334 | 1380 | ||
1335 | } | 1381 | } |
1336 | 1382 | ||
1337 | #ifdef MODEL_LEVEL_PRUNE | 1383 | #ifdef MODEL_LEVEL_PRUNE |
1338 | mlp_update(gv, hmmcode , scr); | 1384 | mlp_update(gv, hmmcode , scr); |
1339 | #endif | 1385 | #endif |
1340 | 1386 | /* If a transition from state to exit state exists, determine its | |
1387 | likelihood.*/ | ||
1341 | if ( trnprob[ j * n_state + exit_state ] > BAD_SCR ) { | 1388 | if ( trnprob[ j * n_state + exit_state ] > BAD_SCR ) { |
1342 | scr = (long) state_cell[ j ].scr + | 1389 | scr = (long) state_cell[ j ].scr + |
1343 | (long) trnprob[ j * n_state + exit_state ]; | 1390 | (long) trnprob[ j * n_state + exit_state ]; |
@@ -1346,16 +1393,19 @@ init_search(short mfcc_feature[], short cur_idx, gmhmm_type *gv, unsigned short | |||
1346 | max_exit_scr = (short) scr; /*track the best score to exit the sym*/ | 1393 | max_exit_scr = (short) scr; /*track the best score to exit the sym*/ |
1347 | } | 1394 | } |
1348 | } | 1395 | } |
1349 | state_cell[ j ].frm = USHRT_MAX; /*the 4 lines below say : there is no prior sym and frame*/ | 1396 | |
1397 | /* Set prior symbol and frame for the state to invalid values indicating | ||
1398 | beginning of search. */ | ||
1399 | state_cell[ j ].frm = UNDEFINEDTIME; | ||
1350 | state_cell[ j ].sym = USHRT_MAX; | 1400 | state_cell[ j ].sym = USHRT_MAX; |
1351 | } /* end of all emiting states */ | 1401 | } /* end of all emiting states */ |
1352 | 1402 | ||
1353 | state_cell[ exit_state ].frm = USHRT_MAX; | 1403 | /* Set prior symbol and frame of exit state to invalid values */ |
1404 | state_cell[ exit_state ].frm = UNDEFINEDTIME; | ||
1354 | state_cell[ exit_state ].sym = USHRT_MAX; | 1405 | state_cell[ exit_state ].sym = USHRT_MAX; |
1355 | 1406 | ||
1356 | /* HMM (sym) completed, create a backtrace cell */ | 1407 | /* If valid likelihood of exit, update exit state likelihood score. */ |
1357 | 1408 | if ( max_exit_scr > BAD_SCR ) { | |
1358 | if ( max_exit_scr > BAD_SCR ) { /* if can be end of symbol, but sure not for first frame. so why here ? */ | ||
1359 | state_cell[ exit_state ].scr = max_exit_scr; | 1409 | state_cell[ exit_state ].scr = max_exit_scr; |
1360 | 1410 | ||
1361 | 1411 | ||
@@ -1363,19 +1413,18 @@ init_search(short mfcc_feature[], short cur_idx, gmhmm_type *gv, unsigned short | |||
1363 | //status = grow_beam_cell(VTL_SYM(t_symcode, sym_dlt), state_cell + exit_state, first_time_call, 0, | 1413 | //status = grow_beam_cell(VTL_SYM(t_symcode, sym_dlt), state_cell + exit_state, first_time_call, 0, |
1364 | // gv, last_frm); | 1414 | // gv, last_frm); |
1365 | gv->ending_sym_count ++; | 1415 | gv->ending_sym_count ++; |
1366 | if (psym->n_next & 0x8000 || gv->word_backtrace!=WORDBT) //never should happen in word bt | 1416 | |
1367 | { | 1417 | /* Add the symbol/prior info of the exit state to the beam cell linked |
1368 | status = grow_beam_cell(VTL_SYM(t_symcode, sym_dlt), state_cell + exit_state, first_time_call, 0, | 1418 | list for this frame if HMM is word ending or if HMM backtrace requested */ |
1419 | if (psym->n_next & 0x8000 || gv->word_backtrace!=WORDBT) | ||
1420 | { | ||
1421 | status = grow_beam_cell(VTL_SYM(t_symcode, sym_dlt), state_cell + exit_state, first_time_call, 0, | ||
1369 | gv, last_frm); | 1422 | gv, last_frm); |
1370 | first_time_call = FALSE; //first time to call beam cell stuff -- for this frame! | 1423 | first_time_call = FALSE; //first time to call beam cell stuff -- for this frame! |
1371 | gv->beam_count++; | 1424 | gv->beam_count++; |
1372 | if ( status != eTIesrEngineSuccess ) | 1425 | if ( status != eTIesrEngineSuccess ) |
1373 | return status; | 1426 | return status; |
1374 | } | 1427 | } |
1375 | |||
1376 | |||
1377 | |||
1378 | |||
1379 | } | 1428 | } |
1380 | } | 1429 | } |
1381 | } | 1430 | } |