/*
 * Write exact hypothesis.  Format:
 *   <id> T <scr> A <ascr> L <lscr> {<sf> <wascr> <wlscr> <word>}... <ef>
 * where:
 *   scr = ascr + (lscr*lw+N*wip), where N = #words excluding <s>
 *   ascr = scaled acoustic score for entire utterance
 *   lscr = LM score (without lw or wip) for entire utterance
 *   sf = start frame for word
 *   wascr = scaled acoustic score for word
 *   wlscr = LM score (without lw or wip) for word
 *   ef = end frame for utterance.
 */
static void log_hypseg (char *uttid,
			FILE *fp,	/* Out: output file */
			hyp_t *hypptr,	/* In: Hypothesis */
			int32 nfrm)	/* In: #frames in utterance */
{
    hyp_t *h;
    int32 ascr, lscr, tscr;
    
    ascr = lscr = tscr = 0;
    for (h = hypptr; h; h = h->next) {
	ascr += h->ascr;
	if (dict_basewid(h->wid) != startwid) {
	    lscr += lm_rawscore (h->lscr, 1.0);
	} else {
	    assert (h->lscr == 0);
	}
	tscr += h->ascr + h->lscr;
    }

    fprintf (fp, "%s T %d A %d L %d", uttid, tscr, ascr, lscr);
    
    if (! hypptr)	/* HACK!! */
	fprintf (fp, " (null)\n");
    else {
	for (h = hypptr; h; h = h->next) {
	    lscr = (dict_basewid(h->wid) != startwid) ? lm_rawscore (h->lscr, 1.0) : 0;
	    fprintf (fp, " %d %d %d %s", h->sf, h->ascr, lscr, dict_wordstr (h->wid));
	}
	fprintf (fp, " %d\n", nfrm);
    }
    
    fflush (fp);
}
Exemplo n.º 2
0
void
matchseg_write(FILE * fp, glist_t hyp, char *uttid, char *hdr,
               lm_t * lm, dict_t * dict, int32 num_frm, int32 * ascale,
               int32 unnorm)
{
    gnode_t *gn;
    srch_hyp_t *h;
    int32 ascr, lscr, scl, hypscale, global_hypscale;
    int32 i;

    if (fp == NULL)
        return;

    ascr = 0;
    lscr = 0;
    scl = 0;
    hypscale = 0;
    global_hypscale = 0;

    for (gn = hyp; gn; gn = gnode_next(gn)) {
        h = (srch_hyp_t *) gnode_ptr(gn);

        if (h->sf != h->ef) {   /* FSG outputs zero-width hyps */
            ascr += h->ascr;
            lscr += lm ? lm_rawscore(lm, h->lscr) : h->lscr;

            if (unnorm)
                global_hypscale += compute_scale(h->sf, h->ef, ascale);
        }
    }

    for (i = 0; i < num_frm; i++)
        scl += ascale[i];

    fprintf(fp, "%s%s S %d T %d A %d L %d", (hdr ? hdr : ""), uttid,
	    scl, ascr + lscr + global_hypscale, ascr + global_hypscale,
	    lscr);

    for (gn = hyp; gn; gn = gnode_next(gn)) {
            h = (srch_hyp_t *) gnode_ptr(gn);

            if (h->sf != h->ef) {   /* FSG outputs zero-width hyps */
                hypscale = 0;
                if (unnorm)
		    hypscale += compute_scale(h->sf, h->ef, ascale);


                fprintf(fp, " %d %d %d %s", h->sf, h->ascr + hypscale,
                        lm ? lm_rawscore(lm, h->lscr) : h->lscr,
                        dict_wordstr(dict, h->id));
            }
    }
    fprintf(fp, " %d\n", num_frm);

    fflush(fp);

}
Exemplo n.º 3
0
/*
 * Write exact hypothesis.  Format
 *   <id> S <scl> T <scr> A <ascr> L <lscr> {<sf> <wascr> <wlscr> <word>}... <ef>
 * where:
 *   scl = acoustic score scaling for entire utterance
 *   scr = ascr + (lscr*lw+N*wip), where N = #words excluding <s>
 *   ascr = scaled acoustic score for entire utterance
 *   lscr = LM score (without lw or wip) for entire utterance
 *   sf = start frame for word
 *   wascr = scaled acoustic score for word
 *   wlscr = LM score (without lw or wip) for word
 *   ef = end frame for utterance.
 */
void
log_hypseg(char *uttid, FILE * fp,      /* Out: output file */
           srch_hyp_t * hypptr, /* In: Hypothesis */
           int32 nfrm,          /* In: #frames in utterance */
           int32 scl,           /* In: Acoustic scaling for entire utt */
           float64 lwf,         /* In: LM score scale-factor (in dagsearch) */
           dict_t * dict,       /* In: dictionary */
           lm_t * lm, int32 unnorm
                                /**< Whether unscaled the score back */
    )
{
    srch_hyp_t *h;
    int32 ascr, lscr, tscr;

    if (fp == NULL)
        return;

    ascr = lscr = tscr = 0;
    for (h = hypptr; h; h = h->next) {
        ascr += h->ascr;
        if (dict_basewid(dict, h->id) != dict->startwid) {
            lscr += lm_rawscore(lm, h->lscr);
        }
        else {
            assert(h->lscr == 0);
        }
        tscr += h->ascr + h->lscr;
    }

    fprintf(fp, "%s S %d T %d A %d L %d", uttid, scl, tscr, ascr, lscr);

    if (!hypptr)                /* HACK!! */
        fprintf(fp, " (null)\n");
    else {
        for (h = hypptr; h; h = h->next) {
            lscr =
                (dict_basewid(dict, h->id) !=
                 dict->startwid) ? lm_rawscore(lm, h->lscr) : 0;
            fprintf(fp, " %d %d %d %s", h->sf, h->ascr, lscr,
                    dict_wordstr(dict, h->id));
        }
        fprintf(fp, " %d\n", nfrm);
    }

    fflush(fp);
}