Skip to content

Commit db5d1b6

Browse files
authored
Merge pull request #420 from cmusphinx/kal-ps-lm-convert
Fix pocketsphinx_lm_convert failing due to missing lw/wip parameters
2 parents 03b3847 + 20a4dcb commit db5d1b6

3 files changed

Lines changed: 65 additions & 2 deletions

File tree

src/lm/ngram_model.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,13 @@ ngram_model_read(cmd_ln_t * config,
165165
float32 lw = 1.0;
166166
float32 wip = 1.0;
167167

168-
lw = ps_config_float(config, "lw");
169-
wip = ps_config_float(config, "wip");
168+
/* Only read weights if they are defined in the config.
169+
* This allows tools like pocketsphinx_lm_convert to work
170+
* without defining these decoder-specific parameters. */
171+
if (ps_config_typeof(config, "lw"))
172+
lw = ps_config_float(config, "lw");
173+
if (ps_config_typeof(config, "wip"))
174+
wip = ps_config_float(config, "wip");
170175

171176
ngram_model_apply_weights(model, lw, wip);
172177
}

test/unit/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ set(TESTS
1616
test_jsgf
1717
test_keyphrase
1818
test_lattice
19+
test_lm_convert
1920
test_ngram_model_read
2021
test_log_shifted
2122
test_log_int8

test/unit/test_lm_convert.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */
2+
/**
3+
* Test that pocketsphinx_lm_convert works without lw/wip parameters
4+
*/
5+
6+
#include <stdio.h>
7+
#include <string.h>
8+
#include <stdlib.h>
9+
10+
#include <pocketsphinx.h>
11+
#include "util/cmd_ln.h"
12+
#include "lm/ngram_model.h"
13+
14+
#include "test_macros.h"
15+
16+
static const ps_arg_t defn[] = {
17+
{ "logbase",
18+
ARG_FLOATING,
19+
"1.0001",
20+
"Base in which all log-likelihoods calculated" },
21+
{ "mmap",
22+
ARG_BOOLEAN,
23+
"no",
24+
"Use memory-mapped I/O for reading binary LM files"},
25+
{ NULL, 0, NULL, NULL }
26+
};
27+
28+
int
29+
main(int argc, char *argv[])
30+
{
31+
ps_config_t *config;
32+
ngram_model_t *lm;
33+
logmath_t *lmath;
34+
35+
(void)argc;
36+
(void)argv;
37+
38+
/* Create a minimal config without lw/wip parameters */
39+
config = ps_config_init(defn);
40+
TEST_ASSERT(config != NULL);
41+
42+
/* Create log math object */
43+
lmath = logmath_init(1.0001, 0, 0);
44+
TEST_ASSERT(lmath != NULL);
45+
46+
/* Try to read a language model - this should work without errors */
47+
lm = ngram_model_read(config, DATADIR "/turtle.lm.bin",
48+
NGRAM_AUTO, lmath);
49+
TEST_ASSERT(lm != NULL);
50+
51+
/* Clean up */
52+
ngram_model_free(lm);
53+
logmath_free(lmath);
54+
ps_config_free(config);
55+
56+
return 0;
57+
}

0 commit comments

Comments
 (0)