void Initialise(char *hmmListFn) { /* Stacks for global structures requiring memory allocation */ CreateHeap(&aSetStack,"ASetStore", MSTAK, 1, 0.0, 1000, 1000); CreateHeap(&sSetStack,"SSetStore", MSTAK, 1, 0.0, 1000, 1000); CreateHeap(&wsStack,"WsStore", MSTAK, 1, 0.0, 1000, 1000); CreateHeap(&labIdStack,"LabIdStore", MSTAK, 1, 0.0, 1000, 1000); CreateHeap(&wtAccStack,"WtAccStore", MSTAK, 1, 0.0, 1000, 1000); /* Load HMMs and init HMMSet related global variables */ if(MakeHMMSet( &hset, hmmListFn )<SUCCESS) HError(2429,"Initialise: MakeHMMSet failed"); if(LoadHMMSet( &hset,hmmDir,newExt)<SUCCESS) HError(2429,"Initialise: LoadHMMSet failed"); AttachAccs(&hset, &gstack,uFlags); ZeroAccs(&hset,uFlags); nPhyHmms = hset.numPhyHMM; nLogHmms = hset.numLogHMM; vSize = hset.vecSize; nStreams = hset.swidth[0]; maxMixes = MaxMixInSet(&hset); maxStates = MaxStatesInSet(&hset); hsKind = hset.hsKind; /* Store for mix weights accs from each input acc file */ CreateWtStore(&wtAccStack); if ((hsKind != TIEDHS) && (hsKind != DISCRETEHS)) HError(2421,"Initialise: HMM's must be full Tied Mixture or Discrete"); if (trace&T_TOP) { printf("HSmooth Updating: "); if (uFlags&UPTRANS) printf("Transitions "); if (uFlags&UPMEANS) printf("Means "); if (uFlags&UPVARS) printf("Variances "); if (uFlags&UPMIXES && maxMixes>1) printf("MixWeights "); printf("\n "); printf(" Max Steps: %d, Epsilon : %f, Max Mixes: %d\n", maxStep,epsilon,maxMixes); printf("%d Logical/%d Physical Models Loaded, VecSize=%d\n",nLogHmms,nPhyHmms,vSize); fflush(stdout); } SetVFloor( &hset, vFloor, minVar); aSet=(HLink *)New(&aSetStack, nPhyHmms*sizeof(HLink)); --aSet; sSet=(StreamElem **)New(&sSetStack, nPhyHmms*sizeof(StreamElem *)); --sSet; }
/* EXPORT->PItemList: parse items in item list setting ilist and type */ char *PItemList(ILink *ilist, char *type, HMMSet *hset, Source *s, Boolean itrace) { int rtrace; /* Initialise static variables */ rtrace=trace; if (itrace) trace|=T_ITM; source = s; maxMixes = MaxMixInSet(hset); maxStates = MaxStatesInSet(hset); position=pattern; *position=0; /* Parse item set */ ReadCh(); SkipSpaces(); if (ch != '{') EdError("{ expected"); ReadCh(); PItemSet(ilist,type,hset); SkipSpaces(); while (ch == ',') { ReadCh(); PItemSet(ilist,type,hset); SkipSpaces(); } if (ch != '}') EdError("} expected"); if (trace & T_ITM) fflush(stdout); trace=rtrace; return(pattern); }
/* InitMgeTrnInfo: Initialize all info struct for MGE training */ static void InitMgeTrnInfo() { int i, p, nWin; /* setup GenInfo */ genInfo->genMem = &genStack; genInfo->hset = &hset; genInfo->maxStates = MaxStatesInSet(&hset); genInfo->MSDthresh = MSDthresh; genInfo->frameRate = frameRate; genInfo->stateAlign = TRUE; CheckGenSetUp(); /* setup MTStatInfo */ statInfo->order = GetTotalOrder(mtInfo->genInfo); for (p = 1; p <= genInfo->nPdfStream[0]; p++) { statInfo->initErrAcc[p] = CreateDVector(&gstack, genInfo->pst[p].order * 2); statInfo->prevErrAcc[p] = CreateDVector(&gstack, genInfo->pst[p].order * 2); statInfo->currErrAcc[p] = CreateDVector(&gstack, genInfo->pst[p].order * 2); ZeroDVector(statInfo->initErrAcc[p]); ZeroDVector(statInfo->prevErrAcc[p]); ZeroDVector(statInfo->currErrAcc[p]); } nWin = mtInfo->genInfo->pst[1].win.num; for (p = 1; p <= genInfo->nPdfStream[0]; p++) { statInfo->pnMeanFloor[p] = (IMatrix *) New(&gstack, statInfo->order * sizeof(IMatrix *)); statInfo->pnMeanFloor[p]--; statInfo->pnVarFloor[p] = (IMatrix *) New(&gstack, statInfo->order * sizeof(IMatrix *)); statInfo->pnVarFloor[p]--; for (i = 1; i <= statInfo->order; i++) { statInfo->pnMeanFloor[p][i] = CreateIMatrix(&gstack, nWin, 2); /* 2: High & Low floor */ ZeroIMatrix(statInfo->pnMeanFloor[p][i]); statInfo->pnVarFloor[p][i] = CreateIMatrix(&gstack, nWin, 2); /* 2: High & Low floor */ ZeroIMatrix(statInfo->pnVarFloor[p][i]); } } /* setup MgeTrnInfo */ mtInfo->nBoundAdjWin = nBoundAdjWin; mtInfo->fGVDistWght = fGVDistWght; mtInfo->uFlags = uFlags; mtInfo->funcType = funcType; for (p = 1; p <= genInfo->nPdfStream[0]; p++) { mtInfo->SRMean[p] = CreateVector(&gstack, genInfo->pst[p].order); mtInfo->SRVar[p] = CreateVector(&gstack, genInfo->pst[p].order); mtInfo->DWght[p] = CreateVector(&gstack, genInfo->pst[p].order); ZeroVector(mtInfo->SRMean[p]); ZeroVector(mtInfo->SRVar[p]); ZeroVector(mtInfo->DWght[p]); } if (scalefn != NULL) { LoadScaleRate(scalefn); mtInfo->bMScale = TRUE; } else mtInfo->bMScale = FALSE; CheckMTInfoSetUp(); return; }
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); }
/* CreateDecoderInst Create a new instance of the decoding engine. All state information is stored here. #### Ideally instances should share other structures (i.e. LexNets) this is not implemented, yet. */ DecoderInst *CreateDecoderInst(HMMSet *hset, FSLM *lm, int nTok, Boolean latgen, Boolean useHModel, int outpBlocksize, Boolean doPhonePost, Boolean modAlign) { DecoderInst *dec; int i, N; char buf[MAXSTRLEN]; dec = (DecoderInst *) New (&recCHeap, sizeof (DecoderInst)); dec->lm = lm; dec->hset = hset; dec->useHModel = useHModel; /* dec->net = net; */ /* create compact State info. This can change number of shared states! */ /* #### this is ugly as we end up doing this twice, if we use adaptation! */ dec->si = ConvertHSet (&gcheap, hset, dec->useHModel); CreateHeap (&dec->heap, "Decoder Instance heap", MSTAK, 1, 1.5, 10000, 100000); CreateHeap (&dec->nodeInstanceHeap, "Decoder NodeInstance heap", MHEAP, sizeof (LexNodeInst), 1.5, 1000, 10000); dec->nTok = nTok; dec->latgen = latgen; dec->nLayers = 0; dec->instsLayer = NULL; /* alloc & init Heaps for TokenSets */ N = MaxStatesInSet (dec->hset); dec->maxNStates = N; dec->tokSetHeap = (MemHeap *) New (&dec->heap, N * sizeof (MemHeap)); /* #### make initial size of heap blocks smaller, or don't alloc unneeded ones in the first place (scan HMMSet) */ for (i = 0; i < N; ++i) { sprintf (buf, "Decoder %d TokenSet heap", i+1); CreateHeap (&dec->tokSetHeap[i], buf, MHEAP, (i+1) * sizeof (TokenSet), 9, 10, 5000); } dec->tempTS = (TokenSet **) New (&dec->heap, (N+1) * sizeof (TokenSet *)); /* alloc Heap for RelToken arrays */ CreateHeap (&dec->relTokHeap, "Decoder RelToken array heap", MHEAP, dec->nTok * sizeof (RelToken), 1, 1000, 5000); /* alloc heap for word end hyps */ CreateHeap (&dec->weHypHeap, "WordendHyp heap", MHEAP, sizeof (WordendHyp), 1.0, 80000, 800000); if (dec->latgen) { CreateHeap (&dec->altweHypHeap, "AltWordendHyp heap", MHEAP, sizeof (AltWordendHyp), 1.0, 8000, 80000); } #ifdef MODALIGN dec->modAlign = modAlign; if (dec->modAlign) { CreateHeap (&dec->modendHypHeap, "ModendHyp heap", MHEAP, sizeof (ModendHyp), 1.0, 80000, 800000); } #else if (modAlign) HError (9999, "CreateDecoderInst: model alignment not supported; recompile with MODALIGN"); #endif /* output probability cache */ dec->outPCache = CreateOutPCache (&dec->heap, dec->hset, outpBlocksize); /* cache debug code */ #if 0 printf (" %d %d \n", dec->hset->numStates, dec->nCacheFlags); for (i = 0; i < dec->nCacheEntries; ++i) printf ("i %d cacheFlags %lu\n", i, dec->cacheFlags[i]); for (i = 0; i < dec->hset->numStates; ++i) { assert (!CACHE_FLAG_GET(dec,i)); CACHE_FLAG_SET(dec, i); assert (CACHE_FLAG_GET(dec,i)); } /* printf ("i %d C_G %lu\n", i, CACHE_FLAG_GET(dec,i)); */ #endif /* tag left-to-right models */ { HMMScanState hss; NewHMMScan(dec->hset,&hss); do { /* #### should check each tidX only once! */ /* if (!IsSeenV(hss.hmm->transP)) { */ if (CheckLRTransP (hss.hmm->transP)) hss.hmm->tIdx *= -1; /* TouchV(hss.hmm->transP); */ } while(GoNextHMM(&hss)); EndHMMScan(&hss); } if (doPhonePost) InitPhonePost (dec); else dec->nPhone = 0; return dec; }