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