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);
52 static 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);
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",
120 phone_loop_search_init(cmd_ln_t *config,
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));
156 phone_loop_search_free_renorm(pls);
171 for (i = 0; i < pls->
n_phones; ++i) {
177 for (i = 0; i < pls->
window; i++)
179 phone_loop_search_free_renorm(pls);
196 for (i = 0; i < pls->
n_phones; ++i) {
209 for (i = 0; i < pls->
n_phones; ++i) {
213 if (hmm_frame(hmm) < frame_idx)
228 for (i = 0; i < pls->
n_phones; ++i) {
236 for (i = 0; i < pls->
n_phones; ++i) {
238 for (j = 0, itr = pls->
pen_buf_ptr + 1; j < pls->window; j++, itr++) {
250 int nf = frame_idx + 1;
254 for (i = 0; i < pls->
n_phones; ++i) {
257 if (hmm_frame(hmm) < frame_idx)
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);
301 phone_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);
348 phone_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");
int32 * penalties
Penalties for CI phones in current frame.
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.
int32 ** pen_buf
Penalty buffer.
float64 penalty_weight
Weighting factor for penalties.
void ps_search_init(ps_search_t *search, ps_searchfuncs_t *vt, const char *type, const char *name, 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.
void ps_search_base_free(ps_search_t *search)
Free search.
int16 pen_buf_ptr
Pointer for frame to fill in penalty buffer.
#define WORST_SCORE
Large "bad" score.
tmat_t * tmat
Transition matrices.
void hmm_enter(hmm_t *h, int32 score, int32 histid, int frame)
Enter an HMM with the given path score and history ID.
void acmod_clear_active(acmod_t *acmod)
Clear set of active senones.
#define hmm_context_set_senscore(ctx, senscr)
Change the senone score array for a context.
#define SENSCR_SHIFT
Shift count for senone scores.
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.
int window
Window size for phoneme lookahead.
hmm_t * hmms
Basic HMM structures for CI phones.
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.
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.