Viterbi history structures. Mainly vithist_t, also its slightly older brother latticehist_t. They are respectively used by decode (mode 4 and 5) and decode_anytopo (mode 3). The curent arrangement is temporary. More...
#include <stdio.h>#include <s3types.h>#include <cmd_ln.h>#include <logmath.h>#include <glist.h>#include "kbcore.h"#include "search.h"#include "dict.h"#include "lm.h"#include "fillpen.h"#include "dag.h"#include "ctxt_table.h"Go to the source code of this file.
Classes | |
| union | vh_lmstate_u |
| struct | backpointer_s |
| struct | vithist_entry_t |
| struct | vh_lms2vh_t |
| struct | vithist_t |
| struct | lattice_s |
| struct | latticehist_t |
Defines | |
| #define | vithist_entry_wid(ve) ((ve)->wid) |
| #define | vithist_entry_sf(ve) ((ve)->sf) |
| #define | vithist_entry_ef(ve) ((ve)->ef) |
| #define | vithist_entry_ascr(ve) ((ve)->ascr) |
| #define | vithist_entry_lscr(ve) ((ve)->lscr) |
| #define | vithist_entry_score(ve) ((ve)->path.score) |
| #define | vithist_entry_pred(ve) ((ve)->path.pred) |
| #define | vithist_entry_valid(ve) ((ve)->valid) |
| #define | VITHIST_BLKSIZE 16384 |
| #define | VITHIST_MAXBLKS 256 |
| #define | VITHIST_ID2BLK(i) ((i) >> 14) |
| #define | VITHIST_ID2BLKOFFSET(i) ((i) & 0x00003fff) |
| #define | vithist_id2entry(vh, id) ((vh)->entry[VITHIST_ID2BLK(id)] + VITHIST_ID2BLKOFFSET(id)) |
| #define | vithist_n_entry(vh) ((vh)->n_entry) |
| #define | vithist_bestscore(vh) ((vh)->bestscore) |
| #define | vithist_bestvh(vh) ((vh)->bestvh) |
| #define | vithist_lms2vh_root(vh, w) ((vh)->lms2vh_root[w]) |
| #define | vithist_lwidlist(vh) ((vh)->lwidlist) |
| #define | vithist_first_entry(vh, f) ((vh)->frame_start[f]) |
| #define | vithist_last_entry(vh, f) ((vh)->frame_start[f+1] - 1) |
| #define | LAT_ALLOC_INCR 32768 |
| #define | LATID2SF(hist, l) |
| #define | latticehist_n_cand(hist) ((hist)->n_cand) |
| #define | latticehist_lat_alloc(hist) ((hist)->lat_alloc) |
| #define | latticehist_n_lat_entry(hist) ((hist)->n_lat_entry) |
Typedefs | |
| typedef union vh_lmstate_u | vh_lmstate_t |
| typedef struct backpointer_s | backpointer_t |
| typedef struct lattice_s | lattice_t |
Functions | |
| vithist_t * | vithist_init (kbcore_t *kbc, int32 wbeam, int32 bghist, int32 report) |
| int32 | vithist_utt_begin (vithist_t *vh, kbcore_t *kbc) |
| int32 | vithist_utt_end (vithist_t *vh, kbcore_t *kbc) |
| int32 | vithist_partialutt_end (vithist_t *vh, kbcore_t *kbc) |
| void | vithist_utt_reset (vithist_t *vh) |
| glist_t | vithist_backtrace (vithist_t *vh, int32 id, dict_t *dict) |
| void | vithist_enter (vithist_t *vh, kbcore_t *kbc, vithist_entry_t *tve, int32 comp_rc) |
| void | vithist_rescore (vithist_t *vh, kbcore_t *kbc, s3wid_t wid, int32 ef, int32 score, int32 pred, int32 type, int32 rc) |
| void | vithist_frame_windup (vithist_t *vh, int32 frm, FILE *fp, kbcore_t *kbc) |
| void | vithist_prune (vithist_t *vh, dict_t *dict, int32 frm, int32 maxwpf, int32 maxhist, int32 beam) |
| void | vithist_dump (vithist_t *vh, int32 frm, kbcore_t *kbc, FILE *fp) |
| dag_t * | vithist_dag_build (vithist_t *vh, glist_t hyp, dict_t *dict, int32 endid, cmd_ln_t *config, logmath_t *logmath) |
| int32 | vithist_dag_write (vithist_t *vithist, const char *filename, dag_t *dag, lm_t *lm, dict_t *dict) |
| void | vithist_free (vithist_t *vh) |
| void | vithist_report (vithist_t *vh) |
| void | vh_lmstate_display (vh_lmstate_t *vhl, dict_t *dict) |
| void | vithist_entry_display (vithist_entry_t *ve, dict_t *dict) |
| latticehist_t * | latticehist_init (int32 init_alloc_size, int32 num_frames) |
| void | latticehist_free (latticehist_t *lat) |
| void | latticehist_reset (latticehist_t *lat) |
| void | latticehist_dump (latticehist_t *lathist, FILE *fp, dict_t *dict, ctxt_table_t *ct, int32 dumpRC) |
| void | lattice_entry (latticehist_t *lathist, s3wid_t w, int32 f, int32 score, s3latid_t history, int32 rc, ctxt_table_t *ct, dict_t *dict) |
| void | two_word_history (latticehist_t *lathist, s3latid_t l, s3wid_t *w0, s3wid_t *w1, dict_t *dict) |
| int32 | lat_pscr_rc (latticehist_t *lathist, s3latid_t l, s3wid_t w_rc, ctxt_table_t *ct, dict_t *dict) |
| s3latid_t | lat_pscr_rc_history (latticehist_t *lathist, s3latid_t l, s3wid_t w_rc, ctxt_table_t *ct, dict_t *dict) |
| int32 | lat_seg_lscr (latticehist_t *lathist, s3latid_t l, lm_t *lm, dict_t *dict, ctxt_table_t *ct, fillpen_t *fillpen, int32 isCand) |
| void | lat_seg_ascr_lscr (latticehist_t *lathist, s3latid_t l, s3wid_t w_rc, int32 *ascr, int32 *lscr, lm_t *lm, dict_t *dict, ctxt_table_t *ct, fillpen_t *fillpen) |
| s3latid_t | lat_final_entry (latticehist_t *lathist, dict_t *dict, int32 curfrm, char *uttid) |
| srch_hyp_t * | lattice_backtrace (latticehist_t *lathist, s3latid_t l, s3wid_t w_rc, srch_hyp_t **hyp, lm_t *lm, dict_t *dict, ctxt_table_t *ct, fillpen_t *fillpen) |
| dag_t * | latticehist_dag_build (latticehist_t *vh, glist_t hyp, dict_t *dict, lm_t *lm, ctxt_table_t *ctxt, fillpen_t *fpen, int32 endid, cmd_ln_t *config, logmath_t *logmath) |
| int32 | latticehist_dag_write (latticehist_t *lathist, const char *filename, dag_t *dag, lm_t *lm, dict_t *dict, ctxt_table_t *ct, fillpen_t *fillpen) |
Viterbi history structures. Mainly vithist_t, also its slightly older brother latticehist_t. They are respectively used by decode (mode 4 and 5) and decode_anytopo (mode 3). The curent arrangement is temporary.
| #define LAT_ALLOC_INCR 32768 |
| #define LATID2SF | ( | hist, | |||
| l | ) |
(IS_S3LATID(hist->lattice[l].history) ? \ hist->lattice[hist->lattice[l].history].frm + 1 : 0)
| #define latticehist_lat_alloc | ( | hist | ) | ((hist)->lat_alloc) |
| #define latticehist_n_cand | ( | hist | ) | ((hist)->n_cand) |
| #define latticehist_n_lat_entry | ( | hist | ) | ((hist)->n_lat_entry) |
| #define vithist_bestscore | ( | vh | ) | ((vh)->bestscore) |
Return the best score of the Viterbi history
| #define vithist_bestvh | ( | vh | ) | ((vh)->bestvh) |
Return the best viterbi history entry ID of the Viterbi history
| #define VITHIST_BLKSIZE 16384 |
| #define vithist_entry_ascr | ( | ve | ) | ((ve)->ascr) |
Return the acoustic score of an entry
| #define vithist_entry_ef | ( | ve | ) | ((ve)->ef) |
Return the ending frame of an entry
| #define vithist_entry_lscr | ( | ve | ) | ((ve)->lscr) |
Return the language score of an entry
| #define vithist_entry_pred | ( | ve | ) | ((ve)->path.pred) |
| #define vithist_entry_score | ( | ve | ) | ((ve)->path.score) |
Return the total score of an entry
| #define vithist_entry_sf | ( | ve | ) | ((ve)->sf) |
Return the starting frame of an entry
| #define vithist_entry_valid | ( | ve | ) | ((ve)->valid) |
| #define vithist_entry_wid | ( | ve | ) | ((ve)->wid) |
Return the word ID of an entry
| #define vithist_first_entry | ( | vh, | |||
| f | ) | ((vh)->frame_start[f]) |
Return the first entry for the frame f
| #define VITHIST_ID2BLK | ( | i | ) | ((i) >> 14) |
| #define VITHIST_ID2BLKOFFSET | ( | i | ) | ((i) & 0x00003fff) |
| #define vithist_id2entry | ( | vh, | |||
| id | ) | ((vh)->entry[VITHIST_ID2BLK(id)] + VITHIST_ID2BLKOFFSET(id)) |
Access macros; not meant for arbitrary use Return a pointer to the entry with the given ID.
| #define vithist_last_entry | ( | vh, | |||
| f | ) | ((vh)->frame_start[f+1] - 1) |
Return the last entry for the frame f
| #define vithist_lms2vh_root | ( | vh, | |||
| w | ) | ((vh)->lms2vh_root[w]) |
Return lms2vh
| #define vithist_lwidlist | ( | vh | ) | ((vh)->lwidlist) |
Return the language word ID list
| #define VITHIST_MAXBLKS 256 |
| #define vithist_n_entry | ( | vh | ) | ((vh)->n_entry) |
Return the number of entry in the Viterbi history
| typedef struct backpointer_s backpointer_t |
| typedef union vh_lmstate_u vh_lmstate_t |
LM state. Depending on type of LM (word-ngram, class-ngram, FSG, etc.), the contents of LM state will vary. Accommodate them with a union. For now, only trigram LM in it. (Not completely thought out; some of this might have to change later.)
| s3latid_t lat_final_entry | ( | latticehist_t * | lathist, | |
| dict_t * | dict, | |||
| int32 | curfrm, | |||
| char * | uttid | |||
| ) |
Get the final entry of the lattice
| lathist | A table of lattice entries | |
| curfrm | The dictioanry The current frame | |
| uttid | Utterance ID |
| int32 lat_pscr_rc | ( | latticehist_t * | lathist, | |
| s3latid_t | l, | |||
| s3wid_t | w_rc, | |||
| ctxt_table_t * | ct, | |||
| dict_t * | dict | |||
| ) |
Find path score for lattice entry l for the given right context word. If context word is BAD_S3WID it's a wild card; return the best path score.
| lathist | A table of lattice entries | |
| l | lattice ID | |
| w_rc | The right context word | |
| ct | Context table | |
| dict | The dictionary |
| s3latid_t lat_pscr_rc_history | ( | latticehist_t * | lathist, | |
| s3latid_t | l, | |||
| s3wid_t | w_rc, | |||
| ctxt_table_t * | ct, | |||
| dict_t * | dict | |||
| ) |
Find path history for lattice entry l for the given right context word. If context word is BAD_S3WID it's a wild card; return the phone history.
| lathist | A table of lattice entries | |
| l | lattice ID | |
| w_rc | The right context word | |
| ct | Context table | |
| dict | The dictionary |
| void lat_seg_ascr_lscr | ( | latticehist_t * | lathist, | |
| s3latid_t | l, | |||
| s3wid_t | w_rc, | |||
| int32 * | ascr, | |||
| int32 * | lscr, | |||
| lm_t * | lm, | |||
| dict_t * | dict, | |||
| ctxt_table_t * | ct, | |||
| fillpen_t * | fillpen | |||
| ) |
Find LM score for transition into lattice entry l.
| lathist | A table of lattice entries | |
| l | lattice ID | |
| w_rc | The right context word | |
| ascr | Out: Acoustic score | |
| lscr | Out: language score | |
| lm | LM | |
| dict | Dictionary | |
| fillpen | Context table filler penalty |
Referenced by flat_fwd_dag_add_fudge_edges().
| int32 lat_seg_lscr | ( | latticehist_t * | lathist, | |
| s3latid_t | l, | |||
| lm_t * | lm, | |||
| dict_t * | dict, | |||
| ctxt_table_t * | ct, | |||
| fillpen_t * | fillpen, | |||
| int32 | isCand | |||
| ) |
| srch_hyp_t* lattice_backtrace | ( | latticehist_t * | lathist, | |
| s3latid_t | l, | |||
| s3wid_t | w_rc, | |||
| srch_hyp_t ** | hyp, | |||
| lm_t * | lm, | |||
| dict_t * | dict, | |||
| ctxt_table_t * | ct, | |||
| fillpen_t * | fillpen | |||
| ) |
Backtrace the lattice and get back a search hypothesis.
| lathist | A table of lattice entries | |
| l | The lattice ID | |
| w_rc | The word on the right | |
| hyp | Output: final hypothesis | |
| lm | LM | |
| dict | Dictionary | |
| ct | Context table | |
| fillpen | filler penalty struct |
| void lattice_entry | ( | latticehist_t * | lathist, | |
| s3wid_t | w, | |||
| int32 | f, | |||
| int32 | score, | |||
| s3latid_t | history, | |||
| int32 | rc, | |||
| ctxt_table_t * | ct, | |||
| dict_t * | dict | |||
| ) |
Enter a entry into lattice
| lathist | A table of lattice entries | |
| w | Word ID to enter. | |
| f | current frame number | |
| score | The score to enter, usually it is the score of the final state of hmm | |
| history | The last lattice entry to enter, usually the entry of the final state of hmm is used. | |
| rc | Right context of the HMM | |
| ct | A context table | |
| dict | A dictionary |
Referenced by whmm_exit().
| dag_t* latticehist_dag_build | ( | latticehist_t * | vh, | |
| glist_t | hyp, | |||
| dict_t * | dict, | |||
| lm_t * | lm, | |||
| ctxt_table_t * | ctxt, | |||
| fillpen_t * | fpen, | |||
| int32 | endid, | |||
| cmd_ln_t * | config, | |||
| logmath_t * | logmath | |||
| ) |
Build a DAG from the lattice: each unique <word-id,start-frame> is a node, i.e. with a single start time but it can represent several end times. Links are created whenever nodes are adjacent in time. dagnodes_list = linear list of DAG nodes allocated, ordered such that nodes earlier in the list can follow nodes later in the list, but not vice versa: Let two DAG nodes d1 and d2 have start times sf1 and sf2, and end time ranges [fef1..lef1] and [fef2..lef2] respectively. If d1 appears later than d2 in dag.list, then fef2 >= fef1, because d2 showed up later in the word lattice. If there is a DAG edge from d1 to d2, then sf1 > fef2. But fef2 >= fef1, so sf1 > fef1. Reductio ad absurdum.
| int32 latticehist_dag_write | ( | latticehist_t * | lathist, | |
| const char * | filename, | |||
| dag_t * | dag, | |||
| lm_t * | lm, | |||
| dict_t * | dict, | |||
| ctxt_table_t * | ct, | |||
| fillpen_t * | fillpen | |||
| ) |
Write a dag from latticehist_t
| lathist | A table off lattice entries |
| void latticehist_dump | ( | latticehist_t * | lathist, | |
| FILE * | fp, | |||
| dict_t * | dict, | |||
| ctxt_table_t * | ct, | |||
| int32 | dumpRC | |||
| ) |
Dump the lattice history table
| lathist | A table of lattice entries | |
| fp | File pointer where one would want to dump the lattice | |
| dict | The dictionary | |
| ct | Context table | |
| dumpRC | Whether we whould dump all the scores and histories for right context |
| void latticehist_free | ( | latticehist_t * | lat | ) |
Free lattice history table
| lat | The latticie history table |
| latticehist_t* latticehist_init | ( | int32 | init_alloc_size, | |
| int32 | num_frames | |||
| ) |
Initialization of lattice history table
| init_alloc_size | Initial allocation size | |
| num_frames | Number of frames in represented in the lattice |
| void latticehist_reset | ( | latticehist_t * | lat | ) |
| lat | The lattice history table |
| void two_word_history | ( | latticehist_t * | lathist, | |
| s3latid_t | l, | |||
| s3wid_t * | w0, | |||
| s3wid_t * | w1, | |||
| dict_t * | dict | |||
| ) |
| void vh_lmstate_display | ( | vh_lmstate_t * | vhl, | |
| dict_t * | dict | |||
| ) |
Display the lmstate of an entry.
| vhl | In: An lmstate data structure | |
| dict | In: If specified, the word string of lm IDs would also be translated |
Viterbi backtrace. Return value: List of hyp_t pointer entries for the individual word segments. Caller responsible for freeing the list.
| vh | In: a Viterbi history data structure | |
| id | ID from which to begin backtrace | |
| dict | a dictionary for look up the ci phone of a word |
| dag_t* vithist_dag_build | ( | vithist_t * | vh, | |
| glist_t | hyp, | |||
| dict_t * | dict, | |||
| int32 | endid, | |||
| cmd_ln_t * | config, | |||
| logmath_t * | logmath | |||
| ) |
Build a word graph (DAG) from Viterbi history.
| int32 vithist_dag_write | ( | vithist_t * | vithist, | |
| const char * | filename, | |||
| dag_t * | dag, | |||
| lm_t * | lm, | |||
| dict_t * | dict | |||
| ) |
Write a word graph (DAG) built from Viterbi history (temporary function)
Dump the Viterbi history data to the given file (for debugging/diagnostics).
| vh | In: a Viterbi history data structure | |
| frm | In: If >= 0, print only entries made in this frame, otherwise print all entries | |
| kbc | In: a KBcore | |
| fp | Out: File to be written |
| void vithist_enter | ( | vithist_t * | vh, | |
| kbcore_t * | kbc, | |||
| vithist_entry_t * | tve, | |||
| int32 | comp_rc | |||
| ) |
Add an entry to the Viterbi history table without rescoring. Any entry having the same LM state will be replaced with the one given.
| vh | The history table | |
| kbc | a KB core | |
| tve | an input vithist element | |
| comp_rc | a compressed rc. If it is the actual rc, it won't work. FIXME: WHAT DOES THIS MEAN?!!?!? |
| void vithist_entry_display | ( | vithist_entry_t * | ve, | |
| dict_t * | dict | |||
| ) |
Display the vithist_entry structure.
| ve | In: An entry of vithist | |
| dict | In: If specified, the word string of lm IDs would also be translated |
Invoked at the end of each frame
| vh | In/Out: Vithist module to be updated | |
| frm | In: Frame in which being invoked | |
| fp | In: If not NULL, dump vithist entries this frame to the file (for debugging) | |
| kbc | In: Used only for dumping to fp, for debugging |
| void vithist_free | ( | vithist_t * | vh | ) |
Free a Viterbi history data structure
| vh | In: a Viterbi history data structure |
One-time intialization: Allocate and return an initially empty vithist module
| kbc | Core search data structure | |
| wbeam | Word exit beam width | |
| bghist | If only bigram history is used | |
| report | Whether to report the progress |
Invoked at the end of each block of a live decode. Returns viterbi histories of partial decodes
| vh | In: a Viterbi history data structure | |
| kbc | In: a KBcore |
| void vithist_prune | ( | vithist_t * | vh, | |
| dict_t * | dict, | |||
| int32 | frm, | |||
| int32 | maxwpf, | |||
| int32 | maxhist, | |||
| int32 | beam | |||
| ) |
Mark up to maxwpf best words, and variants within beam of best frame score as valid, and the remaining as invalid.
| vh | In: a Viterbi history data structure | |
| dict | In: Dictionary, for distinguishing filler words | |
| frm | In: Frame in which being invoked | |
| maxwpf | In: Max unique words per frame to be kept valid | |
| maxhist | In: Max histories to maintain per frame | |
| beam | In: Entry score must be >= frame bestscore+beam |
| void vithist_report | ( | vithist_t * | vh | ) |
Report a Viterbi history architecture
| vh | In: a Viterbi history data structure |
| void vithist_rescore | ( | vithist_t * | vh, | |
| kbcore_t * | kbc, | |||
| s3wid_t | wid, | |||
| int32 | ef, | |||
| int32 | score, | |||
| int32 | pred, | |||
| int32 | type, | |||
| int32 | rc | |||
| ) |
Like vithist_enter, but LM-rescore this word exit wrt all histories that ended at the same time as the given, tentative pred. Create a new vithist entry for each predecessor (but, of course, only the best for each distinct LM state will be retained; see above).
ARCHAN: Precisely speaking, it is a full trigram rescoring.
| vh | In: a Viterbi history data structure | |
| kbc | In: a kb core. | |
| wid | In: a word ID | |
| ef | In: End frame for this word instance | |
| score | In: Does not include LM score for this entry | |
| pred | In: Tentative predecessor | |
| type | In: Type of lexical tree | |
| rc | In: The compressed rc. So if you use the actual rc, it doesn't work. |
Invoked at the beginning of each utterance; vithist initialized with a root <s> entry.
| vh | In: a Viterbi history data structure | |
| kbc | In: a KBcore |
Invoked at the end of each utterance; append a final </s> entry that results in the best path score (i.e., LM including LM transition to </s>). Return the ID of the appended entry if successful, -ve if error (empty utterance).
| vh | In: a Viterbi history data structure | |
| kbc | In: a KBcore |
| void vithist_utt_reset | ( | vithist_t * | vh | ) |
| vh | In: a Viterbi history data structure |
1.6.1