Example #1
0
/* LoadMgeTrnHmmFile: */
static void LoadMgeTrnHmmFile(int nIter)
{
   char hext[15], hmmFile[255];

   ResetHeap(&hmmStack);
   CreateHeap(&hmmStack, "Model Stack", MSTAK, 1, 1.0, 80000, 400000);

   sprintf(hext, "mmf%d", nIter);
   MakeFN(mmfFn, outDir, hext, hmmFile);

   CreateHMMSet(&hset, &hmmStack, TRUE);
   AddMMF(&hset, hmmFile);
   if (trace & T_TOP)
      printf("Loading MGE-trained HMM in iteration %d ... ... \n", nIter);
   if (MakeHMMSet(&hset, hmmListFn) < SUCCESS)
      HError(2321, "Initialise: MakeHMMSet failed");
   if (LoadHMMSet(&hset, hmmDir, hmmExt) < SUCCESS)
      HError(2321, "Initialise: LoadHMMSet failed");
   SetParmHMMSet(&hset);
   /* variance inversion, MGE training only support INVDIAGC case */
   ConvDiagC(&hset, TRUE);

   if (funcType == MGE_TRAIN)
      AttachAccToModel();
}
Example #2
0
/* OutputIntmdHmmFile: Output intermedia HMM files */
static void OutputIntmdHmmFile(int nIter)
{
   char hext[16];

   if (trace & T_TOP) {
      fprintf(stdout, "\nSaving HMM to %s ... \n", outDir);
      fflush(stdout);
   }
   /* fix variance floor */
   ApplyVFloor(&hset);

   /* variance re-inversion for output HMM */
   ConvDiagC(&hset, TRUE);
   sprintf(hext, "mmf%d", nIter);
   SaveHMMSet(&hset, outDir, NULL, hext, TRUE);
   ConvDiagC(&hset, TRUE);
}
Example #3
0
  xf = xfInfo.paXForm;

  if ((xfInfo.paXForm != NULL) && !(uFlags&UPXFORM)) {

    while (xf != NULL) {

       if ((xf->xformSet->xkind != CMLLR) && (xf->xformSet->xkind != SEMIT))

	HError(999,"SAT only supported with SEMIT/CMLLR transforms");

      xf = xf->parentXForm;

    }

  }

}



int main(int argc, char *argv[])

