Ejemplo n.º 1
0
ps_search_t *
state_align_search_init(const char *name,
                        cmd_ln_t *config,
                        acmod_t *acmod,
                        ps_alignment_t *al)
{
    state_align_search_t *sas;
    ps_alignment_iter_t *itor;
    hmm_t *hmm;

    sas = ckd_calloc(1, sizeof(*sas));
    ps_search_init(ps_search_base(sas), &state_align_search_funcs,
		   PS_SEARCH_TYPE_STATE_ALIGN, name,
                   config, acmod, al->d2p->dict, al->d2p);
    sas->hmmctx = hmm_context_init(bin_mdef_n_emit_state(acmod->mdef),
                                   acmod->tmat->tp, NULL, acmod->mdef->sseq);
    if (sas->hmmctx == NULL) {
        ckd_free(sas);
        return NULL;
    }
    sas->al = al;

    /* Generate HMM vector from phone level of alignment. */
    sas->n_phones = ps_alignment_n_phones(al);
    sas->n_emit_state = ps_alignment_n_states(al);
    sas->hmms = ckd_calloc(sas->n_phones, sizeof(*sas->hmms));
    for (hmm = sas->hmms, itor = ps_alignment_phones(al); itor;
         ++hmm, itor = ps_alignment_iter_next(itor)) {
        ps_alignment_entry_t *ent = ps_alignment_iter_get(itor);
        hmm_init(sas->hmmctx, hmm, FALSE,
                 ent->id.pid.ssid, ent->id.pid.tmatid);
    }
    return ps_search_base(sas);
}
static int
phone_loop_search_reinit(ps_search_t *search, dict_t *dict, dict2pid_t *d2p)
{
    phone_loop_search_t *pls = (phone_loop_search_t *)search;
    cmd_ln_t *config = ps_search_config(search);
    acmod_t *acmod = ps_search_acmod(search);
    int i;

    /* Free old dict2pid, dict, if necessary. */
    ps_search_base_reinit(search, dict, d2p);

    /* Initialize HMM context. */
    if (pls->hmmctx)
        hmm_context_free(pls->hmmctx);
    pls->hmmctx = hmm_context_init(bin_mdef_n_emit_state(acmod->mdef),
                                   acmod->tmat->tp, NULL, acmod->mdef->sseq);
    if (pls->hmmctx == NULL)
        return -1;

    /* Initialize penalty storage */
    pls->n_phones = bin_mdef_n_ciphone(acmod->mdef);
    pls->window = cmd_ln_int32_r(config, "-pl_window");
    if (pls->penalties)
        ckd_free(pls->penalties);
    pls->penalties = (int32 *)ckd_calloc(pls->n_phones, sizeof(*pls->penalties));
    if (pls->pen_buf)
        ckd_free_2d(pls->pen_buf);
    pls->pen_buf = (int32 **)ckd_calloc_2d(pls->window, pls->n_phones, sizeof(**pls->pen_buf));

    /* Initialize phone HMMs. */
    if (pls->hmms) {
        for (i = 0; i < pls->n_phones; ++i)
            hmm_deinit((hmm_t *)&pls->hmms[i]);
        ckd_free(pls->hmms);
    }
    pls->hmms = (hmm_t *)ckd_calloc(pls->n_phones, sizeof(*pls->hmms));
    for (i = 0; i < pls->n_phones; ++i) {
        hmm_init(pls->hmmctx, (hmm_t *)&pls->hmms[i],
                 FALSE,
                 bin_mdef_pid2ssid(acmod->mdef, i),
                 bin_mdef_pid2tmatid(acmod->mdef, i));
    }
    pls->penalty_weight = cmd_ln_float64_r(config, "-pl_weight");
    pls->beam = logmath_log(acmod->lmath, cmd_ln_float64_r(config, "-pl_beam")) >> SENSCR_SHIFT;
    pls->pbeam = logmath_log(acmod->lmath, cmd_ln_float64_r(config, "-pl_pbeam")) >> SENSCR_SHIFT;
    pls->pip = logmath_log(acmod->lmath, cmd_ln_float32_r(config, "-pl_pip")) >> SENSCR_SHIFT;
    E_INFO("State beam %d Phone exit beam %d Insertion penalty %d\n",
           pls->beam, pls->pbeam, pls->pip);

    return 0;
}
Ejemplo n.º 3
0
int
main(int argc, char *argv[])
{
	dict_t *dict;
	dict2pid_t *d2p;
	bin_mdef_t *mdef;
	glextree_t *tree;
	hmm_context_t *ctx;
	logmath_t *lmath;
	tmat_t *tmat;
	int i;

	TEST_ASSERT(mdef = bin_mdef_read(NULL, MODELDIR "/hmm/en_US/hub4wsj_sc_8k/mdef"));
	TEST_ASSERT(dict = dict_init(cmd_ln_init(NULL, NULL, FALSE,
						 "-dict", DATADIR "/turtle.dic",
						 "-dictcase", "no", NULL),
				       mdef));
	TEST_ASSERT(d2p = dict2pid_build(mdef, dict));
	lmath = logmath_init(1.0001, 0, TRUE);
	tmat = tmat_init(MODELDIR "/hmm/en_US/hub4wsj_sc_8k/transition_matrices",
			 lmath, 1e-5, TRUE);
	ctx = hmm_context_init(bin_mdef_n_emit_state(mdef), tmat->tp, NULL, mdef->sseq);
	TEST_ASSERT(tree = glextree_build(ctx, dict, d2p, NULL, NULL));

	/* Check that a path exists for all dictionary words. */
	for (i = 0; i < dict_size(dict); ++i)
		TEST_ASSERT(glextree_has_word(tree, i));

	dict_free(dict);
	dict2pid_free(d2p);
	bin_mdef_free(mdef);
	tmat_free(tmat);
	hmm_context_free(ctx);
	glextree_free(tree);
	return 0;
}
Ejemplo n.º 4
0
int
srch_FLAT_FWD_init(kb_t * kb,    /**< The KB */
                   void *srch     /**< The pointer to a search structure */
    )
{
    srch_FLAT_FWD_graph_t *fwg;
    kbcore_t *kbc;
    srch_t *s;
    mdef_t *mdef;
    dict_t *dict;
    lm_t *lm;

    kbc = kb->kbcore;
    s = (srch_t *) srch;
    mdef = kbcore_mdef(kbc);
    dict = kbcore_dict(kbc);
    lm = kbcore_lm(kbc);


    fwg = ckd_calloc(1, sizeof(srch_FLAT_FWD_graph_t));

    E_INFO("Initialization\n");

    /** For convenience */
    fwg->kbcore = s->kbc;

    /* Allocate whmm structure */
    fwg->hmmctx = hmm_context_init(mdef_n_emit_state(mdef),
				   kbcore_tmat(kbc)->tp, NULL,
				   mdef->sseq);
    fwg->whmm = (whmm_t **) ckd_calloc(dict->n_word, sizeof(whmm_t *));

    /* Data structures needed during word transition */
    /* These five things need to be tied into the same structure.  Such that when multiple LM they could be switched.  */
    fwg->rcscore = NULL;
    fwg->rcscore = (int32 *) ckd_calloc(mdef->n_ciphone, sizeof(int32));
    fwg->ug_backoff =
        (backoff_t *) ckd_calloc(mdef->n_ciphone, sizeof(backoff_t));
    fwg->filler_backoff =
        (backoff_t *) ckd_calloc(mdef->n_ciphone, sizeof(backoff_t));
    fwg->tg_trans_done = (uint8 *) ckd_calloc(dict->n_word, sizeof(uint8));
    fwg->word_ugprob = init_word_ugprob(mdef, lm, dict);

    /* Input candidate-word lattices information to restrict search; if any */
    fwg->word_cand_dir = cmd_ln_str_r(kbcore_config(fwg->kbcore), "-inlatdir");
    fwg->latfile_ext = cmd_ln_str_r(kbcore_config(fwg->kbcore), "-latext");
    fwg->word_cand_win = cmd_ln_int32_r(kbcore_config(fwg->kbcore), "-inlatwin");
    if (fwg->word_cand_win < 0) {
        E_ERROR("Invalid -inlatwin argument: %d; set to 50\n",
                fwg->word_cand_win);
        fwg->word_cand_win = 50;
    }
    /* Allocate pointers to lists of word candidates in each frame */
    if (fwg->word_cand_dir) {
        fwg->word_cand =
            (word_cand_t **) ckd_calloc(S3_MAX_FRAMES,
                                        sizeof(word_cand_t *));
        fwg->word_cand_cf =
            (s3wid_t *) ckd_calloc(dict->n_word + 1, sizeof(s3wid_t));
    }


    /* Initializing debugging information such as trace_wid,
       word_dump_sf, word_dump_ef, hmm_dump_sf and hmm_dump_ef */

    fwg->fwdDBG = init_fwd_dbg(fwg);

    fwg->ctr_mpx_whmm = pctr_new("mpx");
    fwg->ctr_nonmpx_whmm = pctr_new("~mpx");
    fwg->ctr_latentry = pctr_new("lat");

    /** Initialize the context table */
    fwg->ctxt = ctxt_table_init(kbcore_dict(kbc), kbcore_mdef(kbc));

    /* Viterbi history structure */
    fwg->lathist = latticehist_init(cmd_ln_int32_r(kbcore_config(fwg->kbcore), "-bptblsize"),
				   S3_MAX_FRAMES + 1);

    /* Glue the graph structure */
    s->grh->graph_struct = fwg;
    s->grh->graph_type = GRAPH_STRUCT_FLAT;



    return SRCH_SUCCESS;

}