📄 hnet.h
字号:
/* Create a new lattice structure with nn nodes and na arcs. Arcs are full-size.*/Lattice *NewILattice(MemHeap *heap,int nn,int na,Lattice *info);/* Create a new lattice structure with fields initialised by info. If nn/na == -1 the nodes/arcs will also be copied otherwise these will be set allocated (assuming nn/na!=0) and initialised with 0.*/void FreeLattice(Lattice *lat);/* Free up storage used by lattice*/ReturnStatus WriteLattice(Lattice *lat, FILE *file, LatFormat form);/* Write lattice to given file, according to given format specifier.*/Lattice *ReadLattice(FILE *file, MemHeap *heap, Vocab *voc, Boolean shortArc, Boolean add2Dict);/* Read lattice from file and creates a lattice in memory using heap. Word names in the lattice are mapped to the internal Word type using the Vocab voc. If shortArc is true, then each arc is stored in short form and cannot then support alignment information. If add2Dict is TRUE then ReadLattice will add unseen words to voc rather than generating an error.*/SubLatDef *AdjSubList(Lattice *lat,LabId subLatId,Lattice *subLat,int adj);/* Adjust list of subLatDefs (and usage counts) for lattice lat to reflect usage adjustment adj to subLat/subLatId.*/Lattice *SubLatList(Lattice *lat, Lattice *tail, int depth);/* Create an ordered list of lattices that are sub lattices of lat, adding them to tail in dependency order.*/Lattice *ExpandMultiLevelLattice(MemHeap *heap, Lattice *lat,Vocab *voc);/* Take the multi-level lattice lat and expand it into a single-level lattice using heap to create the new expanded lattice. ExpandMultiLevelLattice returns the expanded lattice.*/Lattice *LatticeFromLabels(LabList *ll,LabId bnd,Vocab *voc,MemHeap *heap);/* Convert label list into a lattice under to compute an alignment. Each word in the label list is replaced by a Word using the vocab voc. If bnd is not null, then it is inserted at the start and end of the label list. This is typically used to include a silence model.*/int NumNodeFoll(NodeId n);/* Return the number of followers (outgoing arcs) from node n*/ int NumNodePred(NodeId n);/* Return the number of predecessors (incoming arcs) to node n */ NodeId FindLatStart(Lattice *lat);/* Find and return the lattice start node, there can only be one*/ NodeId FindLatEnd(Lattice *lat);/* Find and return the lattice end node, there can only be one*//* ----------------------- Networks ------------------------ *//* Model level networks - for use with e.g. HRec *//* Types of node that can appear in the network */enum { n_unused, /* Node Instance not yet assigned */ n_hmm=2, /* Node Instance represents HMM */ n_word=4, /* Node Instance represents word end (or null) */ n_tr0=4, /* Entry token reaches exit in t=0 */ n_wd0=1, /* Exit token reaches word node in t=0 */ n_wdstart=8, /* Temporary wdstart node */ n_nocontext=15, /* binary and with this to remove context ids */ n_lcontext=16, /* Multiplication factor for context id */ n_rcontext=16384 /* Multiplication factor for context id */};typedef int NetNodeType; typedef struct _NetLink NetLink;typedef struct _NetInst NetInst;typedef struct _NetNode NetNode;/* The network nodes themselves just store connectivity info */struct _NetNode { NetNodeType type; /* Type of this node (includes context) */ union { HLink hmm; /* HMM (physical) definition */ Pron pron; /* Word represented (may == null) */ } info; /* Extra information specific to type of node */ char *tag; /* Semantic tagging information */ int nlinks; /* Number of nodes connected to this one */ NetLink *links; /* Array[0..nlinks-1] of links to connected nodes */ NetInst *inst; /* Model Instance (if one exists, else NULL) */ NetNode *chain; int aux;};struct _NetLink{ NetNode *node; /* Node in network */ LogFloat like; /* Transition likelihood */};typedef struct { MemHeap *heap; /* heap for allocating network */ Vocab *vocab; /* Dictionary from which words appear */ Word nullWord; /* Word for output when word==NULL */ Boolean teeWords; /* True if any tee words are present */ NetNode initial; /* Initial (dummy) node */ NetNode final; /* Final (dummy) node */ int numNode; int numLink; MemHeap nodeHeap; /* a heap for allocating nodes */ MemHeap linkHeap; /* a stack for adding the links as needed */ NetNode *chain;} Network;typedef struct hmmsetcxtinfo { HMMSet *hset; /* HMMSet */ int nc; /* Number of contexts */ int xc; /* Number of cross word contexts */ Boolean sLeft; /* Seen left context dependency */ Boolean sRight; /* Seen right context dependency */ LabId *cxs; /* Sorted array of labids indexed by context */ int nci; /* Number of context independent models */ LabId *cis; /* Sorted array of context independent labids */ int ncf; /* Number of context free models */ LabId *cfs; /* Sorted array of context free labids */}HMMSetCxtInfo;Network *ExpandWordNet(MemHeap *heap,Lattice *lat,Vocab *voc,HMMSet *hset);/* ExpandWordNet converts a lattice to a network. It uses the dictionary voc to expand each word in lat into a series of pronunciation instances. How this expansion is performed depends upon the hmms that appear in hset and the value of HNet configuration parameters, ALLOWCXTEXP, ALLOWXWRDEXP, FORCECXTEXP, FORCELEFTBI and FORCERIGHTBI. The expansion proceeds in four stages. i) Context definition. It is necessary for the expansion routine to determine how model names are constructed from the dictionary entries and whether cross word context expansion should be performed. Phones in the dictionary are classified as either a) Context Free. Phone is skipped when determining context. b) Context Indpendent. Phone only exists in CI form. c) Context Dependent. Otherwise phone needs modelsname expansion. This classification depends on whether a phone appears in the context part of the name (and this defines the context name) and whether and context dependent versions of the phone exist in the HMMSet. ii) Determination of network type. The default behaviour is to try and produce the simplest network possible. So if the dictionary is closed no expansion of phone names is used to get model names, otherwise if word internal context expansion will find each model this is used otherwise it tries full cross word context expansion. This behaviour can be modified by the configuration parameters. If ALLOWCXTEXP==FALSE no expansion of phone names (from the dictionary) is performed and each phone corresponds to the model of the same name. If ALLOWXWRDEXP==FALSE expansion across word boundaries is blocked and although each phone still corresponds to a single model the phone labels can be expanded to produce a context dependent model name. If FORCECXTEXP==TRUE an error will be generated if no context expansion is possible. iii) Network expansion. For cross word context expansion the initial and final context dependent phones (and any preceding/following context independent ones) are duplicated several times to allow for different cross word contexts. Each pronunciation instance has a word end node for each left context in which it appears. (!NULL words just have these word nodes). Otherwise each word in the lattice is expanded into its different pronunciations and these expanded into a node for each phone together with a word end node. (Again !NULL words just have the word end node). iv) Linking of models to network nodes. Model names are determined from the phone name and the surrounding context names. a) Construct CD name and see if model exists. b) Construct CI name and see if model exists. If ALLOWCXTEXP==FALSE (a) is skipped and if FORCECXTEXP==TRUE (b) is skipped. When no matching model is found and error is generated. The name for (a) is either a left biphone (when the right context is a boundary or FORCELEFTBI==TRUE), a right biphone (when the left context is a boundary or FORCERIGHTBI==TRUE) or a triphone. The resulting name is of the [left_context-]phone[+right_context] with the phone label coming direct from the dictionary and the context names coming from (i) above. Context free phones are skipped in this process so sil aa r sp y uw sp sil would be expanded as sil sil-aa+r aa-r+y sp r-y+uw y-uw+sil sp sil if sil was context independent and sp was context free. [ Stages (iii) and (iv) actually proceed concurrently to allow sharing of logical models with the same underlying physical model for the first and last phone of context dependent models ].*//* --- Context handling stuff useful for general network building --- */HMMSetCxtInfo *GetHMMSetCxtInfo(HMMSet *hset, Boolean frcCxtInd);/* Create HMMSetCxtInfo for hset - possibly forced to be CI.*/int GetHCIContext(HMMSetCxtInfo *hci,LabId labid);/* Search hci to find appropriate context number for labid*/Boolean IsHCIContextInd(HMMSetCxtInfo *hci,LabId labid);/* Search hci to find if labid represents a context independent model*/HLink GetHCIModel(HMMSetCxtInfo *hci,int lc,LabId name,int rc);/* Find the appropriate model for particular context*/int AddHCIContext(HMMSetCxtInfo *hci,LabId labid);/* Explicitly add phone into context set. Return its context (possibly newly added).*/#ifdef __cplusplus}#endif#endif /* _HNET_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -