51 #include "lm3g_model.h"
75 float32 lw, float32 wip, float32 uw)
77 int32 log_wip, log_uw, log_uniform_weight;
85 for (i = 0; i < base->
n_counts[0]; ++i) {
86 int32 prob1, bo_wt, n_used;
89 bo_wt = (int32)(lm3g->unigrams[i].
bo_wt1.l / base->
lw);
94 lm3g->unigrams[i].
bo_wt1.l = (int32)(bo_wt * lw);
95 if (strcmp(base->
word_str[i],
"<s>") == 0) {
97 lm3g->unigrams[i].
prob1.l = (int32)(prob1 * lw) + log_wip;
104 lm3g->unigrams[i].
prob1.l = (int32)(prob1 * lw) + log_wip;
108 for (i = 0; i < lm3g->
n_prob2; ++i) {
112 lm3g->
prob2[i].l = (int32)(prob2 * lw) + log_wip;
116 for (i = 0; i < lm3g->
n_bo_wt2; ++i) {
119 for (i = 0; i < lm3g->
n_prob3; i++) {
123 lm3g->
prob3[i].l = (int32)(prob3 * lw) + log_wip;
141 assert(!NGRAM_IS_CLASSWID(wid));
146 memset(lm3g->unigrams + base->
n_counts[0], 0,
161 lm3g->unigrams[wid].
prob1.l = score;
164 lm3g->unigrams[wid].
bo_wt1.l = 0;
165 lm3g->unigrams[wid].
bigrams = 0;
178 #define INITIAL_SORTED_ENTRIES MAX_UINT16
184 l->list[0].
val.l = INT_MIN;
185 l->list[0].
lower = 0;
188 l->size = INITIAL_SORTED_ENTRIES;
204 for (i = 0; i < l->
free; i++)
205 vals[i] = l->list[i].
val;
215 if (*val == l->list[i].
val.l)
217 if (*val < l->list[i].val.l) {
218 if (l->list[i].
lower == 0) {
220 if (l->
free >= l->size) {
221 int newsize = l->size + INITIAL_SORTED_ENTRIES;
223 memset(l->list + l->size,
230 i = l->list[i].
lower;
231 l->list[i].
val.l = *val;
235 i = l->list[i].
lower;
238 if (l->list[i].
higher == 0) {
240 if (l->
free >= l->size) {
241 int newsize = l->size + INITIAL_SORTED_ENTRIES;
243 memset(l->list + l->size,
251 l->list[i].
val.l = *val;
lmprob_t bo_wt1
Unigram backoff weight.
listelem_alloc_t * le
List element allocator for tginfo.
SPHINXBASE_EXPORT int32 ngram_ng_prob(ngram_model_t *model, int32 wid, int32 *history, int32 n_hist, int32 *n_used)
Quick "raw" probability lookup for a general N-Gram.
int32 log_uniform
Log of uniform (0-gram) probability.
#define ckd_calloc(n, sz)
Macros to simplify the use of above functions.
lmprob_t val
value being kept in this node
char ** word_str
Unigram names.
Sphinx's memory allocation/deallocation routines.
int32 log_uniform_weight
Log of uniform weight (i.e.
lmprob_t * prob2
Table of actual bigram probs.
SPHINXBASE_EXPORT int logmath_log(logmath_t *lmath, float64 p)
Convert linear floating point number to integer log in base B.
int32 * n_counts
Counts for 1, 2, 3, ...
SPHINXBASE_EXPORT void ckd_free(void *ptr)
Test and free a 1-D array.
int32 bigrams
Index of 1st entry in lm_t.bigrams[].
int32 n_bo_wt2
bo_wt2 size
int32 n_1g_alloc
Number of allocated word strings (for new word addition)
lmprob_t * prob3
Table of actual trigram probs.
Trigram information cache.
Common internal structure for Sphinx 3-gram models.
Fast memory allocator for uniformly sized objects.
uint8 n
This is an n-gram model (1, 2, 3, ...).
Implementation of logging routines.
logmath_t * lmath
Log-math object.
uint32 lower
index of another entry.
int32 log_uw
Log of unigram weight.
lmprob_t prob1
Unigram probability.
lmprob_t * bo_wt2
Table of actual bigram backoff weights.
SPHINXBASE_EXPORT listelem_alloc_t * listelem_alloc_init(size_t elemsize)
Initialize and return a list element allocator.
float32 lw
Language model scaling factor.
Bigram probs and bo-wts, and trigram probs are kept in separate tables rather than within the bigram_...
Common implementation of ngram_model_t.
Type used to store language model probabilities.
int32 free
first free element in list
#define ckd_realloc(ptr, sz)
Macro for ckd_realloc
tginfo_t ** tginfo
tginfo[lw2] is head of linked list of trigram information for some cached subset of bigrams (*...
int32 log_wip
Log of word insertion penalty.
SPHINXBASE_EXPORT int logmath_add(logmath_t *lmath, int logb_p, int logb_q)
Add two values in log space (i.e.
SPHINXBASE_EXPORT void listelem_alloc_free(listelem_alloc_t *le)
Finalize and release all memory associated with a list element allocator.
uint32 higher
index of another entry.