static void
state_align_search_free(ps_search_t *search)
{
    state_align_search_t *sas = (state_align_search_t *)search;
    ps_search_base_free(search);
    ckd_free(sas->hmms);
    ckd_free(sas->tokens);
    hmm_context_free(sas->hmmctx);
    ckd_free(sas);
}
Beispiel #2
0
int
srch_FLAT_FWD_uninit(void *srch)
{

    srch_FLAT_FWD_graph_t *fwg;
    srch_t *s;

    s = (srch_t *) srch;
    fwg = (srch_FLAT_FWD_graph_t *) s->grh->graph_struct;

    if (fwg->rcscore)
        ckd_free(fwg->rcscore);

    if (fwg->ug_backoff)
        ckd_free(fwg->ug_backoff);

    if (fwg->filler_backoff)
        ckd_free(fwg->filler_backoff);

    if (fwg->tg_trans_done)
        ckd_free(fwg->tg_trans_done);

    if (fwg->word_cand_cf)
        ckd_free(fwg->word_cand_cf);

    if (fwg->word_cand)
        ckd_free(fwg->word_cand);

    if (fwg->ctxt)
        ctxt_table_free(fwg->ctxt);

    if (fwg->lathist)
	latticehist_free(fwg->lathist);

    if (fwg->fwdDBG)
	ckd_free(fwg->fwdDBG);

    if (fwg->whmm)
	ckd_free(fwg->whmm);

    if (fwg->hmmctx)
	hmm_context_free(fwg->hmmctx);

    if (fwg->word_ugprob)
	word_ugprob_free(fwg->word_ugprob, kbcore_mdef(s->kbc)->n_ciphone);

    pctr_free(fwg->ctr_mpx_whmm);
    pctr_free(fwg->ctr_nonmpx_whmm);
    pctr_free(fwg->ctr_latentry);

    ckd_free(fwg);

    return SRCH_SUCCESS;
}
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;
}
static void
phone_loop_search_free(ps_search_t *search)
{
    phone_loop_search_t *pls = (phone_loop_search_t *)search;
    int i;

    ps_search_deinit(search);
    for (i = 0; i < pls->n_phones; ++i)
        hmm_deinit((hmm_t *)&pls->phones[i]);
    phone_loop_search_free_renorm(pls);
    ckd_free(pls->phones);
    hmm_context_free(pls->hmmctx);
    ckd_free(pls);
}
Beispiel #5
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;
}