Classes | Macros | Typedefs | Functions
vithist.h File Reference

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
 

Macros

#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 /* (1 << 14) */
 
#define VITHIST_MAXBLKS   256
 
#define VITHIST_ID2BLK(i)   ((i) >> 14)
 
#define VITHIST_ID2BLKOFFSET(i)   ((i) & 0x00003fff) /* 14 LSB */
 
#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_tvithist_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_tvithist_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_tlatticehist_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_tlattice_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_tlatticehist_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)
 

Detailed Description

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.

Macro Definition Documentation

◆ LAT_ALLOC_INCR

#define LAT_ALLOC_INCR   32768

◆ LATID2SF

#define LATID2SF (   hist,
 
)
Value:
(IS_S3LATID(hist->lattice[l].history) ? \
hist->lattice[hist->lattice[l].history].frm + 1 : 0)
#define IS_S3LATID(l)
Definition: s3types.h:169

◆ latticehist_lat_alloc

#define latticehist_lat_alloc (   hist)    ((hist)->lat_alloc)

◆ latticehist_n_cand

#define latticehist_n_cand (   hist)    ((hist)->n_cand)

◆ latticehist_n_lat_entry

#define latticehist_n_lat_entry (   hist)    ((hist)->n_lat_entry)

◆ vithist_bestscore

#define vithist_bestscore (   vh)    ((vh)->bestscore)

Return the best score of the Viterbi history

◆ vithist_bestvh

#define vithist_bestvh (   vh)    ((vh)->bestvh)

Return the best viterbi history entry ID of the Viterbi history

◆ VITHIST_BLKSIZE

#define VITHIST_BLKSIZE   16384 /* (1 << 14) */

◆ vithist_entry_ascr

#define vithist_entry_ascr (   ve)    ((ve)->ascr)

Return the acoustic score of an entry

◆ vithist_entry_ef

#define vithist_entry_ef (   ve)    ((ve)->ef)

Return the ending frame of an entry

◆ vithist_entry_lscr

#define vithist_entry_lscr (   ve)    ((ve)->lscr)

Return the language score of an entry

◆ vithist_entry_pred

#define vithist_entry_pred (   ve)    ((ve)->path.pred)

◆ vithist_entry_score

#define vithist_entry_score (   ve)    ((ve)->path.score)

Return the total score of an entry

◆ vithist_entry_sf

#define vithist_entry_sf (   ve)    ((ve)->sf)

Return the starting frame of an entry

◆ vithist_entry_valid

#define vithist_entry_valid (   ve)    ((ve)->valid)

◆ vithist_entry_wid

#define vithist_entry_wid (   ve)    ((ve)->wid)

Return the word ID of an entry

◆ vithist_first_entry

#define vithist_first_entry (   vh,
 
)    ((vh)->frame_start[f])

Return the first entry for the frame f

◆ VITHIST_ID2BLK

#define VITHIST_ID2BLK (   i)    ((i) >> 14)

◆ VITHIST_ID2BLKOFFSET

#define VITHIST_ID2BLKOFFSET (   i)    ((i) & 0x00003fff) /* 14 LSB */

◆ vithist_id2entry

#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.

◆ vithist_last_entry

#define vithist_last_entry (   vh,
 
)    ((vh)->frame_start[f+1] - 1)

Return the last entry for the frame f

◆ vithist_lms2vh_root

#define vithist_lms2vh_root (   vh,
 
)    ((vh)->lms2vh_root[w])

Return lms2vh

◆ vithist_lwidlist

#define vithist_lwidlist (   vh)    ((vh)->lwidlist)

Return the language word ID list

◆ VITHIST_MAXBLKS

#define VITHIST_MAXBLKS   256

◆ vithist_n_entry

#define vithist_n_entry (   vh)    ((vh)->n_entry)

Return the number of entry in the Viterbi history

Typedef Documentation

◆ backpointer_t

typedef struct backpointer_s backpointer_t

◆ lattice_t

typedef struct lattice_s lattice_t

◆ vh_lmstate_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.)

Function Documentation

◆ lat_final_entry()

s3latid_t lat_final_entry ( latticehist_t lathist,
dict_t dict,
int32  curfrm,
char *  uttid 
)

Get the final entry of the lattice

Parameters
lathistA table of lattice entries
curfrmThe dictioanry The current frame
uttidUtterance ID

◆ lat_pscr_rc()

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.

Parameters
lathistA table of lattice entries
llattice ID
w_rcThe right context word
ctContext table
dictThe dictionary

◆ lat_pscr_rc_history()

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.

Parameters
lathistA table of lattice entries
llattice ID
w_rcThe right context word
ctContext table
dictThe dictionary

◆ lat_seg_ascr_lscr()

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.

Parameters
lathistA table of lattice entries
llattice ID
w_rcThe right context word
ascrOut: Acoustic score
lscrOut: language score
lmLM
dictDictionary
fillpenContext table filler penalty

◆ lat_seg_lscr()

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 
)

◆ lattice_backtrace()

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.

Parameters
lathistA table of lattice entries
lThe lattice ID
w_rcThe word on the right
hypOutput: final hypothesis
lmLM
dictDictionary
ctContext table
fillpenfiller penalty struct

◆ lattice_entry()

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

Parameters
lathistA table of lattice entries
wWord ID to enter.
fcurrent frame number
scoreThe score to enter, usually it is the score of the final state of hmm
historyThe last lattice entry to enter, usually the entry of the final state of hmm is used.
rcRight context of the HMM
ctA context table
dictA dictionary

◆ latticehist_dag_build()

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.

