📄 hnet.h
字号:
/* ----------------------------------------------------------- *//* *//* ___ *//* |_| | |_/ SPEECH *//* | | | | \ RECOGNITION *//* ========= SOFTWARE */ /* *//* *//* ----------------------------------------------------------- *//* developed at: *//* *//* Speech Vision and Robotics group *//* Cambridge University Engineering Department *//* http://svr-www.eng.cam.ac.uk/ *//* *//* Entropic Cambridge Research Laboratory *//* (now part of Microsoft) *//* *//* ----------------------------------------------------------- *//* Copyright: Microsoft Corporation *//* 1995-2000 Redmond, Washington USA *//* http://www.microsoft.com *//* *//* 2001-2002 Cambridge University *//* Engineering Department *//* *//* Use of this software is governed by a License Agreement *//* ** See the file License for the Conditions of Use ** *//* ** This banner notice must not be removed ** *//* *//* ----------------------------------------------------------- *//* File: HNet.h Network and Lattice Functions *//* ----------------------------------------------------------- *//* !HVER!HNET: 3.3 [CUED 28/04/05] *//* Nets come in two forms. a) Lattices are used to represent word level networks. b) Networks used by HRec for viterbi decoding. The network reads in a word level network in the form of a lattice. To reduce storage requirements for this lattice (which could be very large) the lattice uses a compact storage representation which does not contain many of the optional lattice fields. This lattice is then expanded into the network required for HRec. Finally HRec produces a lattice as output in which the lattice arcs use the full format and contain additional information rather than just the language model likelihood.*/#ifndef _HNET_H_#define _HNET_H_#ifdef __cplusplusextern "C" {#endif/* ------------------------ Initialisation --------------------------- */void InitNet(void);/* register module & set configuration parameters*//* -------------------- Lattice Definintions ------------------------- *//* Lattice Types and Routines. These are used for all word-level networks */#define L_VERSION "1.0" /* Version written to header of all lattices */typedef int LatFormat; /* Format of lattice. Formed by oring flags */#define HLAT_ALABS 0x0001 /* Word labels with arcs (normally with nodes) */#define HLAT_LBIN 0x0002 /* Binary lattices for speed */#define HLAT_TIMES 0x0008 /* Node times */#define HLAT_PRON 0x0010 /* Pronunciation information */#define HLAT_ACLIKE 0x0020 /* Acoustic likelihoods */#define HLAT_LMLIKE 0x0040 /* Language model likelihoods (and scale etc) */#define HLAT_ALIGN 0x0080 /* Output within word alignment (if present) */#define HLAT_ALDUR 0x0100 /* Output within word alignment durations */#define HLAT_ALLIKE 0x0200 /* Output within word alignment likelihoods */#define HLAT_PRLIKE 0x0400 /* Pronunciation likelihoods (and scale etc) */#define HLAT_TAGS 0x0800 /* Output semantic tags */#define HLAT_NOSORT 0x1000 /* Do not sort lattice before output */#define HLAT_NOSUBS 0x2000 /* Do not output sublats *//* #define HLAT_EXTEN 0x2000 Using extensible versions of everything */#define HLAT_SHARC 0x4000 /* Using short version of arc data structures */#define HLAT_DEFAULT 0x03f8 /* Default output format */typedef struct lnode *NodeId;typedef struct larc *ArcId;#define NARC NULL /* NULL arcid for end of linked lists */#define NNODE NULL /* NULL nodeid for end of linked lists */typedef struct lalign { int state; /* State number (-1==model_end) */ LabId label; /* Segment label ('phys_hmm[state]' or 'phys_hmm') */ float dur; /* Duration of segment in seconds */ LogFloat like; /* Total aclike of label (inc trans within + out) */}LAlign;/* Storage of SubLats */typedef struct sublatdef { struct lattice *lat; /* Lattice this refers to (may be shared) */ int usage; /* Number of references to this SubLat */ struct sublatdef *next; /* Next sublat at this level */ /* struct sublatdef *prev; Previous sublat at this level */ struct sublatdef *chain; /* Next sublat referring to lat */} SubLatDef;/* Note the following is not standard C. In order to accomodate compact arcs we need to know how big they are so we define larc_s as a type solely to be used in sizeof calculations to allow us to find out how big the first five fields of larc are.*/typedef struct larc_s{ NodeId start; NodeId end; LogFloat lmlike; ArcId farc; ArcId parc;}LArc_S;typedef struct larc_e *EArcId;typedef struct larc_e{ NodeId start; /* Node at start of word */ NodeId end; /* Node at end of word */ LogFloat lmlike; /* Language model likelihood of word */ EArcId farc; /* Next arc following start node */ EArcId parc; /* Next arc preceding end node */ EArcId fcra; /* List linked in both directions */ EArcId pcra; /* to easy deletetion */ int n; /* Arc identity */ /* Ptr hook; Hook - For 64 bit machines this is too big */}LArc_E;typedef struct larc{ NodeId start; /* Node at start of word */ NodeId end; /* Node at end of word */ LogFloat lmlike; /* Language model likelihood of word */ ArcId farc; /* Next arc following start node */ ArcId parc; /* Next arc preceding end node */ LogFloat aclike; /* Acoustic likelihood of word */ short nAlign; /* Number of alignment records in word */ LAlign *lAlign; /* Array[0..nAlign-1] of alignment records */ float score; /* Field used for pruning/sorting */ LogFloat prlike; /* Pronunciation likelihood of arc */}LArc;/* Note: Total arc likelihood == aclike + lmlike*lmscale + wdpenalty */typedef struct lnode{ int n; /* Sorted order */ Word word; /* Word represented by arc (labels may be on nodes) */ char *tag; /* Semantic tag for this node */ short v; /* Pronunciation variant number */ SubLatDef *sublat; /* SubLat for node (if word==lat->voc->subLatWord) */ HTime time; /* Time of word boundary at node */ ArcId foll; /* Linked list of arcs following node */ ArcId pred; /* Linked list of arcs preceding node */ double score; /* Field used for pruning */ Ptr hook; /* User definable hook */}LNode;typedef struct lattice{ MemHeap *heap; /* Heap lattice uses */ LatFormat format; /* indicate which fields are valid */ Vocab *voc; /* Dictionary lattice based on */ int nn; /* Number of nodes */ int na; /* Number of arcs */ LNode *lnodes; /* Array of lattice nodes */ LArc *larcs; /* Array of lattice arcs */ LabId subLatId; /* Lattice Identifier (for SubLats only) */ SubLatDef *subList; /* List of sublats in this lattice level */ SubLatDef *refList; /* List of all SubLats referring to this lat */ struct lattice *chain; /* Linked list used for various jobs */ char *utterance; /* Utterance file name (NULL==unknown) */ char *vocab; /* Dictionary file name (NULL==unknown) */ char *hmms; /* MMF file name (NULL==unknown) */ char *net; /* Network file name (NULL==unknown) */ float acscale; /* Acoustic scale factor */ float lmscale; /* LM scale factor */ LogFloat wdpenalty; /* Word insertion penalty */ float prscale; /* Pronunciation scale factor */ HTime framedur; /* Frame duration in 100ns units */ float logbase; /* base of logarithm for likelihoods in lattice files (1.0 = default (e), 0.0 = no logs) */ float tscale; /* time scale factor (default: 1, i.e. seconds) */ Ptr hook; /* User definable hook */}Lattice;/* To use both long and short formats for lattice arcs should use the following macros to access the arcs.*//*#define NumbLArc(lat,n) ((lat)->format&HLAT_EXTEN?(lat)->larcs+(n):\ (lat)->format&HLAT_SHARC?\ (LArc*)(((LArc_S*)(lat)->larcs)+(n)):(lat)->larcs+(n))*/#define NumbLArc(lat,n) ((lat)->format&HLAT_SHARC?\ (LArc*)(((LArc_S*)(lat)->larcs)+(n)):(lat)->larcs+(n))#define LArcNumb(la,lat) ((lat)->format&HLAT_SHARC?\ (((LArc_S*)(la))-((LArc_S*)(lat)->larcs)):\ (la)-(lat)->larcs)#define NextLArc(lat,la) (LArc*)((char*)la+((lat->format&HLAT_SHARC)?\ sizeof(LArc_S):sizeof(LArc)))#define LArcTotLMLike(lat,la) ((la)->lmlike*(lat)->lmscale + \ (((la)->end->word==NULL || \ (la)->end->word==(lat)->voc->nullWord) ? \ 0.0 : (lat)->wdpenalty ))#define LArcTotLike(lat,la) ((la)->aclike*(lat)->acscale + \ (la)->lmlike*(lat)->lmscale + \ (la)->prlike*(lat)->prscale + \ (((la)->end->word==NULL || \ (la)->end->word==(lat)->voc->nullWord) ? \ 0.0 : (lat)->wdpenalty ))Lattice *NewLattice(MemHeap *heap, int nn, int na);/* Create a new lattice structure with nn nodes and na arcs. Arcs
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -