Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00042 #ifndef __NGRAM_SEARCH_H__
00043 #define __NGRAM_SEARCH_H__
00044
00045
00046 #include <cmd_ln.h>
00047 #include <logmath.h>
00048 #include <ngram_model.h>
00049 #include <listelem_alloc.h>
00050
00051
00052 #include "pocketsphinx_internal.h"
00053 #include "hmm.h"
00054
00063 typedef struct chan_s {
00064 hmm_t hmm;
00067 struct chan_s *next;
00070 struct chan_s *alt;
00072 int32 ciphone;
00073 union {
00074 int32 penult_phn_wid;
00078 int32 rc_id;
00079 } info;
00080 } chan_t;
00081
00089 typedef struct root_chan_s {
00090 hmm_t hmm;
00093 chan_t *next;
00095 int32 penult_phn_wid;
00096 int32 this_phn_wid;
00099 int16 diphone;
00101 int16 ciphone;
00103 } root_chan_t;
00104
00108 typedef struct bptbl_s {
00109 int16 frame;
00110 uint8 valid;
00111 uint8 reserved;
00112 int32 wid;
00113 int32 bp;
00114 int32 score;
00115 int32 s_idx;
00116 int32 real_wid;
00117 int32 prev_real_wid;
00118 int32 r_diph;
00119 int32 ascr;
00120 int32 lscr;
00121 } bptbl_t;
00122
00126 typedef struct bptbl_seg_s {
00127 ps_seg_t base;
00128 int32 *bpidx;
00129 int16 n_bpidx;
00130 int16 cur;
00131 } bptbl_seg_t;
00132
00133
00134
00135
00136
00137
00138 typedef struct lastphn_cand_s {
00139 int32 wid;
00140 int32 score;
00141 int32 bp;
00142 int32 next;
00143 } lastphn_cand_t;
00144
00145
00146
00147
00148
00149
00150
00151 typedef struct {
00152 int32 sf;
00153 int32 dscr;
00154 int32 bp;
00155 } last_ltrans_t;
00156
00157 #define CAND_SF_ALLOCSIZE 32
00158 typedef struct {
00159 int32 bp_ef;
00160 int32 cand;
00161 } cand_sf_t;
00162
00163
00164
00165
00166
00167
00168
00169 typedef struct bestbp_rc_s {
00170 int32 score;
00171 int32 path;
00172 int32 lc;
00173 } bestbp_rc_t;
00174
00175 #define NO_BP -1
00176
00180 typedef struct ngram_search_stats_s {
00181 int32 n_phone_eval;
00182 int32 n_root_chan_eval;
00183 int32 n_nonroot_chan_eval;
00184 int32 n_last_chan_eval;
00185 int32 n_word_lastchan_eval;
00186 int32 n_lastphn_cand_utt;
00187 int32 n_fwdflat_chan;
00188 int32 n_fwdflat_words;
00189 int32 n_fwdflat_word_transition;
00190 int32 n_senone_active_utt;
00191 } ngram_search_stats_t;
00192
00193
00197 struct ngram_search_s {
00198 ps_search_t base;
00199 ngram_model_t *lmset;
00200 hmm_context_t *hmmctx;
00202
00203 uint8 fwdtree;
00204 uint8 fwdflat;
00205 uint8 bestpath;
00206
00207
00208 uint8 done;
00209
00210
00211 listelem_alloc_t *chan_alloc;
00212 listelem_alloc_t *root_chan_alloc;
00213 listelem_alloc_t *latnode_alloc;
00231 root_chan_t *root_chan;
00232 int32 n_root_chan_alloc;
00233 int32 n_root_chan;
00234 int32 n_nonroot_chan;
00235 int32 max_nonroot_chan;
00236 int32 *first_phone_rchan_map;
00237 root_chan_t *rhmm_1ph;
00247 chan_t **word_chan;
00248 bitvec_t *word_active;
00264 int32 *homophone_set;
00265 int32 *single_phone_wid;
00266 int32 n_1ph_words;
00267 int32 n_1ph_LMwords;
00276 chan_t ***active_chan_list;
00277 int32 n_active_chan[2];
00288 int32 **active_word_list;
00289 int32 n_active_word[2];
00291
00292
00293
00294 lastphn_cand_t *lastphn_cand;
00295 int32 n_lastphn_cand;
00296 last_ltrans_t *last_ltrans;
00297 int32 cand_sf_alloc;
00298 cand_sf_t *cand_sf;
00299 bestbp_rc_t *bestbp_rc;
00300
00301 bptbl_t *bp_table;
00302 int32 bpidx;
00303 int32 bp_table_size;
00304 int32 *bscore_stack;
00305 int32 bss_head;
00306 int32 bscore_stack_size;
00307
00308 int32 n_frame_alloc;
00309 int32 n_frame;
00310 int32 *bp_table_idx;
00311 int32 *word_lat_idx;
00312
00313
00314 uint16 *zeroPermTab;
00317
00318
00319
00320 ps_latnode_t **frm_wordlist;
00321 int32 *fwdflat_wordlist;
00322 bitvec_t *expand_word_flag;
00323 int32 *expand_word_list;
00324 int32 n_expand_words;
00325 int32 min_ef_width;
00326 int32 max_sf_win;
00327 float32 fwdflat_fwdtree_lw_ratio;
00328
00329 int32 best_score;
00330 int32 last_phone_best_score;
00331 int32 renormalized;
00332
00333
00334
00335
00336 float32 bestpath_fwdtree_lw_ratio;
00337 float32 ascale;
00339 ngram_search_stats_t st;
00341
00342 int32 beam;
00343 int32 dynamic_beam;
00344 int32 pbeam;
00345 int32 wbeam;
00346 int32 lpbeam;
00347 int32 lponlybeam;
00348 int32 fwdflatbeam;
00349 int32 fwdflatwbeam;
00350 int32 fillpen;
00351 int32 silpen;
00352 int32 wip;
00353 int32 nwpen;
00354 int32 pip;
00355 int32 maxwpf;
00356 int32 maxhmmpf;
00357 };
00358 typedef struct ngram_search_s ngram_search_t;
00359
00363 ps_search_t *ngram_search_init(cmd_ln_t *config,
00364 acmod_t *acmod,
00365 dict_t *dict);
00366
00370 void ngram_search_free(ps_search_t *ngs);
00371
00377 int ngram_search_mark_bptable(ngram_search_t *ngs, int frame_idx);
00378
00382 void ngram_search_save_bp(ngram_search_t *ngs, int frame_idx, int32 w,
00383 int32 score, int32 path, int32 rc);
00384
00388 void ngram_search_alloc_all_rc(ngram_search_t *ngs, int32 w);
00389
00393 void ngram_search_free_all_rc(ngram_search_t *ngs, int32 w);
00394
00400 int ngram_search_find_exit(ngram_search_t *ngs, int frame_idx, int32 *out_best_score);
00401
00407 char const *ngram_search_bp_hyp(ngram_search_t *ngs, int bpidx);
00408
00412 void ngram_compute_seg_scores(ngram_search_t *ngs, float32 lwf);
00413
00417 ps_lattice_t *ngram_search_lattice(ps_search_t *search);
00418
00419 #endif