예제 #1
0
/* MGE evaluation main procedure */
static void PerformMgeEval()
{
   int nIter, nSent;

   /* create data file list */
   CreateDataFileList();
   nSent = g_nDataFileNum;
   nSamples = 0;

   /* synchronize parameters with previous iterations */
   if (nBAEndIter < 0)
      nBAEndIter = endIter;
   for (nIter = 1; nIter < startIter; nIter++) {
      nSamples += nSent;
      if (nMaxBAIter > 1 && nIter > 0)
         nMaxBAIter -= 1;
      if (nMaxBALen > 1 && nIter > 0)
         nMaxBALen -= 1;
   }

   /* apply transform to related models */
   if (hset.curXForm != NULL)
      ApplyHMMSetXForm(&hset, hset.curXForm, FALSE);

   /* iteration from startIter to endIter */
   for (nIter = startIter; nIter <= endIter; nIter++) {
      if (trace & T_TOP) {
         fprintf(stdout, "\n\n\n--------------------- Iteration %d -------------------\n", nIter);
         fflush(stdout);
      }
      /* load MGE-trained HMM files */
      if (nIter > 0)
         LoadMgeTrnHmmFile(nIter);
      /* set the flag for boundary adjustment */
      bBoundAdj = mtInfo->bBoundAdj;

      /* one iteration of MGE training */
      nSent = OneIterMgeEval(nIter);
      /* print the statistical information of training */
      PrintStatInfo(nSent, nIter);
      /* reduce the shift iterations and length after each iteration until it reach to 1 */
      /* heuristic code to improve the efficiency */
      if (nMaxBAIter > 1 && nIter > 0)
         nMaxBAIter -= 1;
      if (nMaxBALen > 1 && nIter > 0)
         nMaxBALen -= 1;
   }

   PrintFinalResult(nSent, nIter);
}
예제 #2
0
/* PerformMgeTrain: MGE training main procedur */
static void PerformMgeTrain()
{
   int nIter, nSent;

   /* create data file list */
   CreateDataFileList();
   nSent = g_nDataFileNum;
   nSamples = 0;

   /* synchronize parameters with previous iterations */
   if (nBAEndIter < 0)
      nBAEndIter = endIter;
   for (nIter = 1; nIter < startIter; nIter++) {
      nSamples += nSent;
      ShuffleDataFileList();
      if (nMaxBAIter > 1 && nIter > 0)
         nMaxBAIter -= 1;
      if (nMaxBALen > 1 && nIter > 0)
         nMaxBALen -= 1;
   }
   /* initialize step size */
   mtInfo->initStepSize = 1 / A_STEP;

   /* apply transform to related models */
   if (hset.curXForm != NULL) {
      ApplyHMMSetXForm(&hset, hset.curXForm, FALSE);
      if (mtInfo->bOrigHmmRef)
         ApplyHMMSetXForm(&orighset, orighset.curXForm, FALSE);
   }

   /* iteration from startIter ~ endIter */
   for (nIter = startIter; nIter <= endIter; nIter++) {
      /* shuffle data file list */
      if (nIter != 0)
         ShuffleDataFileList();

      if (trace & T_TOP) {
         fprintf(stdout, "\n\n\n--------------------- Iteration %d -------------------\n", nIter);
         fflush(stdout);
      }
      /* set the flag for boundary adjustment */
      if (nMaxBAIter > 1 || nIter <= nBAEndIter)
         bBoundAdj = mtInfo->bBoundAdj;
      else
         bBoundAdj = FALSE;

      /* one iteration of MGE training */
      nSent = OneIterMgeTrain(nIter);

      /* print the statistical information of training */
      PrintStatInfo(nSent, nIter);

      /* output intermedia HMM files */
      if (nIter > 0 && outProcData && bMgeUpdate)
         OutputIntmdHmmFile(nIter);
      /* reduce the shift length after each iteration until it reach to 2 */
      /* heuristic code to improve the efficiency */
      if (nMaxBAIter > 1 && nIter > 0)
         nMaxBAIter -= 1;
      if (nMaxBALen > 1 && nIter > 0)
         nMaxBALen -= 1;
   }

   PrintFinalResult(nSent, nIter);
}
예제 #3
0
/* DoRecognition:  use single network to recognise each input utterance */
void DoRecognition(void)
{
   FILE *nf;
   Network *net;
   Boolean isPipe;
   int n=0;
   AdaptXForm *incXForm;

   if ( (nf = FOpen(wdNetFn,NetFilter,&isPipe)) == NULL)
      HError(3210,"DoRecognition: Cannot open Word Net file %s",wdNetFn);
   if((wdNet = ReadLattice(nf,&ansHeap,&vocab,TRUE,FALSE))==NULL)
      HError(3210,"DoAlignment: ReadLattice failed");
   FClose(nf,isPipe);

   if (trace&T_TOP) {
      printf("Read lattice with %d nodes / %d arcs\n",wdNet->nn,wdNet->na);
      fflush(stdout);
   }
   CreateHeap(&netHeap,"Net heap",MSTAK,1,0,
              wdNet->na*sizeof(NetLink),wdNet->na*sizeof(NetLink));

   net = ExpandWordNet(&netHeap,wdNet,&vocab,&hset);
   ResetHeap(&ansHeap);
   if (trace&T_TOP) {
      printf("Created network with %d nodes / %d links\n",
             net->numNode,net->numLink);  fflush(stdout);
   }
   if (trace & T_MEM){
      printf("Memory State Before Recognition\n");
      PrintAllHeapStats();
   }

   if (NumArgs()==0) {      /* Process audio */
      while(TRUE){
         printf("\nREADY[%d]>\n",++n); fflush(stdout);
	 /* no input transform possible for audio input .... */
         ProcessFile(NULL,net,n,genBeam, FALSE);
         if (update > 0 && n%update == 0) {
            if (trace&T_TOP) {
               printf("Transforming model set\n");
               fflush(stdout);
            }
	    /* 
	       at every stage a new transform is created - fix?? 
	       Estimate transform and then set it up as the 
	       input XForm
	    */
	    incXForm = CreateAdaptXForm(&hset,"inc");
            TidyBaseAccs();
	    GenAdaptXForm(&hset,incXForm);
            xfInfo.inXForm = GetMLLRDiagCov(incXForm);;
            SetXForm(&hset,xfInfo.inXForm);
	    ApplyHMMSetXForm(&hset,xfInfo.inXForm);
         }
      }
   }
   else {                   /* Process files */
      while (NumArgs()>0) {
         if (NextArg()!=STRINGARG)
            HError(3219,"DoRecognition: Data file name expected");
         datFN = GetStrArg();
         if (trace&T_TOP) {
            printf("File: %s\n",datFN); fflush(stdout);
         }
	 /* This handles the initial input transform, parent transform setting
	    and output transform creation */
         if (UpdateSpkrStats(&hset, &xfInfo, datFN) && (!(xfInfo.useInXForm)) && (hset.semiTied == NULL)) {
            xfInfo.inXForm = NULL;
         }
         ProcessFile(datFN,net,n++,genBeam,FALSE);
         if (update > 0 && n%update == 0) {
            if (trace&T_TOP) {
               printf("Transforming model set\n");
               fflush(stdout);
            }
	    /* 
	       at every stage a new transform is created - fix?? 
	       Estimate transform and then set it up as the 
	       input XForm
	    */
	    incXForm = CreateAdaptXForm(&hset,"inc");
            TidyBaseAccs();
	    GenAdaptXForm(&hset,incXForm);
            xfInfo.inXForm = GetMLLRDiagCov(incXForm);;
            SetXForm(&hset,xfInfo.inXForm);
	    ApplyHMMSetXForm(&hset,xfInfo.inXForm);
         }
      }
   }
}
예제 #4
0
void Initialise(void)
{
   /* load HMM mmf */
   if (MakeHMMSet(&hmset, GetStrArg()) < SUCCESS)
      HError(9928, "Initialise: MakeHMMSet failed");
   if (LoadHMMSet(&hmset, hmmDir, hmmExt) < SUCCESS)
      HError(9928, "Initialise: LoadHMMSet failed");
   if (hmset.hsKind == DISCRETEHS)
      HError(9999, "Initialise: Only continuous model is surpported");
   ConvDiagC(&hmset, TRUE);

   if (trace & T_TOP) {
      PrintrFlags();
      printf("HMMSet is ");
      switch (hmset.hsKind) {
      case PLAINHS:
         printf("PLAIN\n");
         break;
      case SHAREDHS:
         printf("SHARED\n");
         break;
      case TIEDHS:
         printf("TIED\n");
         break;
      default:
         HError(9999, "Initialise: Only continuous model is supported");
      }

      printf("%d Logical/%d Physical Models Loaded, VecSize=%d\n", hmset.numLogHMM, hmset.numPhyHMM, hmset.vecSize);
      if (hmset.numFiles > 0)
         printf("%d MMF input files\n", hmset.numFiles);
      fflush(stdout);
   }

   /* load duration mmf */
   if (!stateAlign) {
      if (MakeHMMSet(&dmset, GetStrArg()) < SUCCESS)
         HError(9928, "Initialise: MakeHMMSet failed");
      if (LoadHMMSet(&dmset, dmDir, dmExt) < SUCCESS)
         HError(9928, "Initialise: LoadHMMSet failed");
      if (hmset.hsKind == DISCRETEHS)
         HError(9999, "Initialise: Only continuous duration model mmf is surpported");
      ConvDiagC(&dmset, TRUE);

      if (trace & T_TOP) {
         printf("DurationModelSet is ");
         switch (dmset.hsKind) {
         case PLAINHS:
            printf("PLAIN\n");
            break;
         case SHAREDHS:
            printf("SHARED\n");
            break;
         case TIEDHS:
            printf("TIED\n");
            break;
         default:
            HError(9999, "Initialise: Only continuous model is supported");
         }

         printf("%d Logical/%d Physical Models Loaded, VecSize=%d\n", dmset.numLogHMM, dmset.numPhyHMM, dmset.vecSize);
         if (dmset.numFiles > 0)
            printf("%d MMF input files\n", dmset.numFiles);
         fflush(stdout);
      }
   }

   /* setup GenInfo */
   genInfo->genMem = &genStack;
   genInfo->hset = &hmset;
   genInfo->dset = &dmset;
   genInfo->maxStates = MaxStatesInSet(&hmset);
   genInfo->maxMixes = MaxMixInSet(&hmset);
   genInfo->speakRate = speakRate;
   genInfo->MSDthresh = MSDthresh;
   genInfo->modelAlign = modelAlign;
   genInfo->stateAlign = stateAlign;
   genInfo->frameRate = frameRate;

   CheckGenSetUp();

   /* setup EM-based parameter generation */
   AttachAccs(&hmset, &gstack, (UPDSet) 0);
   ZeroAccs(&hmset, (UPDSet) 0);

   if (!stateAlign) {
      AttachAccs(&dmset, &gstack, (UPDSet) 0);
      ZeroAccs(&dmset, (UPDSet) 0);
   }

   if (type != CHOLESKY)
      InitialiseForBack(fbInfo, &fbInfoStack, &hmset, (UPDSet) 0, ((useHMMFB || stateAlign) ? NULL : &dmset), (UPDSet) 0, pruneInit, pruneInc, pruneLim, minFrwdP, useAlign, FALSE);

   /* handle input xform */
   xfInfo_hmm.inFullC = xfInfo_dur.inFullC = TRUE;

   /* semi-tied case */
   if (hmset.semiTied != NULL) {
      SetXForm(&hmset, NULL, hmset.semiTied);
      ApplyHMMSetXForm(&hmset, hmset.semiTied, TRUE);
   }

   /* linear weight -> log weight */
   ConvLogWt(&hmset);
}
예제 #5
0
/* DoAlignment: by creating network from transcriptions or lattices */
void DoAlignment(void)
{
   FILE *nf;
   char lfn[MAXSTRLEN], buf[MAXSTRLEN];
   Transcription *trans;
   Network *net;
   Boolean isPipe;
   int n=0;
   LogDouble currGenBeam;
   AdaptXForm *incXForm;

   if (trace&T_TOP) {
      if (loadNetworks) 
         printf("New network will be used for each file\n");
      else
         printf("Label file will be used to align each file\n");
      fflush(stdout);
   }
   CreateHeap(&netHeap,"Net heap",MSTAK,1,0,8000,80000);
   while (NumArgs()>0) {
      if (NextArg() != STRINGARG)
         HError(3219,"DoAlignment: Data file name expected");
      datFN = GetStrArg();
      if (trace&T_TOP) {
         printf("Aligning File: %s\n",datFN);  fflush(stdout);
      }
      if (labFileMask != NULL ) { /* support for rescoring lattice masks */
         if (!MaskMatch(labFileMask,buf,datFN))
            HError(2319,"DoAlignment: mask %s has no match with segemnt %s",labFileMask,datFN);
         MakeFN(buf,labInDir,labInExt,lfn);
      } else {
         MakeFN(datFN,labInDir,labInExt,lfn);
      }
      if (loadNetworks) {
         if ( (nf = FOpen(lfn,NetFilter,&isPipe)) == NULL)
            HError(3210,"DoAlignment: Cannot open Word Net file %s",lfn);
         if((wdNet = ReadLattice(nf,&netHeap,&vocab,TRUE,FALSE))==NULL)
            HError(3210,"DoAlignment: ReadLattice failed");
         FClose(nf,isPipe);
         if (trace&T_TOP) {
            printf("Read lattice with %d nodes / %d arcs\n",
                   wdNet->nn,wdNet->na);
            fflush(stdout);
         }
      }
      else {
         LabList *ll = NULL;

         trans=LOpen(&netHeap,lfn,ifmt);
         if (trans->numLists >= 1)
            ll = GetLabelList(trans,1);
         if (!ll && !bndId)
            HError(3233, "DoAlignment: cannot align empty transcription");

         wdNet=LatticeFromLabels(ll, bndId, &vocab,&netHeap);
         if (trace&T_TOP) {
            printf("Created lattice with %d nodes / %d arcs from label file\n",
                   wdNet->nn,wdNet->na);
            fflush(stdout);
         }
      }
      net=ExpandWordNet(&netHeap,wdNet,&vocab,&hset);

      ++n;
      currGenBeam = genBeam;
      /* This handles the initial input transform, parent transform setting
	 and output transform creation */
      if (UpdateSpkrStats(&hset, &xfInfo, datFN) && (!(xfInfo.useInXForm)) && (hset.semiTied == NULL)) {
         xfInfo.inXForm = NULL;
      }
      if (genBeamInc == 0.0)
         ProcessFile (datFN, net, n, currGenBeam, FALSE);
      else {
         Boolean completed;

         completed = ProcessFile (datFN, net, n, currGenBeam, TRUE);
         currGenBeam += genBeamInc;
         while (!completed && (currGenBeam <= genBeamLim - genBeamInc)) {
            completed = ProcessFile (datFN, net, n, currGenBeam, TRUE);
            currGenBeam += genBeamInc;
         }
         if (!completed)
            ProcessFile (datFN, net, n, currGenBeam, FALSE);
      }

      if (update > 0 && n%update == 0) {
         if (trace&T_TOP) {
            printf("Transforming model set\n");
            fflush(stdout);
         }
	 /* 
	    at every stage a new transform is created - fix?? 
	    Estimate transform and then set it up as the 
	    input XForm
	 */
	 incXForm = CreateAdaptXForm(&hset,"inc");
         TidyBaseAccs();
	 GenAdaptXForm(&hset,incXForm);
         xfInfo.inXForm = GetMLLRDiagCov(incXForm);;
	 SetXForm(&hset,xfInfo.inXForm);
	 ApplyHMMSetXForm(&hset,xfInfo.inXForm);
      }
      ResetHeap(&netHeap);
   }
}