switch(s[0]){ case 'b': saveLatBin = TRUE; break; case 'm': if (bType != unknown) HError(3019,"HBuild: Can only specifiy one of -m, -n, -w, -x"); bType = matBiGram;
/* GenSentences: top level control of the sentence generator */ void GenSentences(char * latfn, char * dicfn) { int i,min,max,len; double e,p; MemHeap lheap; FILE *f; Boolean isPipe; InitVocab(&voc); if(ReadDict(dicfn,&voc)<SUCCESS) HError(3413,"GenSententces:ReadDict failed" ); CreateHeap(&lheap,"Lattice Heap",MSTAK,1,0.4,1000,5000); if ((f=FOpen(latfn,NetFilter,&isPipe)) == NULL) HError(3410,"GenSentences: Can't open lattice file %s",latfn); if((lat = ReadLattice(f, &lheap, &voc, TRUE, FALSE))==NULL) HError(3410,"GenSentences: ReadLattice failed"); FClose(f,isPipe); if (trace&T_TOP) printf("HSGen %d sents from lattice %s/dictionary %s\n", ngen,latfn,dicfn); psSum = 0.0; lenSum = 0; min = 100000; max = 0; if (trace&T_DET) quiet = TRUE; /* kill output if detailed trace */ for (i=1; i<=ngen; i++){ len = GenSent(i); lenSum += len; if (len>max) max = len; if (len<min) min = len; } if (stats) { ComputeVSize(); e = psSum / lenSum; p = exp(e); e = e / log(2.0); printf("Entropy = %f, Perplexity = %f\n",e,p); printf("%d Sentences: average len = %.1f, min=%d, max=%d\n", ngen,(float)lenSum/ngen,min,max); } }
void LoadNetwork() { FILE *nf; Boolean isPipe; int n=0; CreateHeap(&wdNetHeap,"Lattice heap",MSTAK,1,0.0,4000,4000); if ( (nf = FOpen(wdNetFn,NetFilter,&isPipe)) == NULL) HError(3210,"LoadNetwork: Cannot open Word Net file %s",wdNetFn); if((wdNet = ReadLattice(nf,&wdNetHeap,&vocab,TRUE,FALSE))==NULL) HError(3210,"LoadNetwork: ReadLattice failed"); FClose(nf,isPipe); printf("Read Word Network with %d nodes / %d arcs\n",wdNet->nn,wdNet->na); CreateHeap(&netHeap,"Net heap",MSTAK,1,0, wdNet->na*sizeof(NetLink),wdNet->na*sizeof(NetLink)); net = ExpandWordNet(&netHeap,wdNet,&vocab,&hset); printf("Created network with %d nodes / %d links\n", net->numNode,net->numLink); }
/* 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); } } } }
/* 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); } }
// # Description // X方向の小さいモデルで転位を作ってX方向を拡張するためのプログラム // # Arguments // 1. ARGV[1] // cmdsファイル // # Contents of cmds // 1. コンディションファイル // 2. 作成するモデル数 // 3. 拡張したいモデルの名前 拡張したいモデルの角度 拡張後のX方向大きさ SPBC_DZ // 4. 拡張したいモデルの名前 拡張したいモデルの角度 拡張後のX方向大きさ SPBC_DZ // 5. : // 6. : // 7. : int main (int argc, char *argv[]) { LATTICE_t lattice; MD_t md, cliped_md; CONDITION_t condition; lattice.x = NULL; md.atom = NULL; int i, j, n, nx, ny, nz; char output_file_name[256], cnd_file_name[256], cmd_name[256], mdl_name[256], cmds_update_output[256], cnd_file_input[256]; double b, b_x, b_z, new_x, scale_top_x, scale_bottom_x, rad, spbc_dz; FILE *fp, *mdl_fp, *cmds_update_fp; char *home = getenv("HOME"); char file_name[256]; if(argc > 1) { sprintf (file_name, "%s", argv[1]); } else { fprintf (stdout, "ファイル名: "); fflush (stdout); fscanf (stdin, "%s", file_name); } sprintf (cmd_name, "%s/lab_src/cmds/%s.cmds", home, file_name); fp = fopen (cmd_name, "r"); if (fp == NULL) { fprintf (stdout, "%s ファイルが開けません\n", file_name); return 1; } sprintf (mdl_name, "%s/lab_src/mdls/%s.mdls", home, file_name); mdl_fp = fopen (mdl_name, "w"); sprintf (cmds_update_output, "%s/lab_src/cmds/%s_update.cmds", home, file_name); cmds_update_fp = fopen (cmds_update_output, "w"); fscanf (fp, "%s", cnd_file_name); fscanf (fp, "%d", &n); // fscanf (fp, "%lf %lf %lf", &lx, &ly, &lz); ARG_t arg[n]; sprintf (cnd_file_input, "%s/lab_src/%s", home, cnd_file_name); fprintf(cmds_update_fp, "%s\n", cnd_file_name); fprintf(cmds_update_fp, "%d\n", n); for (i = 0; i < n; i++) { fscanf (fp, "%lf%lf%lf%lf%lf%lf", &arg[i].a0, &arg[i].deg, &arg[i].clip_x, &arg[i].lx, &arg[i].ly, &arg[i].lz); } for (i = 0; i < n; i++) { InitializeAtoms (&md); InitializeAtoms (&cliped_md); InitializeLattice (&lattice); sprintf (output_file_name, "%s/lab_src/lats/bcc110_deg%.4lf.lat", home, arg[i].deg); rad = (arg[i].deg - 90.0) * M_PI / 180.0; if (ReadLattice (&lattice, output_file_name)) { GenerateLatticeType0 (&lattice, arg[i].a0); GenerateAtoms (&md, &lattice, 200, 1, 200); for (j = 0; j < md.nAtoms; j++) { md.atom[j].x -= md.lx / 2.0; md.atom[j].y -= md.ly / 2.0; md.atom[j].z -= md.lz / 2.0; } ClipAtoms (&md, &cliped_md, arg[i].clip_x, arg[i].a0 / 4.0, rad, arg[i].a0); WriteLattice (&cliped_md, output_file_name); ReadLattice (&lattice, output_file_name); } nx = ceil (arg[i].lx / lattice.lx); ny = ceil (arg[i].ly / (2.0 * lattice.ly)) * 2; // 偶数 nz = ceil (arg[i].lz / lattice.lz); GenerateAtoms (&md, &lattice, nx, ny, nz); // CheckAtomsInDiscRange (&md, md.lx / 2.0, md.ly / 2.0 + arg[i].a0 / 4.0, 0.0, 0.0, 0.0, 1.0, 11.2, md.lz * 10.0); // SetAtomType (&md, 1); // UncheckAllAtoms (&md); b = arg[i].a0 * sqrt (3) / 2.0; b_x = b * cos (rad); b_z = b * sin (rad); new_x = md.lx + b_x / 2.0; // new_x = md.lx; // 下に合わせる // new_x = md.lx + b_x; // 上に合わせる scale_top_x = new_x / (md.lx + b_x); scale_bottom_x = new_x / md.lx; spbc_dz = b_z / 2.0; // cutting from right bottom // CheckAtomsInCubeRange (&md, md.lx - b_x, md.lx, 0.0, md.ly / 2.0 - arg[i].a0 / 4.0, 0.0, md.lz); // cutting from left top CheckAtomsInCubeRange (&md, -INF, 2.0 * b_x, md.ly / 2.0 - arg[i].a0 / 4.0, INF, -INF, INF); DuplicateAtoms (&md, md.lx, 0.0, 0.0); // SetAtomType (&md, 1); UncheckAllAtoms (&md); CheckAtomsInYRange (&md, -INF, md.ly / 2.0 - arg[i].a0 / 4.0); Scale (&md, scale_bottom_x, 1.0, 1.0, scale_bottom_x, 1.0, 1.0); Deform (&md, md.lx, spbc_dz); UncheckAllAtoms (&md); CheckAtomsInYRange (&md, md.ly / 2.0 - arg[i].a0 / 4.0, INF); Scale (&md, scale_top_x, 1.0, 1.0, 1.0, 1.0, 1.0); Deform (&md, md.lx, -spbc_dz); UncheckAllAtoms (&md); // Displacement (&md, md.lx / 2.0, md.ly / 2.0 + arg[i].a0 / 4.0, b_x, b_z); CheckAtomsInYRange (&md, -INF, 10.6); CheckAtomsInYRange (&md, md.ly - 10.6, INF); SetFixAtomBC (&md, 2); UncheckAllAtoms (&md); CheckAtomsInXRange (&md, -INF, 2.0 * b_x); CheckAtomsInXRange (&md, md.lx - 2.0 * b_x, INF); ValidateDuplication (&md, spbc_dz, arg[i].a0 / 4.0); UncheckAllAtoms (&md); // sprintf (output_file_name, "deg_%lf.xxyz", arg[i].deg); // WriteAtomsToXXYZ (&md, output_file_name); ReadCondition (&condition, cnd_file_input); condition.bc.displacement_ux = cos(rad); condition.bc.displacement_uz = sin(rad); condition.bc.displacement_h = 10.6; condition.bc.stress_ex = cos(rad); condition.bc.stress_ez = sin(rad); condition.bc.spbc_dz = spbc_dz; sprintf (output_file_name, "%s_deg%.4lf_nx%d_ny%d_nz%d_mix", file_name, arg[i].deg, nx, ny, nz); fprintf(cmds_update_fp, "%s %lf %lf\n", output_file_name, arg[i].deg, spbc_dz); strcat (output_file_name, ".mdl"); WriteAtomsToMDL (&md, output_file_name, condition); fprintf(mdl_fp, "%s\n", output_file_name); } fclose (fp); fclose (mdl_fp); fclose (cmds_update_fp); return 0; }