Revision: 6942
http://svn.sourceforge.net/cmusphinx/?rev=6942&view=rev
Author: dhdfu
Date: 2007-07-21 06:13:01 -0700 (Sat, 21 Jul 2007)
Log Message:
-----------
Make a lot more stuff go through the abstract search interface. I
don't like this interface much but it's a step in the right direction,
and we can fix it sooner now.
This will let us do some more useful things with DAGs although that
code isn't implemented yet.
There is still a bug where you have to dump the lattice in flat_fwd
search before doing bestpath search, because the latter relies on
having the seqid field filled in.
Modified Paths:
--------------
trunk/sphinx3/include/srch.h
trunk/sphinx3/include/srch_flat_fwd.h
trunk/sphinx3/include/srch_fsg.h
trunk/sphinx3/include/srch_time_switch_tree.h
trunk/sphinx3/src/libs3decoder/libsearch/Makefile.am
trunk/sphinx3/src/libs3decoder/libsearch/dag.c
trunk/sphinx3/src/libs3decoder/libsearch/srch.c
trunk/sphinx3/src/libs3decoder/libsearch/srch_allphone.c
trunk/sphinx3/src/libs3decoder/libsearch/srch_flat_fwd.c
trunk/sphinx3/src/libs3decoder/libsearch/srch_fsg.c
trunk/sphinx3/src/libs3decoder/libsearch/srch_output.c
trunk/sphinx3/src/libs3decoder/libsearch/srch_time_switch_tree.c
trunk/sphinx3/src/libs3decoder/libsearch/srch_word_switch_tree.c
trunk/sphinx3/src/libs3decoder/libsearch/vithist.c
Modified: trunk/sphinx3/include/srch.h
===================================================================
--- trunk/sphinx3/include/srch.h 2007-07-21 11:50:47 UTC (rev 6941)
+++ trunk/sphinx3/include/srch.h 2007-07-21 13:13:01 UTC (rev 6942)
@@ -680,7 +680,7 @@
Interface for sphinx3 dag dumping function
*/
int (*dag_dump) (void * srch_struct,
- glist_t hyp
+ dag_t *dag
);
/** Empty "guard" element which does nothing. */
Modified: trunk/sphinx3/include/srch_flat_fwd.h
===================================================================
--- trunk/sphinx3/include/srch_flat_fwd.h 2007-07-21 11:50:47 UTC (rev 6941)
+++ trunk/sphinx3/include/srch_flat_fwd.h 2007-07-21 13:13:01 UTC (rev 6942)
@@ -203,45 +203,5 @@
kbcore_t* kbcore; /**< A pointer for convenience */
} srch_FLAT_FWD_graph_t ;
-int srch_FLAT_FWD_init(kb_t *kb, /**< The KB */
- void* srch_struct /**< The pointer to a search structure */
- );
-int srch_FLAT_FWD_uninit(void* srch_struct);
-int srch_FLAT_FWD_begin(void* srch_struct);
-int srch_FLAT_FWD_end(void* srch_struct);
-
-int srch_FLAT_FWD_set_lm(void* srch_struct, const char* lmname);
-int srch_FLAT_FWD_add_lm(void* srch, lm_t *lm, const char *lmname);
-int srch_FLAT_FWD_delete_lm(void* srch, const char *lmname);
-
-int srch_FLAT_FWD_srch_one_frame_lv2(void* srch_struct);
-
-int srch_FLAT_FWD_shift_one_cache_frame(void *srch,int32 win_efv);
-
-int srch_FLAT_FWD_frame_windup(void* srch_struct, int32 frmno);
-
-int srch_FLAT_FWD_select_active_gmm(void *srch_struct);
-
-
-glist_t srch_FLAT_FWD_gen_hyp(void* srch_struct /**< A void pointer to a search structure */
- );
-
-int srch_FLAT_FWD_dump_vithist(void* srch_struct /**< A void pointer to a search structure */
- );
-
-dag_t* srch_FLAT_FWD_gen_dag(void * srch_struct, /**< A void pointer to a search structure */
- glist_t hyp
- );
-
-glist_t srch_FLAT_FWD_bestpath_impl(void * srch_struct, /**< A void pointer to a search structure */
- dag_t *dag
- );
-
-
-int32 srch_FLAT_FWD_dag_dump(void *srch_struct,
- glist_t hyp
- );
-
-
#endif /* SRCH_FLT_FWD*/
Modified: trunk/sphinx3/include/srch_fsg.h
===================================================================
--- trunk/sphinx3/include/srch_fsg.h 2007-07-21 11:50:47 UTC (rev 6941)
+++ trunk/sphinx3/include/srch_fsg.h 2007-07-21 13:13:01 UTC (rev 6942)
@@ -76,28 +76,3 @@
#include "cmd_ln.h"
extern struct srch_funcs_s srch_FSG_funcs;
-
-int srch_FSG_init(kb_t *kb, /**< The KB */
- void* srch_struct /**< The pointer to a search structure */
- );
-
-word_fsg_t* srch_FSG_read_fsgfile(void* srch_struct,const char* fsgname);
-
-int srch_FSG_uninit(void* srch_struct);
-int srch_FSG_begin(void* srch_struct);
-int srch_FSG_end(void* srch_struct);
-
-glist_t srch_FSG_gen_hyp(void* srch_struct);
-int srch_FSG_dump_vithist(void* srch_struct);
-
-int srch_FSG_set_lm(void* srch_struct, const char* lmname);
-int srch_FSG_add_lm(void* srch, lm_t *lm, const char *lmname);
-int srch_FSG_delete_lm(void* srch, const char *lmname);
-
-int srch_FSG_srch_one_frame_lv2(void* srch_struct);
-
-int srch_FSG_shift_one_cache_frame(void *srch_struct,int32 win_efv);
-int srch_FSG_select_active_gmm(void *srch_struct);
-
-int srch_FSG_windup(void* srch_struct, int32 frmno);
-
Modified: trunk/sphinx3/include/srch_time_switch_tree.h
===================================================================
--- trunk/sphinx3/include/srch_time_switch_tree.h 2007-07-21 11:50:47 UTC (rev 6941)
+++ trunk/sphinx3/include/srch_time_switch_tree.h 2007-07-21 13:13:01 UTC (rev 6942)
@@ -185,114 +185,6 @@
extern struct srch_funcs_s srch_TST_funcs;
-/** Initializing search-specific data structure for time-switching
- tree search Currently, that is to say to initialize lexical
- tree(s) (both words and fillers) and histprune (it is necessary
- because histprune rely on the number of states of the data
- structure.
-*/
-
-int srch_TST_init(kb_t *kb, /**< The KB. */
- void* srch_struct /** The pointer to a search structure. */
- );
-
-/** Uninitialize search-specific data structure for time-switching
- tree search Currently, that is to say un-initialize lexical tree
- and histprune. Notice that lmset is assumed to be deallocate at kb
- which is the global copy boards of data structure.
-*/
-int srch_TST_uninit(void *srch /**< A void pointer to a search structure */
- );
-
-
-/** Do the preparation for beginning a search for time-switching tree search.
- There are several things would happen in this function
-
- 1, statistics of an utterance will be clear, (i.e stat_clear_utt
- is called)
-
- 2, all the bins for histogram pruning will be zeroed
- (i.e. histprune_zero_histbin is called)
-
- 3, a new viterbi istory will be created. A silence (usually <s> or <sil>)
- will be inserted at the beginning of the history.
- (vithist_utt_begin )
-
- 4, Enter the current word tree with index 0 (curugtree[0])
- assuming left context is silence and enter filler tree with a
- BAD_S3CIPID
-
- 5, Swap the active list of the lexical tree.
-
- @return SRCH_SUCCESS if succeed.
- @see gmm_wrap, srch_TST_end
-*/
-
-int srch_TST_begin(void *srch /**< A void pointer to a search structure */
- );
-
-int srch_TST_end(void * srch /**< A void pointer to a search structure */
- );
-
-glist_t srch_TST_gen_hyp(void* srch_struct /**< A void pointer to a search structure */
- );
-
-int srch_TST_dump_vithist(void* srch_struct /**< A void pointer to a search structure */
- );
-
-dag_t* srch_TST_gen_dag(void * srch_struct, /**< A void pointer to a search structure */
- glist_t hyp
- );
-
-glist_t srch_TST_bestpath_impl(void * srch_struct, /**< A void pointer to a search structure */
- dag_t *dag
- );
-
-int32 srch_TST_dag_dump(void *srch_struct,
- glist_t hyp
- );
-
-/* An empty function, specified for possibly future use of overloading the default
- search abstraction mechanism.
-*/
-
-int srch_TST_decode(void *srch /**< A void pointer to a search structure */
- );
-
-int srch_TST_set_lm(void* srch, /**< A void pointer to a search structure */
- const char* lmname /**< lm name which need to be deleted */
- );
-
-int srch_TST_add_lm(void* srch, /**< A void pointer to a search structure */
- lm_t *lm, const char *lmname);
-
-int srch_TST_delete_lm(void* srch, /**< A void pointer to a search structure */
- const char *lmname /**< lm name which need to be deleted */
- );
-
-int srch_TST_gmm_compute_lv2(void *srch, /** A void pointer to a search structure */
- float32 *feat, int32 time);
-
-int srch_TST_hmm_compute_lv1(void *srch /** A void pointer to a search structure */
- );
-
-int srch_TST_hmm_compute_lv2(void *srch, /** A void pointer to a search structure */
- int32 frmno);
-
-int srch_TST_eval_beams_lv1 (void* srch /** A void pointer to a search structure */
- );
-int srch_TST_eval_beams_lv2 (void* srch);
-int srch_TST_propagate_graph_ph_lv1(void *srch_struct);
-int srch_TST_propagate_graph_wd_lv1(void *srch_struct);
-
-int srch_TST_propagate_graph_ph_lv2(void *srch_struct, int32 frmno);
-int srch_TST_propagate_graph_wd_lv2(void *srch_struct, int32 frmno);
-
-int srch_TST_compute_heuristic(void *srch, int32 win_efv);
-int srch_TST_frame_windup(void *srch_struct,int32 frmno);
-int srch_TST_shift_one_cache_frame(void *srch,int32 win_efv);
-int srch_TST_select_active_gmm(void *srch);
-
#endif
Modified: trunk/sphinx3/src/libs3decoder/libsearch/Makefile.am
===================================================================
--- trunk/sphinx3/src/libs3decoder/libsearch/Makefile.am 2007-07-21 11:50:47 UTC (rev 6941)
+++ trunk/sphinx3/src/libs3decoder/libsearch/Makefile.am 2007-07-21 13:13:01 UTC (rev 6942)
@@ -28,7 +28,6 @@
srch_fsg.c \
srch_output.c \
srch_time_switch_tree.c \
- srch_word_switch_tree.c \
vithist.c \
whmm.c \
word_fsg.c \
Modified: trunk/sphinx3/src/libs3decoder/libsearch/dag.c
===================================================================
--- trunk/sphinx3/src/libs3decoder/libsearch/dag.c 2007-07-21 11:50:47 UTC (rev 6941)
+++ trunk/sphinx3/src/libs3decoder/libsearch/dag.c 2007-07-21 13:13:01 UTC (rev 6942)
@@ -531,7 +531,7 @@
if (!l->bypass) {
/* Link did not bypass any filler node */
- h = (srch_hyp_t *) listelem_alloc(sizeof(srch_hyp_t));
+ h = (srch_hyp_t *) ckd_calloc(1, sizeof(srch_hyp_t));
h->id = l->node->wid;
h->word = dict_wordstr(dict, h->id);
h->sf = l->node->sf;
@@ -547,7 +547,7 @@
src = l->node; /* Note that l is a PREDECESSOR link */
for (; l; l = l->bypass) {
- h = (srch_hyp_t *) listelem_alloc(sizeof(srch_hyp_t));
+ h = (srch_hyp_t *) ckd_calloc(1, sizeof(srch_hyp_t));
h->id = src->wid;
h->word = dict_wordstr(dict, h->id);
h->sf = src->sf;
Modified: trunk/sphinx3/src/libs3decoder/libsearch/srch.c
===================================================================
--- trunk/sphinx3/src/libs3decoder/libsearch/srch.c 2007-07-21 11:50:47 UTC (rev 6941)
+++ trunk/sphinx3/src/libs3decoder/libsearch/srch.c 2007-07-21 13:13:01 UTC (rev 6942)
@@ -220,15 +220,6 @@
#define COMPUTE_HEURISTIC 1
#define SHOW_SENONE_SCORE_FOR_FRAME 0
-static void write_bestsenscore(srch_t * s);
-
-static void display_dump_hypothesis(srch_t * s,
- glist_t hyp,
- char *hyptag,
- char *hypsegtag,
- char *shortformCap,
- char *shortformSmall);
-
int32
srch_mode_str_to_index(const char *mode_str)
{
@@ -423,34 +414,23 @@
/* A switch here to decide all function pointers */
if (op_mode == OPERATION_ALIGN) {
E_FATAL("Alignment mode is not supported yet");
-
}
else if (op_mode == OPERATION_ALLPHONE) {
s->funcs = &srch_allphone_funcs;
}
else if (op_mode == OPERATION_GRAPH) {
- E_WARN
- ("In Sphinx 3.6.0 official release, Graph search is still recommended for internal use only. ");
-
s->funcs = &srch_FSG_funcs;
}
else if (op_mode == OPERATION_FLATFWD) {
s->funcs = &srch_FLAT_FWD_funcs;
}
else if (op_mode == OPERATION_TST_DECODE) {
- if (!cmd_ln_int32("-composite")) {
- E_ERROR
- ("Full triphone expansion is not supported at this point.\n");
- return NULL;
- }
+ if (!cmd_ln_int32("-composite"))
+ E_FATAL("Full triphone expansion is not supported at this point.\n");
s->funcs = &srch_TST_funcs;
}
else if (op_mode == OPERATION_WST_DECODE) {
- E_INFO
- ("You have used a function which is still under development\n");
- E_FATAL
- ("Word Conditioned Tree Search is still under development. It is now fended off from the users.");
- s->funcs = &srch_WST_funcs;
+ E_FATAL("Word Conditioned Tree Search is currently unmaintained.");
}
else if (op_mode == OPERATION_DEBUG) {
s->funcs = &srch_debug_funcs;
@@ -558,43 +538,140 @@
return SRCH_SUCCESS;
}
- /* Several things we want to take care in srch_utt_end
- 1, (Optionally) Generate the history table.
- 2, (Optionally) Generate the best senone score.
- 3, Generate hypothesis.
- 4, Display the hypothesis.
- 5, (Optionally) If enerate the DAG.
- 6, (Optionally) Do best path search <- Given 5 is done
- 7, (Optionally) Confidence estimation based on Lattice <- Given 5 is done.
- Result could come from either 1 or 6.
- 8, Then, finally of course you want to clean up.
- The following essentially follows the above procedure.
+int32
+srch_utt_end(srch_t * s)
+{
+ int32 rv;
+ glist_t hyp;
+ gnode_t *gn;
+ dag_t *dag = NULL;
- The first 1-7 will be mainly taken by function pointers supplied
- by different modes.
+ if (s->funcs->utt_end == NULL) {
+ E_ERROR
+ ("s->funcs->utt_end is NULL. Please make sure it is set.\n");
+ return SRCH_FAILURE;
+ }
- The first 8 will be taken care by s->funcs->utt_end. That is very
- different from the past because s->funcs->utt_end takes of
- everything.
- */
+ if ((rv = s->funcs->utt_end(s)) != SRCH_SUCCESS) {
+ E_ERROR("s->funcs->utt_end failed\n");
+ return rv;
+ }
-int32
-srch_utt_end(srch_t * srch)
-{
+ if (s->funcs->dump_vithist && cmd_ln_str("-bptbldir")) {
+ if ((rv = s->funcs->dump_vithist(s)) != SRCH_SUCCESS) {
+ E_ERROR("s->funcs->dump_vithist failed\n");
+ return rv;
+ }
+ }
- glist_t hyp, bphyp;
- dag_t *dag;
+ /* Get the final 1-best hypothesis */
+ if (s->funcs->gen_hyp == NULL) {
+ /* Or don't... some modes don't implement this yet. */
+ E_WARN("srch->funcs->gen_hyp is NULL. Please make sure it is set.\n");
+ return SRCH_SUCCESS;
+ }
+ if ((hyp = s->funcs->gen_hyp(s)) == NULL) {
+ E_ERROR("s->funcs->gen_hyp failed\n");
+ return SRCH_FAILURE;
+ }
- hyp = bphyp = NULL;
- dag = NULL;
+ /* Generate a DAG if needed */
+ if (s->funcs->gen_dag &&
+ (cmd_ln_str("-outlatdir")
+ || cmd_ln_boolean("-bestpath"))) {
+ if ((dag = s->funcs->gen_dag(s, hyp)) == NULL) {
+ E_ERROR("Failed to generate DAG.\n");
+ }
+ }
- if (srch->funcs->utt_end == NULL) {
- E_ERROR
- ("srch->funcs->utt_end is NULL. Please make sure it is set.\n");
- return SRCH_FAILURE;
+ /* Write backtrace info */
+ if (cmd_ln_boolean("-backtrace")) {
+ fprintf(stderr, "\nBacktrace(%s)\n", s->uttid);
+ match_detailed(stderr, hyp, s->uttid, "FV", "fv", s->ascale,
+ kbcore_dict(s->kbc));
}
- return srch->funcs->utt_end(srch);
+ /* Write hypothesis strings */
+ if (!(dag && cmd_ln_boolean("-bestpath"))) {
+ if (s->matchfp)
+ match_write(s->matchfp, hyp, s->uttid, kbcore_dict(s->kbc), NULL);
+ if (s->matchsegfp)
+ matchseg_write(s->matchsegfp, hyp, s->uttid, NULL,
+ cmd_ln_int32("-hypsegfmt"), kbcore_lm(s->kbc),
+ kbcore_dict(s->kbc), s->stat->nfr, s->ascale,
+ cmd_ln_int32("-hypsegscore_unscale"));
+ }
+ match_write(stderr, hyp, s->uttid, kbcore_dict(s->kbc), "\nFWDVIT: ");
+ matchseg_write(stderr, hyp, s->uttid, "FWDXCT: ",
+ cmd_ln_int32("-hypsegfmt"), kbcore_lm(s->kbc),
+ kbcore_dict(s->kbc), s->stat->nfr, s->ascale,
+ cmd_ln_int32("-hypsegscore_unscale"));
+ fprintf(stderr, "\n");
+
+ /* Write best senone scores */
+ if (cmd_ln_str("-bestsenscrdir")) {
+ int32 ispipe;
+ char str[2048];
+ FILE *bsfp;
+ sprintf(str, "%s/%s.bsenscr",
+ cmd_ln_str("-bestsenscrdir"), s->uttid);
+ E_INFO("Dumping the Best senone scores.\n");
+ if ((bsfp = fopen_comp(str, "w", &ispipe)) == NULL)
+ E_ERROR("fopen_comp (%s,w) failed\n", str);
+ else {
+ write_bstsenscr(bsfp, s->stat->nfr, s->ascale);
+ fclose_comp(bsfp, ispipe);
+ }
+ }
+
+ /* Write lattices */
+ if (dag && cmd_ln_str("-outlatdir")) {
+ if ((s->funcs->dag_dump(s, dag)) != SRCH_SUCCESS) {
+ E_ERROR("Failed to write DAG file.\n");
+ }
+ }
+
+ /* Do second stage search */
+ if (dag && cmd_ln_boolean("-bestpath")) {
+ glist_t rhyp;
+
+ if ((rhyp = s->funcs->bestpath_impl(s, dag)) == NULL) {
+ E_ERROR("Bestpath search failed.\n");
+ }
+ else {
+ if (cmd_ln_int32("-backtrace"))
+ match_detailed(stdout, rhyp, s->uttid, "BP",
+ "bp", s->ascale,
+ kbcore_dict(s->kbc));
+ if (s->matchfp)
+ match_write(s->matchfp, rhyp, s->uttid, kbcore_dict(s->kbc), NULL);
+ if (s->matchsegfp)
+ matchseg_write(s->matchsegfp, rhyp, s->uttid, NULL,
+ cmd_ln_int32("-hypsegfmt"), kbcore_lm(s->kbc),
+ kbcore_dict(s->kbc), s->stat->nfr, s->ascale,
+ cmd_ln_int32("-hypsegscore_unscale"));
+ match_write(stderr, rhyp, s->uttid,
+ kbcore_dict(s->kbc), "BSTPTH: ");
+ matchseg_write(stderr, rhyp, s->uttid, "BSTXCT: ",
+ cmd_ln_int32("-hypsegfmt"),
+ kbcore_lm(s->kbc), kbcore_dict(s->kbc),
+ s->stat->nfr, s->ascale,
+ cmd_ln_int32("-hypsegscore_unscale"));
+ for (gn = rhyp; gn; gn = gnode_next(gn)) {
+ ckd_free(gnode_ptr(gn));
+ }
+ glist_free(rhyp);
+ }
+ }
+
+ if (dag)
+ dag_destroy(dag);
+ for (gn = hyp; gn; gn = gnode_next(gn)) {
+ ckd_free(gnode_ptr(gn));
+ }
+ glist_free(hyp);
+
+ return SRCH_SUCCESS;
}
int32
@@ -826,7 +903,7 @@
{
if (srch->funcs->gen_hyp == NULL) {
E_ERROR
- ("srch->funcs->get_hyp is NULL. Please make sure it is set.\n");
+ ("srch->funcs->gen_hyp is NULL. Please make sure it is set.\n");
return NULL;
}
return srch->funcs->gen_hyp(srch);
@@ -873,275 +950,7 @@
return SRCH_SUCCESS;
}
-
-#if 0 /** fend off*/
-/** using file name of the model definition and directory name to initialize */
-int32
-srch_set_am(srch_t * srch)
-{
- if (srch->funcs->set_am == NULL) {
- E_INFO("srch->funcs->set_am is NULL. Please make sure it is set.\n");
- return SRCH_FAILURE;
- }
-
- return SRCH_SUCCESS;
-}
-
-/** using file name of the regression class mapping or a directory name to initialize */
-int32
-srch_set_mllr(srch_t * srch)
-{
- if (srch->funcs->set_mllr == NULL) {
- E_INFO
- ("srch->funcs->set_mllr is NULL. Please make sure it is set.\n");
- return SRCH_FAILURE;
- }
-
- return SRCH_SUCCESS;
-}
-
-/** using file name of interpolation file to initialize it */
-int32
-srch_set_lamdafn(srch_t * srch)
-{
- if (srch->funcs->set_lamdafn == NULL) {
- E_INFO
- ("srch->funcs->set_lamdafn is NULL. Please make sure it is set.\n");
- return SRCH_FAILURE;
- }
-
- return SRCH_SUCCESS;
-}
-#endif
-
-#if 1 /* Currently only used by tree searches */
void
-reg_result_dump(srch_t * s, int32 id)
-{
- FILE *fp, *latfp, *bptfp;
- glist_t hyp;
- glist_t ghyp, rhyp;
- stat_t *st;
- gnode_t *gn;
- srch_hyp_t *bph, *tmph;
- int32 bp;
- float32 *f32arg;
- float64 lwf;
- dag_t *dag;
- int32 nfrm;
- dict_t *dict;
-
- st = s->stat;
- fp = stderr;
- dag = NULL;
-
- dict = s->kbc->dict;
-
- hyp = ghyp = rhyp = NULL;
-
- if (cmd_ln_str("-bptbldir")) {
- char file[8192];
- sprintf(file, "%s/%s.bpt", cmd_ln_str("-bptbldir"), s->uttid);
- if ((bptfp = fopen(file, "w")) == NULL) {
- E_ERROR("fopen(%s,w) failed; using stdout\n", file);
- bptfp = stdout;
- }
-
- if (s->vithist)
- vithist_dump(s->vithist, -1, s->kbc, bptfp);
-
- if (bptfp != stdout)
- fclose(bptfp);
- }
-
- if (s->vithist) {
- assert(id >= 0);
- hyp = vithist_backtrace(s->vithist, id, dict);
- }
-
-
- /* Detailed backtrace */
- if (cmd_ln_int32("-backtrace")) {
- fprintf(fp, "\nBacktrace(%s)\n", s->uttid);
- match_detailed(fp, hyp, s->uttid, "FV", "fv", s->ascale,
- kbcore_dict(s->kbc));
- }
-
- /* Match */
- if (s->matchfp)
- match_write(s->matchfp, hyp, s->uttid, kbcore_dict(s->kbc), NULL);
- match_write(fp, hyp, s->uttid, kbcore_dict(s->kbc), "\nFWDVIT: ");
-
- /* Matchseg */
- if (s->matchsegfp)
- matchseg_write(s->matchsegfp, hyp, s->uttid, NULL,
- cmd_ln_int32("-hypsegfmt"), kbcore_lm(s->kbc),
- kbcore_dict(s->kbc), s->stat->nfr, s->ascale,
- cmd_ln_int32("-hypsegscore_unscale")
- );
- matchseg_write(fp, hyp, s->uttid, "FWDXCT: ",
- cmd_ln_int32("-hypsegfmt"), kbcore_lm(s->kbc),
- kbcore_dict(s->kbc), s->stat->nfr, s->ascale,
- cmd_ln_int32("-hypsegscore_unscale")
-
- );
- fprintf(fp, "\n");
-
- if (cmd_ln_str("-bestsenscrdir")) {
- int32 ispipe;
- char str[2048];
- FILE *bsfp;
- sprintf(str, "%s/%s.bsenscr",
- cmd_ln_str("-bestsenscrdir"), s->uttid);
- E_INFO("Dumping the Best senone scores.\n");
- if ((bsfp = fopen_comp(str, "w", &ispipe)) == NULL)
- E_ERROR("fopen_comp (%s,w) failed\n", str);
- else {
- write_bestsenscore(s);
- fclose_comp(bsfp, ispipe);
- }
- }
-
- if (cmd_ln_str("-outlatdir")) {
- int32 ispipe;
- char str[2048];
-
- ctl_outfile(str, cmd_ln_str("-outlatdir"), cmd_ln_str("-latext"),
- (s->uttfile ? s->uttfile : s->uttid), s->uttid);
- E_INFO("Writing lattice file: %s\n", str);
-
- if ((latfp = fopen_comp(str, "w", &ispipe)) == NULL)
- E_ERROR("fopen_comp (%s,w) failed\n", str);
- else {
-
-
- /* Write header info */
- /* Do link and unlink silences at here */
- dag_write_header(latfp, st->nfr, 0); /* Very fragile, if 1 is specifed,
- the code will just be stopped */
-
- vithist_dag_write(s->vithist, hyp, dict,
- cmd_ln_int32("-outlatoldfmt"), latfp,
- cmd_ln_int32("-outlatfmt") == OUTLATFMT_IBM);
- fclose_comp(latfp, ispipe);
-
- /* This should be moved out from the functions and allow polymorphism */
- /* Reread the lattice and create rescore it */
- bp = cmd_ln_int32("-bestpath");
-
- if (bp) {
- f32arg = (float32 *) cmd_ln_access("-bestpathlw");
- lwf =
- f32arg ? ((*f32arg) /
- *((float32 *) cmd_ln_access("-lw"))) : 1.0;
-
-
- if ((nfrm = s3dag_dag_load(&dag, lwf,
- str,
- dict, kbcore_fillpen(s->kbc)))
- >= 0) {
-
-
- /** Link back silences */
- linksilences(kbcore_lm(s->kbc), s->kbc,
- kbcore_dict(s->kbc));
-
- bph = dag_search(dag, s->uttid,
- lwf,
- dag->final.node,
- dict,
- kbcore_lm(s->kbc),
- kbcore_fillpen(s->kbc)
- );
-
- if (bph != NULL) {
- ghyp = NULL;
- for (tmph = bph; tmph; tmph = tmph->next)
- ghyp = glist_add_ptr(ghyp, (void *) tmph);
-
- rhyp = glist_reverse(ghyp);
- if (cmd_ln_int32("-backtrace"))
- match_detailed(stdout, rhyp, s->uttid, "BP",
- "bp", s->ascale,
- kbcore_dict(s->kbc));
-
- }
- else {
- E_ERROR
- ("%s: Bestpath search failed; using Viterbi result\n",
- s->uttid);
- rhyp = hyp;
- }
-
- match_write(stdout, rhyp, s->uttid,
- kbcore_dict(s->kbc), "BSTPTH: ");
- matchseg_write(stdout, rhyp, s->uttid, "BSTXCT: ",
- cmd_ln_int32("-hypsegfmt"),
- kbcore_lm(s->kbc), kbcore_dict(s->kbc),
- s->stat->nfr, s->ascale,
- cmd_ln_int32("-hypsegscore_unscale")
- );
-
- if (ghyp)
- glist_free(ghyp);
-
- /** unlink silences again */
- unlinksilences(kbcore_lm(s->kbc), s->kbc,
- kbcore_dict(s->kbc));
-
- }
- else {
- E_ERROR("DAG search (%s) failed\n", s->uttid);
- bph = NULL;
- }
-
- if (dag)
- dag_destroy(dag);
-
- lm_cache_stats_dump(kbcore_lm(s->kbc));
- lm_cache_reset(kbcore_lm(s->kbc));
-
- }
-
- /* If IBM format is required to dumped */
- if (cmd_ln_int32("-outlatfmt") == OUTLATFMT_IBM) {
- dag =
- dag_load(str, cmd_ln_int32("-maxedge"),
- cmd_ln_float32("-logbase"), 0,
- /** No fudge added */
- dict, kbcore_fillpen(s->kbc));
-
- if (dag != NULL) {
-
- word_graph_dump(cmd_ln_str("-outlatdir"),
- (s->uttfile ? s->uttfile : s->uttid),
- s->uttid,
- cmd_ln_str("-latext"), dag, dict,
- kbcore_lm(s->kbc), s->ascale);
-
- }
- else {
- E_ERROR("DAG conversion (%s) failed\n", s->uttid);
- }
-
- if (dag) {
- dag_destroy(dag);
- }
- }
- }
- }
-
-
- /** free the list containing hyps */
- for (gn = hyp; gn; gn = gnode_next(gn)) {
- ckd_free(gnode_ptr(gn));
- }
- glist_free(hyp);
-
-}
-#endif
-
-void
write_bstsenscr(FILE * fp, int32 numframe, int32 * scale)
{
@@ -1150,267 +959,3 @@
for (i = 0; i < numframe; i++)
fprintf(fp, "%d %d\n", i, scale[i]);
}
-
-static void
-write_bestsenscore(srch_t * s)
-{
- int32 ispipe;
- char str[2048];
- FILE *bsfp;
-
- E_INFO("Dumping the Best senone scores.\n");
- sprintf(str, "%s/%s.bsenscr", cmd_ln_str("-bestsenscrdir"), s->uttid);
-
- if ((bsfp = fopen_comp(str, "w", &ispipe)) == NULL)
- E_ERROR("fopen_comp (%s,w) failed\n", str);
- else {
- write_bstsenscr(bsfp, s->stat->nfr, s->ascale);
- fclose_comp(bsfp, ispipe);
- }
-}
-
-static void
-display_dump_hypothesis(srch_t * s, glist_t hyp, char *hyptag,
- char *hypsegtag, char *shortformCap,
- char *shortformSmall)
-{
- FILE *fp;
-
- fp = stderr;
-
- if (cmd_ln_int32("-backtrace")) {
- fprintf(fp, "\nBacktrace(%s)\n", s->uttid);
- match_detailed(fp, hyp, s->uttid, shortformCap, shortformSmall,
- s->ascale, kbcore_dict(s->kbc));
- }
-
- /* Match */
- if (s->matchfp)
- match_write(s->matchfp, hyp, s->uttid, kbcore_dict(s->kbc), NULL);
- fprintf(fp, "\n");
- match_write(fp, hyp, s->uttid, kbcore_dict(s->kbc), hyptag);
-
- /* Matchseg */
- if (s->matchsegfp)
- matchseg_write(s->matchsegfp, hyp, s->uttid, NULL,
- cmd_ln_int32("-hypsegfmt"), kbcore_lm(s->kbc),
- kbcore_dict(s->kbc), s->stat->nfr, s->ascale,
- cmd_ln_int32("-hypsegscore_unscale")
- );
- matchseg_write(fp, hyp, s->uttid, hypsegtag,
- cmd_ln_int32("-hypsegfmt"), kbcore_lm(s->kbc),
- kbcore_dict(s->kbc), s->stat->nfr, s->ascale,
- cmd_ln_int32("-hypsegscore_unscale")
-
- );
- fprintf(fp, "\n");
-}
-
-#if 0
-int32
-srch_bestpath_srch(srch_t * srch, dag_t * dag)
-{
- float32 *f32arg;
- float64 lwf;
-
- f32arg = (float32 *) cmd_ln_access("-bestpathlw");
- lwf = f32arg ? ((*f32arg) / *((float32 *) cmd_ln_access("-lw"))) : 1.0;
-
- bph = dag_search(dag, srch->uttid,
- lwf,
- dag->final.node,
- dict, kbcore_lm(srch->kbc), kbcore_fillpen(srch->kbc)
- );
-
- if (bph != NULL) {
- ghyp = NULL;
- for (tmph = bph; tmph; tmph = tmph->next)
- ghyp = glist_add_ptr(ghyp, (void *) tmph);
-
- rhyp = glist_reverse(ghyp);
- return rhyp;
- }
- else {
- return NULL;
- }
-}
-
-#endif
-
-
-
-#if 0 /* Insert this part of the code when score is needed to be dumped */
- /* This should be written as a small function */
-int32 ind;
-
-if (t == 0) {
- ms_mgau_model_t *mg;
- gauden_t *g;
- mg = kbcore_ms_mgau(s->kbc);
- g = mg->g;
- E_INFO("Time %d, Accum. Time %d, Segments %d Senscale %d. \n", t,
- s->num_frm + t, s->num_segs - 1, s->senscale);
- for (ind = 0; ind < g->n_mgau; ind++) {
-
- if (s->ascr->sen_active[ind]) {
-#if 0
- int32 i, j;
- gauden_dump_ind(g, ind);
-
- printf("Feature vector:\n");
- for (i = 0; i < g->n_feat; i++) {
- for (j = 0; j < g->featlen[i]; j++) {
- printf("%f ", block_feat[t][i][j]);
- }
- }
- printf("\n");
- fflush(stderr);
-#endif
- E_INFO
- ("Time %d Ind %d Active %d Senscr %d %f actual %f (Unnorm) %d %f actual %f \n",
- t, ind, s->ascr->sen_active[ind], s->ascr->senscr[ind],
- logs3_to_log(s->ascr->senscr[ind]),
- exp(logs3_to_log(s->ascr->senscr[ind])),
- s->ascr->senscr[ind] + s->senscale,
- logs3_to_log(s->ascr->senscr[ind] + s->senscale),
- exp(logs3_to_log(s->ascr->senscr[ind] + s->senscale))
- );
- }
- }
-}
-#endif
-
-
-/* Some draft code for 2nd stage: Disabled at this point. */
-
-#if 0 /** Refactor code that should be used, but I just don't have time to test them */
- /* 1, (Optionally) Generate the history table. */
-if (cmd_ln_str("-bptbldir"))
- srch->funcs->dump_vithist(srch);
-
- /* 2, (Optionally) Generate the best senone score. */
-if (cmd_ln_str("-bestsenscrdir"))
- write_bestsenscore(srch);
-
- /* 3, Generate hypothesis. */
-hyp = srch->funcs->gen_hyp(srch);
-
- /* 4, Display the hypthesis */
-if (hyp == NULL)
- E_WARN("No recognition result\n");
-
-display_dump_hypothesis(srch, hyp, "FWDVIT: ", "FWDXCT: ", "FV", "fv");
-
-if (srch->op_mode == OPERATION_GRAPH) {
- E_WARN
- ("Currently mode 2 (FSG decoding) doesn't support DAG generation.\n");
- return srch->funcs->utt_end(srch);
-}
-
- /*5, (Optionally) Generate the DAG. */
-if (cmd_ln_int32("-bestpath") || /* Generate lattice for best path search */
- cmd_ln_int32("-confidence") || /* Generate lattice for confidence scoring. */
- cmd_ln_str("-outlatdir") /* Generate lattice for the sake of generating lattice */
- ) {
-
-#if 1
- /* Hack! */
- /* Take care of the situation where mode 4 and 5 requires lattice
- write back to the harddiscs . That is if the users need to use bestpath
- */
- if ((cmd_ln_int32("-bestpath") || cmd_ln_int32("-confidence")) &&
- cmd_ln_str("-outlatdir") == NULL &&
- (srch->op_mode == OPERATION_TST_DECODE
- || srch->op_mode == OPERATION_WST_DECODE)
- )
- E_FATAL
- ("In TST and WST search (Mode 4 or 5), specifying -bestpath and -confidence also require -outlatdir");
-#endif
-
- dag = srch->funcs->gen_dag(srch, hyp);
-}
-
-
-
- /* 6, (Optionally) Do best path search <- Given 5 is done */
-if (cmd_ln_int32("-bestpath")) {
-
- bphyp = srch->funcs->bestpath_impl(srch, dag);
-
- if (bphyp == NULL) {
- E_ERROR("%s: Bestpath search failed; using Viterbi result\n",
- srch->uttid);
- bphyp = hyp;
- }
-
- display_dump_hypothesis(srch, bphyp, "BSTPTH: ", "BSTXCT: ", "BP",
- "bp");
-
- E_INFO("LM Cache After bestpath search\n");
- lm_cache_stats_dump(kbcore_lm(srch->kbc));
- lm_cache_reset(kbcore_lm(srch->kbc));
-
-}
-
- /*7, (Optionally) Confidence estimation based on Lattice <- Given 5 is done. */
-if (cmd_ln_int32("-confidence")) {
-}
-
-
-if (cmd_ln_int32("-outlatdir")) {
- if (cmd_ln_int32("-outlatfmt") == OUTLATFMT_IBM) {
-
- if (srch->op_mode == OPERATION_FLATFWD) {
- E_WARN("Not dumping IBM lattice file format at this point\n");
- }
- else {
- if (dag != NULL)
- word_graph_dump(cmd_ln_str("-outlatdir"),
- (srch->uttfile ? srch->uttfile : srch->uttid)
- srch->uttid,
- cmd_ln_str("-latext"), dag,
- kbcore_dict(srch->kbc),
- kbcore_lm(srch->kbc), srch->ascale);
- else
- E_ERROR("DAG conversion (%s) failed\n", srch->uttid);
- }
- }
- else if (cmd_ln_int32("-outlatfmt") == OUTLATFMT_SPHINX3) {
-
- if ((cmd_ln_int32("-bestpath") || cmd_ln_int32("-confidence")) &&
- cmd_ln_str("-outlatdir") == NULL &&
- (srch->op_mode == OPERATION_TST_DECODE
- || srch->op_mode == OPERATION_WST_DECODE)
- ) {
-
- /* Do nothing, because the code has already dumped the lattice
- as intermediates.
- */
- }
- else {
- srch->funcs->dag_dump(srch, hyp);
- }
-
- }
- else {
- E_ERROR("Unknown format ,do nothing in dumping files out\n");
- }
-}
-
-
-if (hyp != NULL) {
- /** free the list containing hyps */
- for (gn = hyp; gn; gn = gnode_next(gn))
- ckd_free(gnode_ptr(gn));
- glist_free(hyp);
-}
-if (bphyp != NULL) {
- for (gn = bphyp; gn; gn = gnode_next(gn))
- ckd_free(gnode_ptr(gn));
- glist_free(bphyp);
-}
-if (dag != NULL)
- dag_destroy(dag);
-
-return srch->funcs->utt_end(srch);
-#endif
Modified: trunk/sphinx3/src/libs3decoder/libsearch/srch_allphone.c
===================================================================
--- trunk/sphinx3/src/libs3decoder/libsearch/srch_allphone.c 2007-07-21 11:50:47 UTC (rev 6941)
+++ trunk/sphinx3/src/libs3decoder/libsearch/srch_allphone.c 2007-07-21 13:13:01 UTC (rev 6942)
@@ -672,58 +672,6 @@
}
static void
-allphone_log_hypseg(srch_t *s,
- phseg_t * hypptr, /* In: Hypothesis */
- char *uttid,
- int32 nfrm, /* In: #frames in utterance */
- int32 scl)
-{ /* In: Acoustic scaling for entire utt */
- phseg_t *h;
- int32 ascr, lscr, tscr;
- kbcore_t *kbcore = s->kbc;
- FILE *fp = s->matchsegfp;
-
- ascr = lscr = tscr = 0;
- for (h = hypptr; h; h = h->next) {
- ascr += h->score;
- lscr += h->tscore; /* FIXME: unscaled score? */
- tscr += h->score + h->tscore;
- }
-
- fprintf(fp, "%s S %d T %d A %d L %d", uttid, scl, tscr, ascr, lscr);
-
- if (!hypptr) /* HACK!! */
- fprintf(fp, " (null)\n");
- else {
- for (h = hypptr; h; h = h->next) {
- fprintf(fp, " %d %d %d %s", h->sf, h->score, h->tscore,
- mdef_ciphone_str(kbcore_mdef(kbcore), h->ci));
- }
- fprintf(fp, " %d\n", nfrm);
- }
-
- fflush(fp);
-}
-
-static void
-allphone_log_hypstr(srch_t *s, phseg_t * hypptr, char *uttid)
-{
- kbcore_t *kbcore = s->kbc;
- FILE *fp = s->matchfp;
- phseg_t *h;
-
- if (!hypptr) /* HACK!! */
- fprintf(fp, "(null)");
-
- for (h = hypptr; h; h = h->next) {
- fprintf(fp, "%s ", mdef_ciphone_str(kbcore_mdef(kbcore), h->ci));
- }
- fprintf(fp, " (%s)\n", uttid);
- fflush(fp);
-}
-
-
-static void
write_phseg(srch_t *s, char *dir, char *uttid, phseg_t * phseg)
{
char str[1024];
@@ -944,7 +892,6 @@
srch_t *s;
allphone_t *allp;
stat_t *st;
- int32 scl, i;
s = (srch_t *) srch;
allp = (allphone_t *) s->grh->graph_struct;
@@ -955,16 +902,6 @@
/* Write and/or log phoneme segmentation */
if (cmd_ln_exists("-phsegdir"))
write_phseg(s, (char *) cmd_ln_access("-phsegdir"), s->uttid, allp->phseg);
- else
- write_phseg(s, NULL, s->uttid, allp->phseg);
- if (s->matchfp)
- allphone_log_hypstr(s, allp->phseg, s->uttid);
- if (s->matchsegfp) {
- scl = 0;
- for (i = 0; i < allp->curfrm; ++i)
- scl += allp->score_scale[i];
- allphone_log_hypseg(s, allp->phseg, s->uttid, allp->curfrm, scl);
- }
return SRCH_SUCCESS;
}
@@ -1063,7 +1000,7 @@
srch_hyp_t *h;
h = (srch_hyp_t *) ckd_calloc(1, sizeof(srch_hyp_t));
- h->id = p->ci;
+ h->id = dict_wordid(s->kbc->dict, (char *)mdef_ciphone_str(allp->mdef, p->ci));
h->sf = p->sf;
h->ef = p->ef;
h->ascr = p->score;
Modified: trunk/sphinx3/src/libs3decoder/libsearch/srch_flat_fwd.c
===================================================================
--- trunk/sphinx3/src/libs3decoder/libsearch/srch_flat_fwd.c 2007-07-21 11:50:47 UTC (rev 6941)
+++ trunk/sphinx3/src/libs3decoder/libsearch/srch_flat_fwd.c 2007-07-21 13:13:01 UTC (rev 6942)
@@ -215,53 +215,7 @@
}
-static void
-write_bestscore(char *dir, char *uttid, int32 * score, int32 nfr)
-{
- char filename[1024];
- FILE *fp;
- int32 k;
- sprintf(filename, "%s/%s.bscr", dir, uttid);
- E_INFO("Writing bestscore file: %s\n", filename);
- if ((fp = fopen(filename, "wb")) == NULL) {
- E_ERROR("fopen(%s,wb) failed\n", filename);
- return;
- }
-
- /* Write version no. */
- if (fwrite("0.1\n", sizeof(char), 4, fp) != 4)
- goto write_error;
-
- /* Write binary comment string */
- if (fwrite("*end_comment*\n", sizeof(char), 14, fp) != 14)
- goto write_error;
-
- /* Write byte-ordering magic number */
- k = BYTE_ORDER_MAGIC;
- if (fwrite(&k, sizeof(int32), 1, fp) != 1)
- goto write_error;
-
- /* Write #frames */
- k = nfr;
- if (fwrite(&k, sizeof(int32), 1, fp) != 1)
- goto write_error;
-
- /* Write bestscore/frame */
- if (fwrite(score, sizeof(int32), nfr, fp) != nfr)
- goto write_error;
-
- fclose(fp);
- return;
-
- write_error:
- E_ERROR("fwrite(%s) failed\n", filename);
- fclose(fp);
-}
-
-
-
-
int
srch_FLAT_FWD_init(kb_t * kb, /**< The KB */
void *srch /**< The pointer to a search structure */
@@ -470,20 +424,11 @@
srch_t *s;
kbcore_t *kbc;
dict_t *dict;
- srch_hyp_t *hyp, *tmph, *btmph;
- glist_t ghyp, rhyp;
- glist_t bghyp, brhyp;
-
- /* char *bscrdir; */
stat_t *st;
- dag_t *dag;
- float32 *f32arg;
- float64 lwf;
whmm_t *h, *nexth;
s3wid_t w;
lm_t *lm;
- FILE *bptfp;
s = (srch_t *) srch;
@@ -498,7 +443,6 @@
pctr_increment(fwg->ctr_latentry, s->lathist->n_lat_entry);
/* Free whmm search structures */
-
for (w = 0; w < dict->n_word; w++) {
for (h = fwg->whmm[w]; h; h = nexth) {
nexth = h->next;
@@ -512,197 +456,9 @@
fwg->n_word_cand = 0;
}
-
- /* Check if bptable should be dumped (for debugging) */
- if (cmd_ln_str("-bptbldir")) {
- char file[8192];
- sprintf(file, "%s/%s.bpt", cmd_ln_str("-bptbldir"), s->uttid);
- if ((bptfp = fopen(file, "w")) == NULL) {
- E_ERROR("fopen(%s,w) failed; using stdout\n", file);
- bptfp = stdout;
- }
-
- latticehist_dump(s->lathist, bptfp, dict, fwg->ctxt, 0);
-
- if (bptfp != stdout)
- fclose(bptfp);
- }
-
- /* Backtrack through lattice for Viterbi result */
-
- s->exit_id = lat_final_entry(s->lathist, dict, fwg->n_frm, s->uttid);
- if (NOT_S3LATID(s->exit_id)) {
- E_INFO("lattice ID: %d\n", s->exit_id);
- E_ERROR("%s: NO RECOGNITION\n", s->uttid);
- }
- else {
- /* BAD_S3WID => Any right context */
- lattice_backtrace(s->lathist, s->exit_id, BAD_S3WID, &hyp, lm, dict,
- fwg->ctxt, s->kbc->fillpen);
- }
-
- ghyp = NULL;
- for (tmph = hyp; tmph; tmph = tmph->next) {
- /* E_INFO("tmph %s\n", tmph->word); */
- ghyp = glist_add_ptr(ghyp, (void *) tmph);
- }
-
-
- rhyp = glist_reverse(ghyp);
-
- if (cmd_ln_int32("-backtrace"))
- log_hyp_detailed(stdout, hyp, s->uttid, "FV", "fv", s->ascale);
-
-
- /* Log recognition output to the standard match and matchseg files */
-
- if (s->matchfp)
- match_write(s->matchfp, rhyp, s->uttid, kbcore_dict(s->kbc), NULL);
- match_write(stdout, rhyp, s->uttid, kbcore_dict(s->kbc), "\nFWDVIT: ");
-
- if (s->matchsegfp)
- matchseg_write(s->matchsegfp, rhyp, s->uttid, NULL,
- cmd_ln_int32("-hypsegfmt"), kbcore_lm(s->kbc),
- kbcore_dict(s->kbc), s->stat->nfr, s->ascale,
- cmd_ln_int32("-hypsegscore_unscale")
- );
- matchseg_write(stdout, rhyp, s->uttid, "FWDXCT: ",
- cmd_ln_int32("-hypsegfmt"), kbcore_lm(s->kbc),
- kbcore_dict(s->kbc), s->stat->nfr, s->ascale,
- cmd_ln_int32("-hypsegscore_unscale")
- );
-
-
-
- /* glist_free(ghyp); */
-
lm_cache_stats_dump(lm);
lm_cache_reset(lm);
- if (cmd_ln_str("-bestsenscrdir")) {
- int32 ispipe;
- char str[2048];
- FILE *bsfp;
- sprintf(str, "%s/%s.bsenscr",
- cmd_ln_str("-bestsenscrdir"), s->uttid);
- E_INFO("Dumping the Best senone scores.\n");
-
- if ((bsfp = fopen_comp(str, "w", &ispipe)) == NULL)
- E_ERROR("fopen_comp (%s,w) failed\n", str);
- else {
- write_bstsenscr(bsfp, s->stat->nfr, s->ascale);
- fclose_comp(bsfp, ispipe);
- }
- }
-
- if (cmd_ln_str("-outlatdir") || cmd_ln_int32("-bestpath")) {
-
- dag =
- dag_build(s->exit_id, s->lathist, dict, lm, fwg->ctxt, s->kbc->fillpen,
- fwg->n_frm);
-
-
- if (cmd_ln_str("-outlatdir")) {
- if (cmd_ln_int32("-outlatfmt") == OUTLATFMT_SPHINX3) {
- s3flat_fwd_dag_dump(cmd_ln_str("-outlatdir"), 0, s->uttid,
- cmd_ln_str("-latext"), s->lathist,
- fwg->n_frm, dag, lm, dict, fwg->ctxt,
- s->kbc->fillpen);
- }
- else if (cmd_ln_int32("-outlatfmt") == OUTLATFMT_IBM) {
-
- E_WARN
- ("IBM lattice generation is currently disabled. Please use s3.x routines instead.\n");
-
-#if 0 /* Keeper, we just don't know how to dump IBM lattice correctly with s3.0 yet */
- /* Add fudge before dump the graph */
- flat_fwd_dag_add_fudge_edges(dag,
- cmd_ln_int32("-dagfudge"),
- cmd_ln_int32("-min_endfr"),
- s->lathist, s->kbc->dict);
-
-
- word_graph_dump(cmd_ln_str("-outlatdir"), s->uttid,
- cmd_ln_str("-latext"), dag, dict, lm,
- s->ascale);
-#endif
- }
- else {
- E_ERROR("Unknown file format, fmt = %d\n",
- cmd_ln_int32("-outlatfmt"));
- }
- }
-
- if (cmd_ln_int32("-bestpath")) {
-
- f32arg = (float32 *) cmd_ln_access("-bestpathlw");
- lwf =
- f32arg ? ((*f32arg) /
- *((float32 *) cmd_ln_access("-lw"))) : 1.0;
-
- flat_fwd_dag_add_fudge_edges(fwg,
- dag,
- cmd_ln_int32("-dagfudge"),
- cmd_ln_int32("-min_endfr"),
- (void *) s->lathist,
- s->kbc->dict);
-
-
- /* Bypass filler nodes */
- if (!dag->filler_removed) {
- flat_fwd_dag_remove_filler_nodes(dag, s->lathist, lwf, lm,
- s->kbc->dict, fwg->ctxt,
- s->kbc->fillpen);
- dag->filler_removed = 1;
- }
-
- tmph =
- dag_search(dag, s->uttid, lwf,
- s->lathist->lattice[dag->latfinal].dagnode,
- s->kbc->dict, lm, s->kbc->fillpen);
-
- if (tmph)
- hyp = tmph;
- else
- E_ERROR
- ("%s: Bestpath search failed; using Viterbi result\n",
- s->uttid);
-
- if (cmd_ln_int32("-backtrace"))
- log_hyp_detailed(stdout, hyp, s->uttid, "BP", "bp",
- s->ascale);
-
- bghyp = NULL;
-
- for (btmph = hyp; btmph; btmph = btmph->next)
- bghyp = glist_add_ptr(bghyp, (void *) btmph);
-
- brhyp = glist_reverse(bghyp);
- match_write(stdout, brhyp, s->uttid, kbcore_dict(s->kbc),
- "\nBSTPTH: ");
- matchseg_write(stdout, brhyp, s->uttid, "BSTXCT: ",
- cmd_ln_int32("-hypsegfmt"), kbcore_lm(s->kbc),
- kbcore_dict(s->kbc), s->stat->nfr, s->ascale,
- cmd_ln_int32("-hypsegscore_unscale")
- );
-
- /* if(bghyp)
- glist_free(bghyp); */
- }
-
- if (dag)
- dag_destroy(dag);
-
- lm_cache_stats_dump(lm);
- lm_cache_reset(lm);
-
- }
-
-#if 0 /* HACK! Temporarily removed, to be put in srch.c */
- if ((bscrdir = (char *) cmd_ln_access("-bestscoredir")) != NULL)
- write_bestscore(bscrdir, s->uttid, bestscr, nfr);
-#endif
-
fwd_timing_dump(fwg);
stat_report_utt(st, s->uttid);
stat_update_corpus(st);
@@ -711,15 +467,7 @@
ptmr_reset(&(st->tm_srch));
ptmr_reset(&(st->tm_ovrhd));
- /* if(hyp!=NULL){
- srch_hyp_t *h;
- for(h=hyp ; h ; h =h->next)
- ckd_free(h);
- } */
-
return SRCH_SUCCESS;
-
-
}
int
@@ -879,26 +627,23 @@
{
srch_t *s;
srch_FLAT_FWD_graph_t *fwg;
- s3latid_t l;
srch_hyp_t *tmph, *hyp;
glist_t ghyp, rhyp;
s = (srch_t *) srch;
fwg = (srch_FLAT_FWD_graph_t *) s->grh->graph_struct;
- if (s->exit_id != -1)
- l = s->exit_id;
- else
- l = lat_final_entry(s->lathist, kbcore_dict(s->kbc), fwg->n_frm,
- s->uttid);
- if (NOT_S3LATID(l)) {
- E_INFO("lattice ID: %d\n", l);
+ if (s->exit_id == -1)
+ s->exit_id = lat_final_entry(s->lathist, kbcore_dict(s->kbc), fwg->n_frm,
+ s->uttid);
+ if (NOT_S3LATID(s->exit_id)) {
+ E_INFO("lattice ID: %d\n", s->exit_id);
E_ERROR("%s: NO RECOGNITION\n", s->uttid);
return NULL;
}
else {
/* BAD_S3WID => Any right context */
- lattice_backtrace(s->lathist, l, BAD_S3WID, &hyp,
+ lattice_backtrace(s->lathist, s->exit_id, BAD_S3WID, &hyp,
s->kbc->lmset->cur_lm, kbcore_dict(s->kbc),
fwg->ctxt, s->kbc->fillpen);
ghyp = NULL;
@@ -912,7 +657,6 @@
}
-#if 0
int
srch_FLAT_FWD_dump_vithist(void *srch)
{
@@ -950,16 +694,12 @@
srch_t *s;
srch_FLAT_FWD_graph_t *fwg;
dag_t *dag;
- s3latid_t l;
s = (srch_t *) srch;
fwg = (srch_FLAT_FWD_graph_t *) s->grh->graph_struct;
- l = lat_final_entry(s->lathist, kbcore_dict(s->kbc), fwg->n_frm,
- s->uttid);
-
dag =
- dag_build(l, s->lathist, kbcore_dict(s->kbc),
+ dag_build(s->exit_id, s->lathist, kbcore_dict(s->kbc),
s->kbc->lmset->cur_lm, fwg->ctxt, s->kbc->fillpen,
fwg->n_frm);
@@ -988,10 +728,11 @@
f32arg = (float32 *) cmd_ln_access("-bestpathlw");
lwf = f32arg ? ((*f32arg) / *((float32 *) cmd_ln_access("-lw"))) : 1.0;
- dag_add_fudge_edges(dag,
- cmd_ln_int32("-dagfudge"),
- cmd_ln_int32("-min_endfr"),
- (void *) s->lathist, s->kbc->dict);
+ flat_fwd_dag_add_fudge_edges(fwg,
+ dag,
+ cmd_ln_int32("-dagfudge"),
+ cmd_ln_int32("-min_endfr"),
+ (void *) s->lathist, s->kbc->dict);
/* Bypass filler nodes */
@@ -1023,30 +764,22 @@
}
int32
-srch_FLAT_FWD_dag_dump(void *srch, glist_t hyp)
+srch_FLAT_FWD_dag_dump(void *srch, dag_t *dag)
{
srch_t *s;
srch_FLAT_FWD_graph_t *fwg;
- dag_t *dag;
- s3latid_t l;
s = (srch_t *) srch;
fwg = (srch_FLAT_FWD_graph_t *) s->grh->graph_struct;
assert(s->lathist);
- l = lat_final_entry(s->lathist, kbcore_dict(s->kbc), fwg->n_frm,
- s->uttid);
- dag =
- dag_build(l, s->lathist, kbcore_dict(s->kbc), kbcore_lm(s->kbc),
- fwg->ctxt, s->kbc->fillpen, fwg->n_frm);
-
s3flat_fwd_dag_dump(cmd_ln_str("-outlatdir"), 0, s->uttid,
cmd_ln_str("-latext"), s->lathist, fwg->n_frm, dag,
kbcore_lm(s->kbc), kbcore_dict(s->kbc), fwg->ctxt,
s->kbc->fillpen);
+
return SRCH_SUCCESS;
}
-#endif
/* Pointers to all functions */
srch_funcs_t srch_FLAT_FWD_funcs = {
@@ -1080,9 +813,9 @@
/* select_active_gmm */ srch_FLAT_FWD_select_active_gmm,
/* gen_hyp */ srch_FLAT_FWD_gen_hyp,
- /* gen_dag */ NULL,
- /* dump_vithist */ NULL,
- /* bestpath_impl */ NULL,
- /* dag_dump */ NULL,
+ /* gen_dag */ srch_FLAT_FWD_gen_dag,
+ /* dump_vithist */ srch_FLAT_FWD_dump_vithist,
+ /* bestpath_impl */ srch_FLAT_FWD_bestpath_impl,
+ /* dag_dump */ srch_FLAT_FWD_dag_dump,
NULL
};
Modified: trunk/sphinx3/src/libs3decoder/libsearch/srch_fsg.c
===================================================================
--- trunk/sphinx3/src/libs3decoder/libsearch/srch_fsg.c 2007-07-21 11:50:47 UTC (rev 6941)
+++ trunk/sphinx3/src/libs3decoder/libsearch/srch_fsg.c 2007-07-21 13:13:01 UTC (rev 6942)
@@ -78,7 +78,9 @@
#include "kb.h"
#include "kbcore.h"
+static word_fsg_t *srch_FSG_read_fsgfile(void *srch, const char *fsgfilename);
+
int
srch_FSG_init(kb_t * kb, /**< The KB */
void *srch /**< The pointer to a search structure */
@@ -110,7 +112,7 @@
return SRCH_SUCCESS;
}
-word_fsg_t *
+static word_fsg_t *
srch_FSG_read_fsgfile(void *srch, const char *fsgfilename)
{
word_fsg_t *fsg;
Modified: trunk/sphinx3/src/libs3decoder/libsearch/srch_output.c
===================================================================
--- trunk/sphinx3/src/libs3decoder/libsearch/srch_output.c 2007-07-21 11:50:47 UTC (rev 6941)
+++ trunk/sphinx3/src/libs3decoder/libsearch/srch_output.c 2007-07-21 13:13:01 UTC (rev 6942)
@@ -118,7 +118,7 @@
h = (srch_hyp_t *) gnode_ptr(gn);
ascr += h->ascr;
- lscr += lm_rawscore(lm, lscr);
+ lscr += lm ? lm_rawscore(lm, h->lscr) : h->lscr;
if (unnorm)
global_hypscale += compute_scale(h->sf, h->ef, ascale);
@@ -140,7 +140,6 @@
lscr);
-/* for (gn = hyp; gn && (gnode_next(gn)); gn = gnode_next(gn)) { */
for (gn = hyp; gn; gn = gnode_next(gn)) {
h = (srch_hyp_t *) gnode_ptr(gn);
@@ -150,14 +149,14 @@
fprintf(fp, " %d %d %d %s", h->sf, h->ascr + hypscale,
- lm_rawscore(lm, h->lscr), dict_wordstr(dict, h->id));
+ lm ? lm_rawscore(lm, h->lscr) : h->lscr,
+ dict_wordstr(dict, h->id));
}
fprintf(fp, " %d\n", num_frm);
}
else if (fmt == SEG_FMT_SPHINX2) {
fprintf(fp, "%s%s ", (hdr ? hdr : ""), uttid);
-/* for (gn = hyp; gn && (gnode_next(gn)); gn = gnode_next(gn)) { */
for (gn = hyp; gn; gn = gnode_next(gn)) {
h = (srch_hyp_t *) gnode_ptr(gn);
@@ -167,7 +166,8 @@
/*FIXME!, what is the second output of the matchseg file? */
fprintf(fp, "%s 0 %d %d %d %d ", dict_wordstr(dict, h->id),
- h->sf, h->ef, h->ascr, lm_rawscore(lm, h->lscr));
+ h->sf, h->ef, h->ascr,
+ lm ? lm_rawscore(lm, h->lscr) : h->lscr);
}
@@ -177,7 +177,6 @@
}
else if (fmt == SEG_FMT_CTM) {
-/* for (gn = hyp; gn && (gnode_next(gn)); gn = gnode_next(gn)) { */
for (gn = hyp; gn; gn = gnode_next(gn)) {
h = (srch_hyp_t *) gnode_ptr(gn);
Modified: trunk/sphinx3/src/libs3decoder/libsearch/srch_time_switch_tree.c
===================================================================
--- trunk/sphinx3/src/libs3decoder/libsearch/srch_time_switch_tree.c 2007-07-21 11:50:47 UTC (rev 6941)
+++ trunk/sphinx3/src/libs3decoder/libsearch/srch_time_switch_tree.c 2007-07-21 13:13:01 UTC (rev 6942)
@@ -141,6 +141,7 @@
#include "srch.h"
#include "dict.h"
#include "cmd_ln.h"
+#include "corpus.h"
#include "approx_cont_mgau.h"
#define REPORT_SRCH_TST 1
@@ -349,6 +350,8 @@
kbc = s->kbc;
g = kbc->mgau;
+ /* Clean up any previous viterbi history */
+ vithist_utt_reset(s->vithist);
stat_clear_utt(s->stat);
histprune_zero_histbin(tstg->histprune);
@@ -391,16 +394,10 @@
srch_TST_end(void *srch)
{
int32 i;
- FILE *fp;
- /**latfp, *bptfp;*/
srch_t *s;
srch_TST_graph_t *tstg;
stat_t *st;
- histprune_t *hp;
- dict_t *dict;
- char *uttid;
-
s = (srch_t *) srch;
assert(s);
assert(s->op_mode == 4);
@@ -409,49 +406,31 @@
assert(tstg);
st = s->stat;
- hp = tstg->histprune;
- fp = stderr;
- dict = kbcore_dict(s->kbc);
- uttid = s->uttid;
+ /* Find the exit word and wrap up Viterbi history (but don't reset
+ * it yet!) */
+ s->exit_id = vithist_utt_end(s->vithist, s->kbc);
- if ((s->exit_id = vithist_utt_end(s->vithist, s->kbc)) >= 0) {
- /* E_INFO("ID %d\n",id); */
- reg_result_dump(s, s->exit_id);
- }
- else
- E_ERROR("%s: No recognition\n\n", uttid);
-
/* Statistics update/report */
st->utt_wd_exit = vithist_n_entry(s->vithist);
- stat_report_utt(st, uttid);
- histprune_showhistbin(tstg->histprune, st->nfr, uttid);
+ stat_report_utt(st, s->uttid);
+ histprune_showhistbin(tstg->histprune, st->nfr, s->uttid);
stat_update_corpus(st);
ptmr_reset(&(st->tm_sen));
ptmr_reset(&(st->tm_srch));
ptmr_reset(&(st->tm_ovrhd));
-#if (!defined(WIN32))
- if (!system("ps auxgw > /dev/null 2>&1")) {
- system("ps aguxwww | grep /live | grep -v grep");
- system("ps aguxwww | grep /dec | grep -v grep");
- }
-#endif
-
for (i = 0; i < tstg->n_lextree; i++) {
lextree_utt_end(tstg->curugtree[i], s->kbc);
lextree_utt_end(tstg->fillertree[i], s->kbc);
}
- vithist_utt_reset(s->vithist);
-
lm_cache_stats_dump(kbcore_lm(s->kbc));
lm_cache_reset(kbcore_lm(s->kbc));
- if (s->exit_id >= 0) {
+ if (s->exit_id >= 0)
return SRCH_SUCCESS;
- }
else
return SRCH_FAILURE;
}
@@ -1251,24 +1230,25 @@
return vithist_backtrace(s->vithist, id, kbcore_dict(s->kbc));
}
-#if 0
int
srch_TST_dump_vithist(void *srch)
{
srch_t *s;
FILE *bptfp;
- char file[8192];
+ char *file;
s = (srch_t *) srch;
assert(s->vithist);
+ file = ckd_calloc(strlen(cmd_ln_str("-bptbldir")) + strlen(s->uttid) + 5, 1);
sprintf(file, "%s/%s.bpt", cmd_ln_str("-bptbldir"), s->uttid);
if ((bptfp = fopen(file, "w")) == NULL) {
E_ERROR("fopen(%s,w) failed; using stdout\n", file);
bptfp = stdout;
}
+ ckd_free(file);
vithist_dump(s->vithist, -1, s->kbc, bptfp);
@@ -1279,17 +1259,6 @@
}
-/* FIXME! Temporary measure, The code now actually temporarily
- write the dag file onto harddisc and all subsequent operation
- will need to require reading the dag back. Currently that
- includes the -bestpath, -outlatfmt and -confidence operation.
- They are now separated with different ifs.
-
- A good way to solve is to work on the dag structure which
- unfortunately was not supported by vithist.c from 3.x (x<6).
- We will change this later on.
-*/
-
dag_t *
srch_TST_gen_dag(void *srch, /**< a pointer of srch_t */
glist_t hyp)
@@ -1361,6 +1330,7 @@
kbcore_lm(s->kbc), kbcore_fillpen(s->kbc)
);
+
if (bph != NULL) {
ghyp = NULL;
for (tmph = bph; tmph; tmph = tmph->next)
@@ -1376,28 +1346,27 @@
}
int32
-srch_TST_dag_dump(void *srch, glist_t hyp)
+srch_TST_dag_dump(void *srch, dag_t *dag)
{
int32 ispipe;
char str[2048];
FILE *latfp;
- float32 *f32arg;
- dag_t *dag;
srch_t *s;
+ glist_t hyp;
s = (srch_t *) srch;
dag = NULL;
- sprintf(str, "%s/%s.%s",
- cmd_ln_str("-outlatdir"), s->uttid, cmd_ln_str("-latext"));
-
+ ctl_outfile(str, cmd_ln_str("-outlatdir"), cmd_ln_str("-latext"),
+ (s->uttfile ? s->uttfile : s->uttid), s->uttid);
E_INFO("Writing lattice file: %s\n", str);
if ((latfp = fopen_comp(str, "w", &ispipe)) == NULL) {
E_ERROR("fopen_comp (%s,w) failed\n", str);
- return NULL;
+ return SRCH_FAILURE;
}
else {
+ hyp = srch_TST_gen_hyp(srch);
dag_write_header(latfp, s->stat->nfr, 0); /* Very fragile, if 1 is specifed,
the code will just be stopped */
@@ -1408,12 +1377,9 @@
fclose_comp(latfp, ispipe);
}
+ return SRCH_SUCCESS;
}
-
-#endif
-
-
/* Pointers to all functions */
srch_funcs_t srch_TST_funcs = {
/* init */ srch_TST_init,
@@ -1446,9 +1412,9 @@
/* select_active_gmm */ srch_TST_select_active_gmm,
/* gen_hyp */ srch_TST_gen_hyp,
- /* gen_dag */ NULL,
- /* dump_vithist */ NULL,
- /* bestpath_impl */ NULL,
- /* dag_dump */ NULL,
+ /* gen_dag */ srch_TST_gen_dag,
+ /* dump_vithist */ srch_TST_dump_vithist,
+ /* bestpath_impl */ srch_TST_bestpath_impl,
+ /* dag_dump */ srch_TST_dag_dump,
NULL
};
Modified: trunk/sphinx3/src/libs3decoder/libsearch/srch_word_switch_tree.c
===================================================================
--- trunk/sphinx3/src/libs3decoder/libsearch/srch_word_switch_tree.c 2007-07-21 11:50:47 UTC (rev 6941)
+++ trunk/sphinx3/src/libs3decoder/libsearch/srch_word_switch_tree.c 2007-07-21 13:13:01 UTC (rev 6942)
@@ -436,7 +436,7 @@
/* This part is duplicated with TST_end */
-#if 1
+#if 0
if ((s->exit_id = vithist_utt_end(s->vithist, s->kbc)) >= 0) {
reg_result_dump(s, s->exit_id);
}
Modified: trunk/sphinx3/src/libs3decoder/libsearch/vithist.c
===================================================================
--- trunk/sphinx3/src/libs3decoder/libsearch/vithist.c 2007-07-21 11:50:47 UTC (rev 6941)
+++ trunk/sphinx3/src/libs3decoder/libsearch/vithist.c 2007-07-21 13:13:01 UTC (rev 6942)
@@ -2062,7 +2062,7 @@
fillpen);
#endif
- h = (srch_hyp_t *) listelem_alloc(sizeof(srch_hyp_t));
+ h = ckd_calloc(1, sizeof(srch_hyp_t));
if (!prevh)
*hyp = h;
else
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|