confidence.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /* ====================================================================
3  * Copyright (c) 1995-2004 Carnegie Mellon University. All rights
4  * reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * This work was supported in part by funding from the Defense Advanced
19  * Research Projects Agency and the National Science Foundation of the
20  * United States of America, and the CMU Sphinx Speech Consortium.
21  *
22  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
23  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
26  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * ====================================================================
35  *
36  */
37 /* confidence.h: Calculate confidence scores from word lattices using
38  * posterior word probabilities and backoff.
39  *
40  * Copyright (c) 2004 Carnegie Mellon University.
41  *
42  * Author: Rong Zhang <rongz@cs.cmu.edu>
43  *
44  * Arthur Chan has significantly changed these routines when incorporating to Sphinx 3.x
45  *
46  * $Log$
47  * Revision 1.1 2006/04/05 20:27:30 dhdfu
48  * A Great Reorganzation of header files and executables
49  *
50  * Revision 1.2 2006/02/21 18:31:09 arthchan2003
51  * Merge confidence.c confidence.h and Makefile.am into the trunk.
52  *
53  * Revision 1.1.2.1 2006/01/16 18:38:25 arthchan2003
54  * Adding Rong's confidence routine. Compare to Rong's routine, this routine used Sphinx3's njmerical routines and make the chances of backward-forward scores inconsistency to be lower.
55  *
56  */
57 
58 #ifndef __CONFIDENCE_H__
59 #define __CONFIDENCE_H__
60 
61 
62 #include <stdio.h>
63 
64 #include <logmath.h>
65 #include "dict.h"
66 #include "lm.h"
67 #include "fillpen.h"
68 #include "s3types.h"
69 #include "search.h"
70 
71 #define CONFIDENCE_MAX_INT 2147483640
72 #define CONFIDENCE_MIN_INT -2147483640
73 #define CONFIDENCE_FAILURE 0
74 #define CONFIDENCE_SUCCESS 1
75 #define MAGIC_CONFIDENCE_CONSTANT 39.5
76 #define MIN_LOG -690810000
77 
78 
79 #ifdef __cplusplus
80 extern "C" {
81 #endif
82 #if 0
83 /* Fool Emacs. */
84 }
85 #endif
86 
92 typedef struct ca_dagnode_type {
93  char word[64];
94  int wid;
95  int seqid;
96  int sf;
97  int fef;
98  int lef;
99  int reachable;
100  int visited;
101  int fanin;
102  int fanout;
103  int hscore;
104  int pscore;
105  int lscore;
106  int cscore;
110 } ca_dagnode;
111 
112 typedef struct ca_daglink_type {
115  int ascore;
119 } ca_daglink;
120 
121 typedef struct ca_dag_type {
126  int nfrm;
127  int nnode;
128  int nedge;
129  logmath_t *logmath;
130 } ca_dag;
131 
132 
138 int32 confidence_word_posterior(char* dagfile,
140  char* uttid,
141  lm_t *lm,
142  dict_t *dict,
143  fillpen_t *fpen
144  );
145 
146 
147 #if 0 /* Not public */
148 
151 int ca_dag_load_lattice(char *filename,
152  ca_dag *word_lattice,
153  lm_t *lm,
154  dict_t *dict,
156  );
157 
161 int alpha_beta(ca_dag *word_lattice,
162  lm_t* lm,
163  dict_t* dict
164  );
165 
166 /*
167  Given a seg_hyp_line, i.e. one hypothesis with time
168  information. Compute the posterior word probability score using the
169  lattice.
170 */
171 int pwp(seg_hyp_line_t *seg_hyp_line,
172  ca_dag *word_lattice
173  );
174 
178 int ca_dag_free_lattice(ca_dag *word_lattice);
179 
180 #endif
181 
187  lm_t* lm,
188  dict_t* dict
189  );
190 
193 
194 #ifdef __cplusplus
195 }
196 #endif
197 
198 
199 #endif /* __CONFIDENCE_H__ */
200 
struct ca_daglink_type * predlist
Definition: confidence.h:108
int nnode
Definition: confidence.h:127
int hscore
Definition: confidence.h:103
int wid
Definition: confidence.h:94
int nfrm
Definition: confidence.h:126
Filler penalties, penalties for words that do not show up in the main LM.
The temporary header file for sphinx 3 functions.
struct ca_daglink_type * succlist
Definition: confidence.h:107
logmath_t * logmath
Definition: confidence.h:129
Operations on dictionary.
int fanin
Definition: confidence.h:101
int lef
Definition: confidence.h:98
struct ca_daglink_type ca_daglink
struct ca_dagnode_type ca_dagnode
char word[64]
Definition: confidence.h:93
int fef
Definition: confidence.h:97
a strurcture that stores one line of hypothesis. Mainly used in confidence.c
int pscore
Definition: confidence.h:104
int sf
Definition: confidence.h:96
int reachable
Definition: confidence.h:99
Definition: search.h:224
ca_daglink entry
Definition: confidence.h:124
int seqid
Definition: confidence.h:95
Size definition of semantically units. Common for both s3 and s3.X decoder.
struct ca_dag_type ca_dag
ca_dagnode ** seqidtonode
Definition: confidence.h:123
#define S3DECODER_EXPORT
Definition: sphinx3_export.h:15
Definition: fillpen.h:97
a structure for a dictionary.
Definition: dict.h:146
Definition: confidence.h:121
int fanout
Definition: confidence.h:102
int32 fillpen(fillpen_t *f, s3wid_t w)
ca_daglink exit
Definition: confidence.h:125
S3DECODER_EXPORT int32 confidence_word_posterior(char *dagfile, seg_hyp_line_t *seg_hyp_line, char *uttid, lm_t *lm, dict_t *dict, fillpen_t *fpen)
ca_dagnode * nodelist
Definition: confidence.h:122
The language model. All unigrams are read into memory on initialization. Bigrams and trigrams read in...
int cscore
Definition: confidence.h:106
S3DECODER_EXPORT int compute_combined_lmtype(seg_hyp_line_t *seg_hyp_line)
int lscore
Definition: confidence.h:105
S3DECODER_EXPORT int compute_lmtype(seg_hyp_line_t *seg_hyp_line, lm_t *lm, dict_t *dict)
Language model.
int nedge
Definition: confidence.h:128
Definition: confidence.h:92
int visited
Definition: confidence.h:100
struct ca_dagnode_type * alloc_next
Definition: confidence.h:109