Esempio n. 1
0
/* SetLabSeg: Set st and en for label (sequence) */
void SetLabSeg(Transcription *tr)
{
   LabList *ll = tr->head;    /* use first lab list */
   LLink p,q;
   
   if (tr->numLists > 1)
      HError(-1031,"SetLabSeg: label lists 2 to %d will be ignored",
             tr->numLists);
   if (labName != NULL) {  /* extract labName */
      if (auxLab==0) {
         p = GetCase(ll,labName,labRep);
         st = p->start; en = p->end;
      } else {
         p = GetAuxCase(ll,labName,labRep,auxLab);
         st = p->start; en = AuxLabEndTime(p,auxLab);
      }        
   } else {                /* extract labstidx to labenidx */
      if (auxLab==0){
         FixLabIdxs(CountLabs(ll));
         p = GetLabN(ll,curstidx);
         q = GetLabN(ll,curenidx);
         st = p->start; en = q->end;
      }else{
         FixLabIdxs(CountAuxLabs(ll,auxLab));
         p = GetAuxLabN(ll,curstidx,auxLab);
         q = GetAuxLabN(ll,curenidx,auxLab);
         st = p->start; en = AuxLabEndTime(q,auxLab);
      }
   }  
   if(trace & T_SEGMENT)
      printf("Extracting %8.0f to %8.0f\n",st,en);
}
Esempio n. 2
0
/* DoOnlineAdaptation: Perform unsupervised online adaptation
   using the recognition hypothesis as the transcription */
