Exemplo n.º 1
0
void
mdef_sseq2sen_active(mdef_t * mdef, uint8 * sseq, uint8 * sen)
{
    int32 ss, i;
    s3senid_t *sp;

    for (ss = 0; ss < mdef_n_sseq(mdef); ss++) {
        if (sseq[ss]) {
            sp = mdef->sseq[ss];
            for (i = 0; i < mdef_n_emit_state(mdef); i++)
                sen[sp[i]] = 1;
        }
    }
}
void dict2pid_comsseq2sen_active (dict2pid_t *d2p, mdef_t *mdef, int32 *comssid, int32 *sen)
{
    int32 ss, cs, i, j;
    s3senid_t *csp, *sp;	/* Composite state pointer */
    
    for (ss = 0; ss < d2p->n_comsseq; ss++) {
	if (comssid[ss]) {
	    csp = d2p->comsseq[ss];

	    for (i = 0; i < mdef_n_emit_state(mdef); i++) {
		cs = csp[i];
		sp = d2p->comstate[cs];
		
		for (j = 0; IS_S3SENID(sp[j]); j++)
		    sen[sp[j]] = 1;
	    }
	}
    }
}
Exemplo n.º 3
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;

}
void dict2pid_dump (FILE *fp, dict2pid_t *d2p, mdef_t *mdef, dict_t *dict)
{
    int32 w, p, pronlen;
    int32 i, j, b, l, r;
    
    fprintf (fp, "# INTERNAL (wd comssid ssid ssid ... ssid comssid)\n");
    for (w = 0; w < dict_size(dict); w++) {
	fprintf (fp, "%30s ", dict_wordstr(dict, w));
	
	pronlen = dict_pronlen(dict, w);
	for (p = 0; p < pronlen; p++)
	    fprintf (fp, " %5d", d2p->internal[w][p]);
	fprintf (fp, "\n");
    }
    fprintf (fp, "#\n");
    
    fprintf (fp, "# LDIPH_LC (b r l ssid)\n");
    for (b = 0; b < mdef_n_ciphone(mdef); b++) {
	for (r = 0; r < mdef_n_ciphone(mdef); r++) {
	    for (l = 0; l < mdef_n_ciphone(mdef); l++) {
		if (IS_S3SSID(d2p->ldiph_lc[b][r][l]))
		    fprintf (fp, "%6s %6s %6s %5d\n",
			     mdef_ciphone_str (mdef, (s3cipid_t)b),
			     mdef_ciphone_str (mdef, (s3cipid_t)r),
			     mdef_ciphone_str (mdef, (s3cipid_t)l),
			     d2p->ldiph_lc[b][r][l]); /* RAH, ldiph_lc is returning an int32, %d expects an int16 */
	    }
	}
    }
    fprintf (fp, "#\n");
    
    fprintf (fp, "# SINGLE_LC (b l comssid)\n");
    for (b = 0; b < mdef_n_ciphone(mdef); b++) {
	for (l = 0; l < mdef_n_ciphone(mdef); l++) {
	    if (IS_S3SSID(d2p->single_lc[b][l]))
		fprintf (fp, "%6s %6s %5d\n",
			 mdef_ciphone_str (mdef, (s3cipid_t)b),
			 mdef_ciphone_str (mdef, (s3cipid_t)l),
			 d2p->single_lc[b][l]);	/* RAH, single_lc is returning an int32, %d expects an int16 */
	}
    }
    fprintf (fp, "#\n");
    
    fprintf (fp, "# SSEQ %d (senid senid ...)\n", mdef->n_sseq);
    for (i = 0; i < mdef->n_sseq; i++) {
	fprintf (fp, "%5d ", i);
	for (j = 0; j < mdef_n_emit_state(mdef); j++)
	    fprintf (fp, " %5d", mdef->sseq[i][j]);
	fprintf (fp, "\n");
    }
    fprintf (fp, "#\n");
    
    fprintf (fp, "# COMSSEQ %d (comstate comstate ...)\n", d2p->n_comsseq);
    for (i = 0; i < d2p->n_comsseq; i++) {
	fprintf (fp, "%5d ", i);
	for (j = 0; j < mdef_n_emit_state(mdef); j++)
	    fprintf (fp, " %5d", d2p->comsseq[i][j]);
	fprintf (fp, "\n");
    }
    fprintf (fp, "#\n");
    
    fprintf (fp, "# COMSTATE %d (senid senid ...)\n", d2p->n_comstate);
    for (i = 0; i < d2p->n_comstate; i++) {
	fprintf (fp, "%5d ", i);
	for (j = 0; IS_S3SENID(d2p->comstate[i][j]); j++)
	    fprintf (fp, " %5d", d2p->comstate[i][j]);
	fprintf (fp, "\n");
    }
    fprintf (fp, "#\n");
    fprintf (fp, "# END\n");
    
    fflush (fp);
}
/*
 * Convert the glist of ssids to a composite sseq id.  Return the composite ID.
 */
