42 #include <sphinxbase/err.h> 46 static int phone_loop_search_start(
ps_search_t *search);
47 static int phone_loop_search_step(
ps_search_t *search,
int frame_idx);
48 static int phone_loop_search_finish(
ps_search_t *search);
50 static void phone_loop_search_free(
ps_search_t *search);
51 static char const *phone_loop_search_hyp(
ps_search_t *search, int32 *out_score, int32 *out_is_final);
52 static int32 phone_loop_search_prob(
ps_search_t *search);
57 phone_loop_search_start,
58 phone_loop_search_step,
59 phone_loop_search_finish,
60 phone_loop_search_reinit,
61 phone_loop_search_free,
63 phone_loop_search_hyp,
64 phone_loop_search_prob,
65 phone_loop_search_seg_iter,
72 cmd_ln_t *config = ps_search_config(search);
73 acmod_t *acmod = ps_search_acmod(search);
95 for (i = 0; i < pls->
n_phones; ++i) {
99 bin_mdef_pid2ssid(acmod->
mdef, i),
100 bin_mdef_pid2tmatid(acmod->
mdef, i));
102 pls->
beam = logmath_log(acmod->
lmath, cmd_ln_float64_r(config,
"-pl_beam"));
103 pls->
pbeam = logmath_log(acmod->
lmath, cmd_ln_float64_r(config,
"-pl_pbeam"));
104 pls->
pip = logmath_log(acmod->
lmath, cmd_ln_float64_r(config,
"-pip"));
105 E_INFO(
"State beam %d Phone exit beam %d Insertion penalty %d\n",
112 phone_loop_search_init(cmd_ln_t *config,
119 pls = ckd_calloc(1,
sizeof(*pls));
121 config, acmod, dict, NULL);
122 phone_loop_search_reinit(ps_search_base(pls), ps_search_dict(pls),
123 ps_search_dict2pid(pls));
125 return ps_search_base(pls);
132 for (gn = pls->
renorm; gn; gn = gnode_next(gn))
133 ckd_free(gnode_ptr(gn));
147 phone_loop_search_free_renorm(pls);
160 for (i = 0; i < pls->
n_phones; ++i) {
165 phone_loop_search_free_renorm(pls);
181 for (i = 0; i < pls->
n_phones; ++i) {
194 for (i = 0; i < pls->
n_phones; ++i) {
198 if (hmm_frame(hmm) < frame_idx)
213 int nf = frame_idx + 1;
217 for (i = 0; i < pls->
n_phones; ++i) {
220 if (hmm_frame(hmm) < frame_idx)
235 int nf = frame_idx + 1;
240 for (i = 0; i < pls->
n_phones; ++i) {
242 int32 newphone_score;
245 if (hmm_frame(hmm) != nf)
248 newphone_score = hmm_out_score(hmm) + pls->
pip;
251 for (j = 0; j < pls->
n_phones; ++j) {
254 if (hmm_frame(nhmm) < frame_idx
255 || newphone_score
BETTER_THAN hmm_in_score(nhmm)) {
256 hmm_enter(nhmm, newphone_score, hmm_out_history(hmm), nf);
264 phone_loop_search_step(
ps_search_t *search,
int frame_idx)
267 acmod_t *acmod = ps_search_acmod(search);
272 if (!ps_search_acmod(pls)->compallsen)
281 E_INFO(
"Renormalizing Scores at frame %d, best score %d\n",
283 renormalize_hmms(pls, frame_idx, pls->
best_score);
287 pls->
best_score = evaluate_hmms(pls, senscr, frame_idx);
290 prune_hmms(pls, frame_idx);
293 phone_transition(pls, frame_idx);
306 phone_loop_search_hyp(
ps_search_t *search, int32 *out_score, int32 *out_is_final)
308 E_WARN(
"Hypotheses are not returned from phone loop search");
316 E_WARN(
"Posterior probabilities are not returned from phone loop search");
321 phone_loop_search_seg_iter(
ps_search_t *search, int32 *out_score)
323 E_WARN(
"Hypotheses are not returned from phone loop search");
Base structure for search module.
void hmm_init(hmm_context_t *ctx, hmm_t *hmm, int mpx, int ssid, int tmatid)
Populate a previously-allocated HMM structure, allocating internal data.
int32 pbeam
Phone exit pruning beam width.
hmm_context_t * hmmctx
HMM context structure.
void ps_search_base_reinit(ps_search_t *search, dict_t *dict, dict2pid_t *d2p)
Re-initialize base structure with new dictionary.
An individual HMM among the HMM search space.
uint8 *** tp
The transition matrices; kept in the same scale as acoustic scores; tp[tmatid][from-state][to-state]...
logmath_t * lmath
Log-math computation.
uint16 ** sseq
Unique senone sequences (2D array built at load time)
void hmm_deinit(hmm_t *hmm)
Free an HMM structure, releasing internal data (but not the HMM structure itself).
void acmod_activate_hmm(acmod_t *acmod, hmm_t *hmm)
Activate senones associated with an HMM.
void ps_search_init(ps_search_t *search, ps_searchfuncs_t *vt, cmd_ln_t *config, acmod_t *acmod, dict_t *dict, dict2pid_t *d2p)
Initialize base structure.
int32 norm
Normalization constant.
int32 hmm_vit_eval(hmm_t *hmm)
Viterbi evaluation of given HMM.
void hmm_normalize(hmm_t *h, int32 bestscr)
Renormalize the scores in this HMM based on the given best score.
hmm_context_t * hmm_context_init(int32 n_emit_state, uint8 **const *tp, int16 const *senscore, uint16 *const *sseq)
Create an HMM context.
#define WORST_SCORE
Large "bad" score.
tmat_t * tmat
Transition matrices.
int16 ciphone
Context-independent phone ID.
void hmm_enter(hmm_t *h, int32 score, int32 histid, int frame)
Enter an HMM with the given path score and history ID.
phone_loop_t * phones
Array of phone arcs.
#define hmm_context_set_senscore(ctx, senscr)
Change the senone score array for a context.
a structure for a dictionary.
#define WORSE_THAN
Is one score worse than another?
void hmm_clear(hmm_t *h)
Reset the states of the HMM to the invalid condition.
Fast and rough context-independent phoneme loop search.
int32 best_score
Best Viterbi score in current frame.
int32 beam
HMM pruning beam width.
#define BETTER_THAN
Is one score better than another?
void hmm_clear_scores(hmm_t *h)
Reset the scores of the HMM.
int32 pip
Phone insertion penalty ("language score").
void hmm_context_free(hmm_context_t *ctx)
Free an HMM context.
bin_mdef_t * mdef
Model definition.
V-table for search algorithm.
Base structure for hypothesis segmentation iterator.
int frame_idx
Frame of renormalization.
Acoustic model structure.
Building composite triphone (as well as word internal triphones) with the dictionary.
void ps_search_deinit(ps_search_t *search)
De-initialize base structure.
int16 n_phones
Size of phone array.
Phone loop search structure.
glist_t renorm
List of renormalizations.
int16 const * acmod_score(acmod_t *acmod, int *inout_frame_idx)
Score one frame of data.