libjulius/src/m_chkparam.c

Go to the documentation of this file.
00001 
00026 /*
00027  * Copyright (c) 1991-2007 Kawahara Lab., Kyoto University
00028  * Copyright (c) 2000-2005 Shikano Lab., Nara Institute of Science and Technology
00029  * Copyright (c) 2005-2007 Julius project team, Nagoya Institute of Technology
00030  * All rights reserved
00031  */
00032 
00033 #include <julius/julius.h>
00034 
00048 boolean
00049 checkpath(char *filename)
00050 {
00051   if (access(filename, R_OK) == -1) {
00052     jlog("ERROR: m_chkparam: cannot access %s\n", filename);
00053     return FALSE;
00054   }
00055   return TRUE;
00056 }
00057 
00094 boolean
00095 j_jconf_finalize(Jconf *jconf)
00096 {
00097   boolean ok_p;
00098   JCONF_LM *lm;
00099   JCONF_AM *am;
00100   JCONF_SEARCH *s, *hs;
00101 
00102   ok_p = TRUE;
00103 
00104   /* update and tailor configuration */
00105   /* if a search config has progout_flag enabled, set it to all config */
00106   hs = NULL;
00107   for(s=jconf->search_root;s;s=s->next) {
00108     if (s->output.progout_flag) {
00109       hs = s;
00110       break;
00111     }
00112   }
00113   if (hs != NULL) {
00114     for(s=jconf->search_root;s;s=s->next) {
00115       s->output.progout_flag = hs->output.progout_flag;
00116       s->output.progout_interval = hs->output.progout_interval;
00117     }
00118   }
00119       
00120   /* if an instance has short-pause segmentation enabled,
00121      set it to global opt for parameter handling
00122      (only a recognizer with this option will decide the segmentation,
00123       but the segmentation should be synchronized for all the recognizer)
00124   */
00125   for(s=jconf->search_root;s;s=s->next) {
00126     if (s->successive.enabled) {
00127       jconf->decodeopt.segment = TRUE;
00128       break;
00129     }
00130   }
00131 #ifdef GMM_VAD
00132   /* if GMM VAD enabled, set it to global */
00133   if (jconf->reject.gmm_filename) {
00134     jconf->decodeopt.segment = TRUE;
00135   }
00136 #endif
00137 
00138   for(lm = jconf->lm_root; lm; lm = lm->next) {
00139     if (lm->lmtype == LM_UNDEF) {
00140       /* determine LM type from the specified LM files */
00141       if (lm->ngram_filename_lr_arpa || lm->ngram_filename_rl_arpa || lm->ngram_filename) {
00142         /* n-gram specified */
00143         lm->lmtype = LM_PROB;
00144         lm->lmvar  = LM_NGRAM;
00145       }
00146       if (lm->gramlist_root) {
00147         /* DFA grammar specified */
00148         if (lm->lmtype != LM_UNDEF) {
00149           jlog("ERROR: m_chkparam: LM conflicts: several LM of different type specified?\n");
00150           return FALSE;
00151         }
00152         lm->lmtype = LM_DFA;
00153         lm->lmvar  = LM_DFA_GRAMMAR;
00154       }
00155       if (lm->dfa_filename) {
00156         /* DFA grammar specified by "-dfa" */
00157         if (lm->lmtype != LM_UNDEF && lm->lmvar != LM_DFA_GRAMMAR) {
00158           jlog("ERROR: m_chkparam: LM conflicts: several LM of different type specified?\n");
00159           return FALSE;
00160         }
00161         lm->lmtype = LM_DFA;
00162         lm->lmvar  = LM_DFA_GRAMMAR;
00163       }
00164       if (lm->wordlist_root) {
00165         /* word list specified */
00166         if (lm->lmtype != LM_UNDEF) {
00167           jlog("ERROR: m_chkparam: LM conflicts: several LM of different type specified?\n");
00168           return FALSE;
00169         }
00170         lm->lmtype = LM_DFA;
00171         lm->lmvar  = LM_DFA_WORD;
00172       }
00173     }
00174     if (lm->lmtype == LM_PROB) {
00175       if (lm->dictfilename == NULL) {
00176         jlog("ERROR: m_chkparam: needs dictionary file (-v dict_file)\n");
00177         ok_p = FALSE;
00178       }
00179     }
00180     /* file existence check */
00181     if (lm->dictfilename != NULL) 
00182       if (!checkpath(lm->dictfilename)) ok_p = FALSE;
00183     if (lm->ngram_filename != NULL) 
00184       if (!checkpath(lm->ngram_filename)) ok_p = FALSE;
00185     if (lm->ngram_filename_lr_arpa != NULL)
00186       if (!checkpath(lm->ngram_filename_lr_arpa)) ok_p = FALSE;
00187     if (lm->ngram_filename_rl_arpa != NULL)
00188       if (!checkpath(lm->ngram_filename_rl_arpa)) ok_p = FALSE;
00189     if (lm->dfa_filename != NULL) 
00190       if (!checkpath(lm->dfa_filename)) ok_p = FALSE;
00191   }
00192 
00193   for(am = jconf->am_root; am; am = am->next) {
00194     /* check if needed files are specified */
00195     if (am->hmmfilename == NULL) {
00196       jlog("ERROR: m_chkparam: needs HMM definition file (-h hmmdef_file)\n");
00197       ok_p = FALSE;
00198     }
00199     /* file existence check */
00200     if (am->hmmfilename != NULL) 
00201       if (!checkpath(am->hmmfilename)) ok_p = FALSE;
00202     if (am->mapfilename != NULL) 
00203       if (!checkpath(am->mapfilename)) ok_p = FALSE;
00204     if (am->hmm_gs_filename != NULL) 
00205       if (!checkpath(am->hmm_gs_filename)) ok_p = FALSE;
00206     /* cmn{save,load}_filename allows missing file (skipped if missing) */
00207     if (am->frontend.ssload_filename != NULL) 
00208       if (!checkpath(am->frontend.ssload_filename)) ok_p = FALSE;
00209   }
00210   if (jconf->reject.gmm_filename != NULL) 
00211     if (!checkpath(jconf->reject.gmm_filename)) ok_p = FALSE;
00212   if (jconf->input.inputlist_filename != NULL) {
00213     if (jconf->input.speech_input != SP_RAWFILE && jconf->input.speech_input != SP_MFCFILE) {
00214       jlog("WARNING: m_chkparam: not file input, \"-filelist %s\" ignored\n", jconf->input.inputlist_filename);
00215     } else {
00216       if (!checkpath(jconf->input.inputlist_filename)) ok_p = FALSE;
00217     }
00218   }
00219 
00220   /* set default realtime flag according to input mode */
00221   if (jconf->decodeopt.force_realtime_flag) {
00222     if (jconf->input.speech_input == SP_MFCFILE) {
00223       jlog("WARNING: m_chkparam: realtime decoding of mfcfile is not supported yet\n");
00224       jlog("WARNING: m_chkparam: realtime turned off\n");
00225       jconf->decodeopt.realtime_flag = FALSE;
00226     } else {
00227       jconf->decodeopt.realtime_flag = jconf->decodeopt.forced_realtime;
00228     }
00229   }
00230 
00231   /* check for cmn */
00232   if (jconf->decodeopt.realtime_flag) {
00233     for(am = jconf->am_root; am; am = am->next) {
00234       if (am->analysis.cmn_update == FALSE && am->analysis.cmnload_filename == NULL) {
00235         jlog("ERROR: m_chkparam: when \"-cmnnoupdate\", initial cepstral mean should be given by \"-cmnload\"\n");
00236         ok_p = FALSE;
00237       }
00238     }
00239   }
00240 
00241   /* set values for search config */
00242   for(s=jconf->search_root;s;s=s->next) {
00243     lm = s->lmconf;
00244     am = s->amconf;
00245 
00246     /* force context dependency handling flag for word-recognition mode */
00247     if (lm->lmtype == LM_DFA && lm->lmvar == LM_DFA_WORD) {
00248       /* disable inter-word context dependent handling ("-no_ccd") */
00249       s->ccd_handling = FALSE;
00250       s->force_ccd_handling = TRUE;
00251       /* force 1pass ("-1pass") */
00252       s->compute_only_1pass = TRUE;
00253     }
00254 
00255     /* set default iwcd1 method from lm */
00256     /* WARNING: THIS WILL BEHAVE WRONG IF MULTIPLE LM TYPE SPECIFIED */
00257     /* RECOMMEND USING EXPLICIT OPTION */
00258     if (am->iwcdmethod == IWCD_UNDEF) {
00259       switch(lm->lmtype) {
00260       case LM_PROB:
00261         am->iwcdmethod = IWCD_NBEST; break;
00262       case LM_DFA:
00263         am->iwcdmethod = IWCD_AVG; break;
00264       }
00265     }
00266 
00267   }
00268 
00269   /* check option validity with the current lm type */
00270   /* just a warning message for user */
00271   for(s=jconf->search_root;s;s=s->next) {
00272     lm = s->lmconf;
00273     am = s->amconf;
00274     if (lm->lmtype != LM_PROB) {
00275       /* in case not a probabilistic model */
00276       if (s->lmp.lmp_specified) {
00277         jlog("WARNING: m_chkparam: \"-lmp\" only for N-gram, ignored\n");
00278       }
00279       if (s->lmp.lmp2_specified) {
00280         jlog("WARNING: m_chkparam: \"-lmp2\" only for N-gram, ignored\n");
00281       }
00282       if (s->lmp.lm_penalty_trans != 0.0) {
00283         jlog("WARNING: m_chkparam: \"-transp\" only for N-gram, ignored\n");
00284       }
00285       if (lm->head_silname && !strmatch(lm->head_silname, BEGIN_WORD_DEFAULT)) {
00286         jlog("WARNING: m_chkparam: \"-silhead\" only for N-gram, ignored\n");
00287       }
00288       if (lm->tail_silname && !strmatch(lm->tail_silname, END_WORD_DEFAULT)) {
00289         jlog("WARNING: m_chkparam: \"-siltail\" only for N-gram, ignored\n");
00290       }
00291       if (lm->enable_iwspword) {
00292         jlog("WARNING: m_chkparam: \"-iwspword\" only for N-gram, ignored\n");
00293       }
00294       if (lm->iwspentry && !strmatch(lm->iwspentry, IWSPENTRY_DEFAULT)) {
00295         jlog("WARNING: m_chkparam: \"-iwspentry\" only for N-gram, ignored\n");
00296       }
00297 #ifdef HASH_CACHE_IW
00298       if (s->pass1.iw_cache_rate != 10) {
00299         jlog("WARNING: m_chkparam: \"-iwcache\" only for N-gram, ignored\n");
00300       }
00301 #endif
00302 #ifdef SEPARATE_BY_UNIGRAM
00303       if (lm->separate_wnum != 150) {
00304         jlog("WARNING: m_chkparam: \"-sepnum\" only for N-gram, ignored\n");
00305       }
00306 #endif
00307     }  
00308     if (lm->lmtype != LM_DFA) {
00309       /* in case not a deterministic model */
00310       if (s->pass2.looktrellis_flag) {
00311         jlog("WARNING: m_chkparam: \"-looktrellis\" only for grammar, ignored\n");
00312       }
00313       if (s->output.multigramout_flag) {
00314         jlog("WARNING: m_chkparam: \"-multigramout\" only for grammar, ignored\n");
00315       }
00316       if (s->lmp.penalty1 != 0.0) {
00317         jlog("WARNING: m_chkparam: \"-penalty1\" only for grammar, ignored\n");
00318       }
00319       if (s->lmp.penalty2 != 0.0) {
00320         jlog("WARNING: m_chkparam: \"-penalty2\" only for grammar, ignored\n");
00321       }
00322     }
00323   }
00324 
00325 
00326 
00327   if (!ok_p) {
00328     jlog("ERROR: m_chkparam: could not pass parameter check\n");
00329   } else {
00330     jlog("STAT: jconf successfully finalized\n");
00331   }
00332 
00333   if (debug2_flag) {
00334     print_jconf_overview(jconf);
00335   }
00336 
00337   return ok_p;
00338 }
00339 
00364 static int
00365 default_width(HTK_HMM_INFO *hmminfo)
00366 {
00367   if (strmatch(JULIUS_SETUP, "fast")) { /* for fast setup */
00368     if (hmminfo->is_triphone) {
00369       if (hmminfo->is_tied_mixture) {
00370         /* tied-mixture triphones (PTM etc.) */
00371         return(600);
00372       } else {
00373         /* shared-state triphone */
00374 #ifdef PASS1_IWCD
00375         return(800);
00376 #else
00377         /* v2.1 compliant (no IWCD on 1st pass) */
00378         return(1000);           
00379 #endif
00380       }
00381     } else {
00382       /* monophone */
00383       return(400);
00384     }
00385   } else {                      /* for standard / v2.1 setup */
00386     if (hmminfo->is_triphone) {
00387       if (hmminfo->is_tied_mixture) {
00388         /* tied-mixture triphones (PTM etc.) */
00389         return(800);
00390       } else {
00391         /* shared-state triphone */
00392 #ifdef PASS1_IWCD
00393         return(1500);
00394 #else
00395         return(1500);           /* v2.1 compliant (no IWCD on 1st pass) */
00396 #endif
00397       }
00398     } else {
00399       /* monophone */
00400       return(700);
00401     }
00402   }
00403 }
00404 
00432 int
00433 set_beam_width(WCHMM_INFO *wchmm, int specified)
00434 {
00435   int width;
00436   int standard_width;
00437   
00438   if (specified == 0) { /* full search */
00439     jlog("WARNING: doing full search (can be extremely slow)\n");
00440     width = wchmm->n;
00441   } else if (specified == -1) { /* not specified */
00442     standard_width = default_width(wchmm->hmminfo); /* system default */
00443     width = (int)(sqrt(wchmm->winfo->num) * 15.0); /* heuristic value!! */
00444     if (width > standard_width) width = standard_width;
00445     /* 2007/1/20 bgn */
00446     if (width < MINIMAL_BEAM_WIDTH) {
00447       width = MINIMAL_BEAM_WIDTH;
00448     }
00449     /* 2007/1/20 end */
00450   } else {                      /* actual value has been specified */
00451     width = specified;
00452   }
00453   if (width > wchmm->n) width = wchmm->n;
00454 
00455   return(width);
00456 }
00457 
00458 /* end of file */

Generated on Tue Dec 18 15:59:52 2007 for Julius by  doxygen 1.5.4