int DoOnlineAdaptation(Lattice *lat, ParmBuf pbuf, int nFrames)
{
   Transcription *modelTrans, *trans;
   BufferInfo pbinfo;
   Lattice *alignLat, *wordNet;
   Network *alignNet;
   int i;

   GetBufferInfo(pbuf,&pbinfo);
   trans=TranscriptionFromLattice(&netHeap,lat,1);
   wordNet=LatticeFromLabels(GetLabelList(trans,1),bndId,
                             &vocab,&netHeap);
   alignNet=ExpandWordNet(&netHeap,wordNet,&vocab,&hset);

   StartRecognition(alignvri,alignNet,0.0,0.0,0.0);     

   /* do forced alignment */
   for (i = 0; i < nFrames; i++) {
      ReadAsTable(pbuf, i, &obs);
      ProcessObservation(alignvri,&obs,-1,xfInfo.inXForm);
   }
    
   alignLat=CompleteRecognition(alignvri,
                                pbinfo.tgtSampRate/10000000.0,
                                &netHeap);
        
   if (alignvri->noTokenSurvived) {
      Dispose(&netHeap, trans);
      /* Return value 0 to indicate zero frames process failed */
      return 0;
   }
   modelTrans=TranscriptionFromLattice(&netHeap,alignLat,1);
      
   /* format the transcription so that it contains just the models */
   FormatTranscription(modelTrans,pbinfo.tgtSampRate,FALSE,TRUE,
                       FALSE,FALSE,TRUE,FALSE,TRUE,TRUE, FALSE);

   /* Now do the frame/state alignment accumulating MLLR statistics */
   /* set the various values in the utterance storage */
   utt->tr = modelTrans;
   utt->pbuf = pbuf;
   utt->Q = CountLabs(utt->tr->head);
   utt->T = nFrames;
   utt->ot = obs;
  
   /* do frame state alignment and accumulate statistics */
   fbInfo->inXForm = xfInfo.inXForm;
   fbInfo->al_inXForm = xfInfo.inXForm;
   fbInfo->paXForm = xfInfo.paXForm;
   if (!FBFile(fbInfo, utt, NULL))
     nFrames = 0;

   Dispose(&netHeap, trans);

   if (trace&T_TOP) {
      printf("Accumulated statistics...\n"); 
      fflush(stdout);
   }
   return nFrames;
} 
Esempio n. 3
0
/* GatherStats: update stats using given label file */
void GatherStats(Transcription *t)
{
   LLink l;
   LabList *ll;
   WordInfo *lt;
   int i,j,st,en,lab,in[ASIZE];
   float dur;
   AEntry *ae;

   ll=GetLabelList(t,1);
   st=1;  en=CountLabs(ll);

   /* If first label is enterId then we need to skip it */
   l = GetLabN(ll,1);
   if (l->labid==enterId) st++;

   /* If the final label is exitId then it should be skipped */
   l = GetLabN(ll,en);
   if (l->labid==exitId) en--;

   /* Coerce previous labels to be enterId */
   for (i=0; i<ASIZE; i++) in[i]=(int)enterId->aux;
   lt = lTab+(int)enterId->aux; ++lt->count;
   
   /* Process actual labels in list */ 
   for (i=st; i<=en; i++) {
      l = GetLabN(ll,i);
      lab=(int)l->labid->aux;
      dur = (float)(l->end - l->start)/10000.0;
      lt=lTab+lab;
      /* increment stats */
      lt->count++;
      lt->sumDur += dur;
      if (dur < lt->minDur) lt->minDur=dur;
      if (dur > lt->maxDur) lt->maxDur=dur;
      lt->pCntr->count++;
      if (doBigram) {
         /* We ignore all transitions into enterId and exitId */
         /* May wish to warn user about badly formed sentences */
         if (!(lab==(int)enterId->aux || (lab==(int)exitId->aux))) {
            for (j=ASIZE-1;j>0;j--) in[j]=in[j-1];
            in[0]=lab;
            ae = GetAEntry(in,TRUE);
            ae->count++;
         }
      }
   }
   /* Deal with transition into EXIT */
   if (doBigram) {
      for (j=ASIZE-1;j>0;j--) in[j]=in[j-1];
      in[0]=(int)exitId->aux;
      ae = GetAEntry(in,TRUE);
      ae->count++;
   }
   lt = lTab+(int)exitId->aux; ++lt->count;
}
Esempio n. 4
0
/* SaveLabs: save trans t to label file corresponding to tgt */
void SaveLabs(char *tgt, Transcription *t)
{
   MakeFN(tgt,outLabDir,labExt,labFile);
   if(trace & T_SEGMENT)
      printf("Saving label file %s\n",labFile);
   if (CountLabs(trans->head) == 0) 
      HError(-1031,"SaveLabs: No labels in transcription %s", labFile);
   if(LSave(labFile,t,tgtLabFF)<SUCCESS)
      HError(1014,"SaveLabs: Could not save label file %s", labFile);
}
Esempio n. 5
0
/* ProcessLabelFile: compute perplexity and related statistics from labels */
static void ProcessLabelFile(char *fn, int nSize)
{
   LLink ll;
   double ppl;
   LabList *ref;
   LabId lab;
   Transcription *tr;
   int i,numPLabs,nLabel;

   tr = LOpen(&tempHeap, fn, lff);
   if (tr->numLists < 1) {
      HError(-16635,"ProcessLabelFile: transcription file %s is Empty",fn);
      return;
   }
   ref = GetLabelList(tr, 1);
   if (ref->head->succ == ref->tail) {
      HError(-16635,"ProcessLabelFile: transcription file %s is Empty",fn);
      return;
   }
   if (trace>0) {
      printf("Processing label file: %s\n", fn);
      fflush(stdout);
   }

   nLabel = CountLabs(ref);
   ZeroStats(&sent);
   sent.nTok = nLabel + 2; sent.nUtt = 1;

   /* copy labels into pLab, mapping OOVs */
   numPLabs = 0;
   if (sstId!=NULL)             /* add sentence start marker(s) */
      for (i=0; i<(nSize-1); i++) pLab[numPLabs++] = sstId;
   for (i=0,ll=ref->head->succ; i<nLabel; i++,ll=ll->succ) {
      lab = GetEQLab(ll->labid);
      if ((i==0) && IS_SST(lab)) {
	sent.nTok--; continue;
      }
      if ((i==(nLabel-1)) && IS_SEN(lab)) {
	 sent.nTok--; continue;
      }
      if (IS_UNK(lab)) {
	 if (trace&T_OOV)
	    printf("mapping OOV: %s\n", lab->name);
	 StoreOOV(&sent,lab,1); lab = unkId;
      }
      pLab[numPLabs++] = lab;
      if (numPLabs>=LBUF_SIZE) {
         HError(16650, "Maximum utterance length in a label file exceeded (limit is compiled to be %d tokens)",
                LBUF_SIZE);
      }
   }
   if (senId!=NULL)             /* add sentence end marker */
     pLab[numPLabs++] = senId;

   CalcPerplexity(&sent, pLab, numPLabs, nSize);
   AddStats(&sent, &totl);

   if (trace&T_SEL) {     /* compact info for sentence selection */
      ppl = exp(-(sent.logpp)/(double) (sent.nWrd));
      printf("#! %.4f", ppl);
      for (i=0, ll=ref->head->succ; i<nLabel; i++, ll=ll->succ)
	 printf(" %s", ll->labid->name);
      printf("\n"); fflush(stdout);
   }
}