static s3ssid_t ssidlist2comsseq (glist_t g, mdef_t *mdef, dict2pid_t *dict2pid,
				  hash_table_t *hs,	/* For composite states */
				  hash_table_t *hp)	/* For composite senone seq */
{
    int32 i, j, n, s, ssid;
    s3senid_t **sen;
    s3senid_t *comsenid;
    gnode_t *gn;
    
    n = glist_count (g);
    if (n <= 0)
	E_FATAL("Panic: length(ssidlist)= %d\n", n);
    
    /* Space for list of senones for each state, derived from the given glist */
    sen = (s3senid_t **) ckd_calloc (mdef_n_emit_state (mdef), sizeof(s3senid_t *));
    for (i = 0; i < mdef_n_emit_state (mdef); i++) {
	sen[i] = (s3senid_t *) ckd_calloc (n+1, sizeof(s3senid_t));
	sen[i][0] = BAD_S3SENID;	/* Sentinel */
    }
    /* Space for composite senone ID for each state position */
    comsenid = (s3senid_t *) ckd_calloc (mdef_n_emit_state (mdef), sizeof(s3senid_t));
    
    for (gn = g; gn; gn = gnode_next(gn)) {
	ssid = gnode_int32 (gn);
	
	/* Expand ssid into individual states (senones); insert in sen[][] if not present */
	for (i = 0; i < mdef_n_emit_state (mdef); i++) {
	    s = mdef->sseq[ssid][i];
	    
	    for (j = 0; (IS_S3SENID(sen[i][j])) && (sen[i][j] != s); j++);
	    if (NOT_S3SENID(sen[i][j])) {
		sen[i][j] = s;
		sen[i][j+1] = BAD_S3SENID;
	    }
	}
    }
    
    /* Convert senones list for each state position into composite state */
    for (i = 0; i < mdef_n_emit_state (mdef); i++) {
	for (j = 0; IS_S3SENID(sen[i][j]); j++);
	assert (j > 0);
	
	j = hash_enter_bkey (hs, (char *)(sen[i]), j*sizeof(s3senid_t), dict2pid->n_comstate);
	if (j == dict2pid->n_comstate)
	    dict2pid->n_comstate++;	/* New composite state */
	else
	    ckd_free ((void *) sen[i]);
	
	comsenid[i] = j;
    }
    ckd_free (sen);
    
    /* Convert sequence of composite senids to composite sseq ID */
    j = hash_enter_bkey (hp, (char *)comsenid, mdef->n_emit_state * sizeof(s3senid_t),
			 dict2pid->n_comsseq);
    if (j == dict2pid->n_comsseq) {
	dict2pid->n_comsseq++;
	if (dict2pid->n_comsseq >= MAX_S3SENID)
	    E_FATAL("#Composite sseq limit(%d) reached; increase MAX_S3SENID\n",
		    dict2pid->n_comsseq);
    } else
	ckd_free ((void *) comsenid);
    
    return ((s3ssid_t)j);
}