◆ latticehist_dag_write()

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

Parameters
lathistA table off lattice entries

◆ latticehist_dump()

void latticehist_dump ( latticehist_t lathist,
FILE *  fp,
dict_t dict,
ctxt_table_t ct,
int32  dumpRC 
)

Dump the lattice history table

Parameters
lathistA table of lattice entries
fpFile pointer where one would want to dump the lattice
dictThe dictionary
ctContext table
dumpRCWhether we whould dump all the scores and histories for right context

◆ latticehist_free()

void latticehist_free ( latticehist_t lat)

Free lattice history table

Parameters
latThe latticie history table

◆ latticehist_init()

latticehist_t* latticehist_init ( int32  init_alloc_size,
int32  num_frames 
)

Initialization of lattice history table

Parameters
init_alloc_sizeInitial allocation size
num_framesNumber of frames in represented in the lattice

◆ latticehist_reset()

void latticehist_reset ( latticehist_t lat)
Parameters
latThe lattice history table

◆ two_word_history()

void two_word_history ( latticehist_t lathist,
s3latid_t  l,
s3wid_t w0,
s3wid_t w1,
dict_t dict 
)

◆ vh_lmstate_display()

void vh_lmstate_display ( vh_lmstate_t vhl,
dict_t dict 
)

Display the lmstate of an entry.

Parameters
vhlIn: An lmstate data structure
dictIn: If specified, the word string of lm IDs would also be translated

◆ vithist_backtrace()

glist_t vithist_backtrace ( vithist_t vh,
int32  id,
dict_t dict 
)

Viterbi backtrace. Return value: List of hyp_t pointer entries for the individual word segments. Caller responsible for freeing the list.

Parameters
vhIn: a Viterbi history data structure
idID from which to begin backtrace
dicta dictionary for look up the ci phone of a word

◆ vithist_dag_build()

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.

◆ vithist_dag_write()

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)

◆ vithist_dump()

void vithist_dump ( vithist_t vh,
int32  frm,
kbcore_t kbc,
FILE *  fp 
)

Dump the Viterbi history data to the given file (for debugging/diagnostics).

Parameters
vhIn: a Viterbi history data structure
frmIn: If >= 0, print only entries made in this frame, otherwise print all entries
kbcIn: a KBcore
fpOut: File to be written

◆ vithist_enter()

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.

Parameters
vhThe history table
kbca KB core
tvean input vithist element
comp_rca compressed rc. If it is the actual rc, it won't work. FIXME: WHAT DOES THIS MEAN?!!?!?

◆ vithist_entry_display()

void vithist_entry_display ( vithist_entry_t ve,
dict_t dict 
)

Display the vithist_entry structure.

Parameters
veIn: An entry of vithist
dictIn: If specified, the word string of lm IDs would also be translated

◆ vithist_frame_windup()

void vithist_frame_windup ( vithist_t vh,
int32  frm,
FILE *  fp,
kbcore_t kbc 
)

Invoked at the end of each frame

Parameters
vhIn/Out: Vithist module to be updated
frmIn: Frame in which being invoked
fpIn: If not NULL, dump vithist entries this frame to the file (for debugging)
kbcIn: Used only for dumping to fp, for debugging

◆ vithist_free()

void vithist_free ( vithist_t vh)

Free a Viterbi history data structure

Parameters
vhIn: a Viterbi history data structure

◆ vithist_init()

vithist_t* vithist_init ( kbcore_t kbc,
int32  wbeam,
int32  bghist,
int32  report 
)

One-time intialization: Allocate and return an initially empty vithist module

Returns
An initialized vithist_t
Parameters
kbcCore search data structure
wbeamWord exit beam width
bghistIf only bigram history is used
reportWhether to report the progress

◆ vithist_partialutt_end()

int32 vithist_partialutt_end ( vithist_t vh,
kbcore_t kbc 
)

Invoked at the end of each block of a live decode. Returns viterbi histories of partial decodes

Parameters
vhIn: a Viterbi history data structure
kbcIn: a KBcore

◆ vithist_prune()

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.

Parameters
vhIn: a Viterbi history data structure
dictIn: Dictionary, for distinguishing filler words
frmIn: Frame in which being invoked
maxwpfIn: Max unique words per frame to be kept valid
maxhistIn: Max histories to maintain per frame
beamIn: Entry score must be >= frame bestscore+beam

◆ vithist_report()

void vithist_report ( vithist_t vh)

Report a Viterbi history architecture

Parameters
vhIn: a Viterbi history data structure

◆ vithist_rescore()

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.

Parameters
vhIn: a Viterbi history data structure
kbcIn: a kb core.
widIn: a word ID
efIn: End frame for this word instance
scoreIn: Does not include LM score for this entry
predIn: Tentative predecessor
typeIn: Type of lexical tree
rcIn: The compressed rc. So if you use the actual rc, it doesn't work.

◆ vithist_utt_begin()

int32 vithist_utt_begin ( vithist_t vh,
kbcore_t kbc 
)

Invoked at the beginning of each utterance; vithist initialized with a root <s> entry.

Returns
Vithist ID of the root <s> entry.
Parameters
vhIn: a Viterbi history data structure
kbcIn: a KBcore

◆ vithist_utt_end()

int32 vithist_utt_end ( vithist_t vh,
kbcore_t kbc 
)

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).

Parameters
vhIn: a Viterbi history data structure
kbcIn: a KBcore

◆ vithist_utt_reset()

void vithist_utt_reset ( vithist_t vh)
Parameters
vhIn: a Viterbi history data structure