{

   char *datafn=NULL;

   char *datafn2=NULL;

   char *s;

   char *scriptFile;

   char datafn1[MAXSTRLEN];

   char newFn[MAXSTRLEN];

   FILE *f;

   UttInfo *utt;            /* utterance information storage */

   FBInfo *fbInfo;          /* forward-backward information storage */

   HMMSet hset;             /* Set of HMMs to be re-estimated */

   Source src;

   float tmpFlt;

   int tmpInt;

   int numUtt,spUtt=0;



   void Initialise(FBInfo *fbInfo, MemHeap *x, HMMSet *hset, char *hmmListFn);

   void DoForwardBackward(FBInfo *fbInfo, UttInfo *utt, char *datafn, char *datafn2);

   void UpdateModels(HMMSet *hset, ParmBuf pbuf2);

   void StatReport(HMMSet *hset);

   

   if(InitShell(argc,argv,herest_version,herest_vc_id)<SUCCESS)

      HError(2300,"HERest: InitShell failed");

   InitMem();    InitMath();

   InitSigP();   InitAudio();

   InitWave();   InitVQ();

   InitLabel();  InitModel();

   if(InitParm()<SUCCESS)  

      HError(2300,"HERest: InitParm failed");

   InitTrain();

   InitUtil();   InitFB();

   InitAdapt(&xfInfo); InitMap();



   if (!InfoPrinted() && NumArgs() == 0)

      ReportUsage();

   if (NumArgs() == 0) Exit(0);

   al_hmmDir[0] = '\0'; al_hmmExt[0] = '\0'; 

   al_hmmMMF[0] = '\0'; al_hmmLst[0] = '\0'; 

   up_hmmMMF[0] = '\0';

   CreateHeap(&hmmStack,"HmmStore", MSTAK, 1, 1.0, 50000, 500000);

   SetConfParms(); 

   CreateHMMSet(&hset,&hmmStack,TRUE);

   CreateHeap(&uttStack,   "uttStore",    MSTAK, 1, 0.5, 100,   1000);

   utt = (UttInfo *) New(&uttStack, sizeof(UttInfo));

   CreateHeap(&fbInfoStack,   "FBInfoStore",  MSTAK, 1, 0.5, 100 ,  1000 );

   fbInfo = (FBInfo *) New(&fbInfoStack, sizeof(FBInfo));

   CreateHeap(&accStack,   "accStore",    MSTAK, 1, 1.0, 50000,   500000);



   while (NextArg() == SWITCHARG) {

      s = GetSwtArg();

      if (strlen(s)!=1) 

         HError(2319,"HERest: Bad switch %s; must be single letter",s);

      switch(s[0]){

      case 'b':

         if (NextArg()!=STRINGARG)

            HError(2319,"HERest: script file expected");

         scriptFile = GetStrArg(); break;
Example #4
0
/* Initialise: */
static void Initialise()
{
   char macroname[MAXSTRLEN];
   AdaptXForm *xform;

   /* load HMMs and init HMMSet related global variables */
   if (trace & T_TOP)
      printf("Loading HMM for updating ... ... \n");
   if (MakeHMMSet(&hset, hmmListFn) < SUCCESS)
      HError(2321, "Initialise: MakeHMMSet failed");
   if (LoadHMMSet(&hset, hmmDir, hmmExt) < SUCCESS)
      HError(2321, "Initialise: LoadHMMSet failed");
   SetParmHMMSet(&hset);
   /* variance inversion, MGE training only support INVDIAGC case */
   if (hset.ckind == DIAGC)
      ConvDiagC(&hset, TRUE);
   /* load transform */
   if (xformfn != NULL) {
      xform = LoadOneXForm(&hset, NameOf(xformfn, macroname), xformfn);
      SetXForm(&hset, &xfInfo, xform);
   }

   if (funcType == MGE_TRAIN)
      AttachAccToModel();

   /* reload the HMM for reference in training */
   if (mtInfo->bOrigHmmRef) {
      if (trace & T_TOP)
         printf("Loading HMM for reference ... ... \n");
      if (MakeHMMSet(&orighset, hmmListFn) < SUCCESS)
         HError(2321, "Initialise: MakeHMMSet failed");
      if (LoadHMMSet(&orighset, hmmDir, hmmExt) < SUCCESS)
         HError(2321, "Initialise: LoadHMMSet failed");
      SetParmHMMSet(&orighset);
      /* variance inversion, MGE training only support INVDIAGC case */
      if (hset.ckind == DIAGC)
         ConvDiagC(&orighset, TRUE);
      /* load transform */
      if (xformfn != NULL) {
         xform = LoadOneXForm(&orighset, NameOf(xformfn, macroname), xformfn);
         SetXForm(&orighset, &xfInfo, xform);
      }
   }

   if (trace & T_TOP) {
      printf("System is ");
      switch (hset.hsKind) {
      case PLAINHS:
         printf("PLAIN\n");
         break;
      case SHAREDHS:
         printf("SHARED\n");
         break;
      case TIEDHS:
         printf("TIED\n");
         break;
      case DISCRETEHS:
         printf("DISCRETE\n");
         break;
      }

      printf("%d Logical/%d Physical Models Loaded, VecSize=%d\n", hset.numLogHMM, hset.numPhyHMM, hset.vecSize);
      if (hset.numFiles > 0)
         printf("%d MMF input files\n", hset.numFiles);
      if (mmfFn != NULL)
         printf("Output to MMF file:  %s\n", mmfFn);
      fflush(stdout);
   }

   /* initialize a MgeTrnInfo for MGE training of HMM */
   InitMgeTrnInfo();
}
Example #5
0
/* main: */
int main(int argc, char *argv[])
{
   char *s;
   char fname[MAXSTRLEN];

   InitShell(argc, argv, hmgetool_version, hmgetool_vc_id);
   InitMem();
   InitMath();
   InitSigP();
   InitWave();
   InitLabel();
   InitModel();
   InitTrain();
   InitParm();
   InitUtil();
   InitFB();
   InitGen();
   InitAdapt(&xfInfo, NULL);
   InitMTrain();

   /* process argument */
   if (NumArgs() == 0)
      ReportUsage();
   CreateHeap(&hmmStack, "Model Stack", MSTAK, 1, 1.0, 80000, 4000000);
   CreateHeap(&orighmmStack, "Model Stack", MSTAK, 1, 1.0, 80000, 4000000);
   CreateHeap(&accStack, "Acc Stack", MSTAK, 1, 1.0, 80000, 400000);
   CreateHeap(&genStack, "Gen Stack", MSTAK, 1, 1.0, 80000, 400000);
   CreateHeap(&mgeStack, "MGE Train Stack", MSTAK, 1, 1.0, 80000, 400000);

   SetConfParms();
   CreateHMMSet(&hset, &hmmStack, TRUE);
   CreateHMMSet(&orighset, &orighmmStack, TRUE);

   statInfo = (MTStatInfo *) New(&gstack, sizeof(MTStatInfo));
   memset(statInfo, 0, sizeof(MTStatInfo));

   genInfo = (GenInfo *) New(&genStack, sizeof(GenInfo));
   memset(genInfo, 0, sizeof(GenInfo));
   genInfo->hset = &hset;
   genInfo->genMem = &genStack;

   mtInfo = (MgeTrnInfo *) New(&mgeStack, sizeof(MgeTrnInfo));
   memset(mtInfo, 0, sizeof(MgeTrnInfo));
   mtInfo->genInfo = genInfo;
   mtInfo->statInfo = statInfo;
   mtInfo->hset = &hset;
   mtInfo->orighset = &orighset;
   mtInfo->mgeMem = &mgeStack;

   while (NextArg() == SWITCHARG) {
      s = GetSwtArg();
      if (strlen(s) != 1)
         HError(6601, "HMgeTool: Bad switch %s; must be single letter", s);
      switch (s[0]) {
      case 'a':
         nMaxBAIter = GetChkedInt(1, 1000, s);
         nMaxBALen = GetChkedInt(1, 1000, s);
         break;
      case 'b':
         mtInfo->bBoundAdj = TRUE;
         nBAEndIter = GetChkedInt(0, 1000, s);
         nBoundAdjWin = GetChkedInt(1, 1000, s);
         break;
      case 'c':
         outProcData = TRUE;
         break;
      case 'd':
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: HMM definition directory expected");
         hmmDir = GetStrArg();
         break;
      case 'e':
         mtInfo->bStepLimit = TRUE;
         break;
      case 'f':
         frameRate = (HTime) GetChkedFlt(0.0, 10000000.0, s);
         break;
      case 'g':
         mtInfo->bMVar = TRUE;
         break;
      case 'i':
         startIter = GetChkedInt(0, 1000, s);
         endIter = GetChkedInt(startIter, 1000, s);
         break;
      case 'j':
         funcType = GetChkedInt(0, 2, s);
         mtInfo->funcType = funcType;
         break;
      case 'l':
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: Label file output directory expected");
         outLabDir = GetStrArg();
         break;
      case 'o':
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: HMM file extension expected");
         outExt = GetStrArg();
         break;
      case 'p':
         A_STEP = GetChkedFlt(0.0, 10000000.0, s);
         B_STEP = GetChkedFlt(0.0, 10000000.0, s);
         break;
      case 'r':
         mtInfo->bOrigHmmRef = TRUE;
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: HMM macro file name expected");
         s = GetStrArg();
         AddMMF(&orighset, s);
         break;
      case 's':                /* updating scale file */
         scalefn = GetStrArg();
         break;
      case 'u':
         SetuFlags();
         break;
      case 'v':
         MSDthresh = GetChkedFlt(0.0, 1.0, s);
         break;
      case 'w':
         fGVDistWght = GetChkedFlt(0.0, 1000.0, s);
         break;
      case 'x':
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: HMM file extension expected");
         hmmExt = GetStrArg();
         break;
      case 'B':
         inBinary = TRUE;
         break;
      case 'G':
         mtInfo->nGainStreamIndex = GetChkedInt(1, SMAX, s);
         mtInfo->nGainDimIndex = GetChkedInt(1, 1000, s);
         if (NextArg() == FLOATARG || NextArg() == INTARG)
            mtInfo->fGainWghtComp = GetChkedFlt(-10000.0, 1000000.0, s);
         break;
      case 'H':
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: HMM macro file name expected");
         mmfFn = GetStrArg();
         AddMMF(&hset, mmfFn);
         break;
      case 'I':
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: MLF file name expected");
         LoadMasterFile(GetStrArg());
         break;
      case 'J':                /* regression class and tree */
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: HMM regression class/tree file name expected");
         s = GetStrArg();
         AddMMF(&hset, s);
         AddMMF(&orighset, s);
         break;
      case 'K':
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: HMM transform file name expected");
         xformfn = GetStrArg();
         break;
      case 'L':
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: Label file directory expected");
         labDir = GetStrArg();
         break;
      case 'M':
         if (NextArg() != STRINGARG)
            HError(6601, "HMgeTool: Output macro file directory expected");
         outDir = GetStrArg();
         break;
      case 'T':
         trace = GetChkedInt(0, 0100000, s);
         break;
      case 'X':
         if (NextArg() != STRINGARG)
            HError(2319, "HMGenS: Label file extension expected");
         labExt = GetStrArg();
         break;
      default:
         HError(6601, "HMgeTool: Unknown switch %s", s);
      }
   }

   if (NextArg() != STRINGARG)
      HError(6601, "HMgeTool: file name of model list expected");
   hmmListFn = GetStrArg();
   Initialise();

   if (funcType == MGE_EVAL) {
      PerformMgeEval();
   } else if (funcType == MGE_TRAIN) {
      PerformMgeTrain();
      if (endIter > 0 && bMgeUpdate) {
         /* output HMM files */
         ConvDiagC(&hset, TRUE);
         SaveHMMSet(&hset, outDir, outExt, NULL, inBinary);
      }
   } else if (funcType == MGE_ADAPT) {
      PerformMgeAdapt();
      if (endIter > 0 && bMgeUpdate) {
         MakeFN(xformfn, outDir, NULL, fname);
         SaveOneXForm(&hset, hset.curXForm, fname, FALSE);
      }
   }

   ResetHeap(&hmmStack);
   ResetHeap(&orighmmStack);
   ResetHeap(&accStack);
   ResetHeap(&genStack);
   ResetHeap(&mgeStack);

   return 0;
}
Example #6
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);
}
Example #7
0
/* Initialise: set up global data structures */
void Initialise(void)
{
   Boolean eSep;
   int s;

   /* Load hmms, convert to inverse DiagC */
   if(MakeHMMSet(&hset,hmmListFn)<SUCCESS) 
      HError(3228,"Initialise: MakeHMMSet failed");
   if(LoadHMMSet(&hset,hmmDir,hmmExt)<SUCCESS) 
      HError(3228,"Initialise: LoadHMMSet failed");
   ConvDiagC(&hset,TRUE);
   
   /* Create observation and storage for input buffer */
   SetStreamWidths(hset.pkind,hset.vecSize,hset.swidth,&eSep);
   obs=MakeObservation(&gstack,hset.swidth,hset.pkind,
                       hset.hsKind==DISCRETEHS,eSep);

   /* sort out masks just in case using adaptation */
   if (xfInfo.inSpkrPat == NULL) xfInfo.inSpkrPat = xfInfo.outSpkrPat; 
   if (xfInfo.paSpkrPat == NULL) xfInfo.paSpkrPat = xfInfo.outSpkrPat; 

   if (xfInfo.useOutXForm || (update>0)) {
      CreateHeap(&regHeap,   "regClassStore",  MSTAK, 1, 0.5, 1000, 8000 );
      /* This initialises things - temporary hack - THINK!! */
      CreateAdaptXForm(&hset, "tmp");
      /* initialise structures for the f-b frame-state alignment pass */
      utt = (UttInfo *) New(&regHeap, sizeof(UttInfo));
      fbInfo = (FBInfo *) New(&regHeap, sizeof(FBInfo));
      /* initialise a recogniser for frame/state alignment purposes */
      alignpsi=InitPSetInfo(&hset);
      alignvri=InitVRecInfo(alignpsi,1,TRUE,FALSE);
      SetPruningLevels(alignvri,0,genBeam,-LZERO,0.0,tmBeam);
      InitUttInfo(utt, FALSE);
      InitialiseForBack(fbInfo, &regHeap, &hset,
                        (UPDSet) (UPXFORM), genBeam*2.0, genBeam*2.0, 
                        genBeam*4.0+1.0, 10.0);
      utt->twoDataFiles = FALSE;
      utt->S = hset.swidth[0]; 
      AttachPreComps(&hset,hset.hmem);
   }
    
   CreateHeap(&bufHeap,"Input Buffer heap",MSTAK,1,0.0,50000,50000);
   CreateHeap(&repHeap,"Replay Buffer heap",MSTAK,1,0.0,50000,50000);
   
   maxM = MaxMixInSet(&hset);
   for (s=1; s<=hset.swidth[0]; s++)
      maxMixInS[s] = MaxMixInSetS(&hset, s);
   if (trace&T_TOP) {
      printf("Read %d physical / %d logical HMMs\n",
             hset.numPhyHMM,hset.numLogHMM);  fflush(stdout);
   }
   
   /* Initialise recogniser */
   if (nToks>1) nBeam=genBeam;
   psi=InitPSetInfo(&hset);
   vri=InitVRecInfo(psi,nToks,models,states);

   /* Read dictionary and create storage for lattice */
   InitVocab(&vocab);   
   if(ReadDict(dictFn,&vocab)<SUCCESS) 
      HError(3213, "Main: ReadDict failed");
   CreateHeap(&ansHeap,"Lattice heap",MSTAK,1,0.0,4000,4000);
   if (trace & T_MEM){
      printf("Memory State After Initialisation\n");
      PrintAllHeapStats();
   }
}