42#include <sphinxbase/err.h>
46static int phone_loop_search_start(
ps_search_t *search);
47static int phone_loop_search_step(
ps_search_t *search,
int frame_idx);
48static int phone_loop_search_finish(
ps_search_t *search);
50static void phone_loop_search_free(
ps_search_t *search);
51static char const *phone_loop_search_hyp(
ps_search_t *search, int32 *out_score);
52static int32 phone_loop_search_prob(
ps_search_t *search);
56 phone_loop_search_start,
57 phone_loop_search_step,
58 phone_loop_search_finish,
59 phone_loop_search_reinit,
60 phone_loop_search_free,
62 phone_loop_search_hyp,
63 phone_loop_search_prob,
64 phone_loop_search_seg_iter,
71 cmd_ln_t *config = ps_search_config(search);
72 acmod_t *acmod = ps_search_acmod(search);
76 ps_search_base_reinit(search, dict, d2p);
80 hmm_context_free(pls->
hmmctx);
81 pls->
hmmctx = hmm_context_init(bin_mdef_n_emit_state(acmod->
mdef),
88 pls->
window = cmd_ln_int32_r(config,
"-pl_window");
103 for (i = 0; i < pls->
n_phones; ++i) {
106 bin_mdef_pid2ssid(acmod->
mdef, i),
107 bin_mdef_pid2tmatid(acmod->
mdef, i));
113 E_INFO(
"State beam %d Phone exit beam %d Insertion penalty %d\n",
120phone_loop_search_init(cmd_ln_t *config,
128 ps_search_init(ps_search_base(pls), &phone_loop_search_funcs,
129 PS_SEARCH_TYPE_PHONE_LOOP, PS_DEFAULT_PL_SEARCH,
130 config, acmod, dict, NULL);
131 phone_loop_search_reinit(ps_search_base(pls), ps_search_dict(pls),
132 ps_search_dict2pid(pls));
134 return ps_search_base(pls);
141 for (gn = pls->
renorm; gn; gn = gnode_next(gn))
142 ckd_free(gnode_ptr(gn));
153 ps_search_base_free(search);
156 phone_loop_search_free_renorm(pls);
160 hmm_context_free(pls->
hmmctx);
171 for (i = 0; i < pls->
n_phones; ++i) {
174 hmm_enter(hmm, 0, -1, 0);
177 for (i = 0; i < pls->
window; i++)
179 phone_loop_search_free_renorm(pls);
196 for (i = 0; i < pls->
n_phones; ++i) {
197 hmm_normalize((
hmm_t *)&pls->
hmms[i], norm);
209 for (i = 0; i < pls->
n_phones; ++i) {
213 if (hmm_frame(hmm) < frame_idx)
215 score = hmm_vit_eval(hmm);
228 for (i = 0; i < pls->
n_phones; ++i) {
236 for (i = 0; i < pls->
n_phones; ++i) {
250 int nf = frame_idx + 1;
254 for (i = 0; i < pls->
n_phones; ++i) {
257 if (hmm_frame(hmm) < frame_idx)
264 hmm_clear_scores(hmm);
272 int nf = frame_idx + 1;
277 for (i = 0; i < pls->
n_phones; ++i) {
279 int32 newphone_score;
282 if (hmm_frame(hmm) != nf)
285 newphone_score = hmm_out_score(hmm) + pls->
pip;
288 for (j = 0; j < pls->
n_phones; ++j) {
291 if (hmm_frame(nhmm) < frame_idx
292 || newphone_score
BETTER_THAN hmm_in_score(nhmm)) {
293 hmm_enter(nhmm, newphone_score, hmm_out_history(hmm), nf);
301phone_loop_search_step(
ps_search_t *search,
int frame_idx)
304 acmod_t *acmod = ps_search_acmod(search);
309 if (!ps_search_acmod(pls)->compallsen) {
320 E_INFO(
"Renormalizing Scores at frame %d, best score %d\n",
322 renormalize_hmms(pls, frame_idx, pls->
best_score);
326 evaluate_hmms(pls, senscr, frame_idx);
329 store_scores(pls, frame_idx);
332 prune_hmms(pls, frame_idx);
335 phone_transition(pls, frame_idx);
348phone_loop_search_hyp(
ps_search_t *search, int32 *out_score)
350 E_WARN(
"Hypotheses are not returned from phone loop search");
358 E_WARN(
"Posterior probabilities are not returned from phone loop search");
365 E_WARN(
"Hypotheses are not returned from phone loop search");
void acmod_activate_hmm(acmod_t *acmod, hmm_t *hmm)
Activate senones associated with an HMM.
int16 const * acmod_score(acmod_t *acmod, int *inout_frame_idx)
Score one frame of data.
void acmod_clear_active(acmod_t *acmod)
Clear set of active senones.
#define BETTER_THAN
Is one score better than another?
#define hmm_context_set_senscore(ctx, senscr)
Change the senone score array for a context.
#define WORST_SCORE
Large "bad" score.
#define WORSE_THAN
Is one score worse than another?
#define SENSCR_SHIFT
Shift count for senone scores.
Fast and rough context-independent phoneme loop search.
Acoustic model structure.
bin_mdef_t * mdef
Model definition.
logmath_t * lmath
Log-math computation.
tmat_t * tmat
Transition matrices.
uint16 ** sseq
Unique senone sequences (2D array built at load time)
Building composite triphone (as well as word internal triphones) with the dictionary.
a structure for a dictionary.
An individual HMM among the HMM search space.
int32 norm
Normalization constant.
int frame_idx
Frame of renormalization.
Phone loop search structure.
int32 * penalties
Penalties for CI phones in current frame.
int32 beam
HMM pruning beam width.
glist_t renorm
List of renormalizations.
int window
Window size for phoneme lookahead.
int16 pen_buf_ptr
Pointer for frame to fill in penalty buffer.
hmm_context_t * hmmctx
HMM context structure.
hmm_t * hmms
Basic HMM structures for CI phones.
int16 n_phones
Size of phone array.
int32 pbeam
Phone exit pruning beam width.
int32 pip
Phone insertion penalty ("language score").
int32 ** pen_buf
Penalty buffer.
float64 penalty_weight
Weighting factor for penalties.
int32 best_score
Best Viterbi score in current frame.
Base structure for search module.
V-table for search algorithm.
Base structure for hypothesis segmentation iterator.
uint8 *** tp
The transition matrices; kept in the same scale as acoustic scores; tp[tmatid][from-state][to-state].