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;
/* 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); } }
/* 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); } } } }
/* 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(®Heap, "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(®Heap, sizeof(UttInfo)); fbInfo = (FBInfo *) New(®Heap, 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, ®Heap, &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(); } }