Merge pull request #2391 from mozilla/optional-lm-test
Make language model scoring optional in Python inference code
This commit is contained in:
commit
d0a578221d
|
@ -870,9 +870,12 @@ def do_single_file_inference(input_file_path):
|
|||
|
||||
logits = np.squeeze(logits)
|
||||
|
||||
scorer = Scorer(FLAGS.lm_alpha, FLAGS.lm_beta,
|
||||
FLAGS.lm_binary_path, FLAGS.lm_trie_path,
|
||||
Config.alphabet)
|
||||
if FLAGS.lm_binary_path:
|
||||
scorer = Scorer(FLAGS.lm_alpha, FLAGS.lm_beta,
|
||||
FLAGS.lm_binary_path, FLAGS.lm_trie_path,
|
||||
Config.alphabet)
|
||||
else:
|
||||
scorer = None
|
||||
decoded = ctc_beam_search_decoder(logits, Config.alphabet, FLAGS.beam_width, scorer=scorer)
|
||||
# Print highest probability result
|
||||
print(decoded[0][1])
|
||||
|
|
|
@ -42,9 +42,12 @@ def sparse_tuple_to_texts(sp_tuple, alphabet):
|
|||
|
||||
|
||||
def evaluate(test_csvs, create_model, try_loading):
|
||||
scorer = Scorer(FLAGS.lm_alpha, FLAGS.lm_beta,
|
||||
FLAGS.lm_binary_path, FLAGS.lm_trie_path,
|
||||
Config.alphabet)
|
||||
if FLAGS.lm_binary_path:
|
||||
scorer = Scorer(FLAGS.lm_alpha, FLAGS.lm_beta,
|
||||
FLAGS.lm_binary_path, FLAGS.lm_trie_path,
|
||||
Config.alphabet)
|
||||
else:
|
||||
scorer = None
|
||||
|
||||
test_csvs = FLAGS.test_files.split(',')
|
||||
test_sets = [create_dataset([csv], batch_size=FLAGS.test_batch_size, train_phase=False) for csv in test_csvs]
|
||||
|
|
|
@ -143,14 +143,6 @@ def create_flags():
|
|||
|
||||
# Register validators for paths which require a file to be specified
|
||||
|
||||
f.register_validator('lm_binary_path',
|
||||
os.path.isfile,
|
||||
message='The file pointed to by --lm_binary_path must exist and be readable.')
|
||||
|
||||
f.register_validator('lm_trie_path',
|
||||
os.path.isfile,
|
||||
message='The file pointed to by --lm_trie_path must exist and be readable.')
|
||||
|
||||
f.register_validator('alphabet_config_path',
|
||||
os.path.isfile,
|
||||
message='The file pointed to by --alphabet_config_path must exist and be readable.')
|
||||
|
|
Loading…
Reference in New Issue