Merge pull request #2391 from mozilla/optional-lm-test

Make language model scoring optional in Python inference code
This commit is contained in:
Reuben Morais 2019-09-30 13:35:26 +02:00 committed by GitHub
commit d0a578221d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 14 deletions

View File

@ -870,9 +870,12 @@ def do_single_file_inference(input_file_path):
logits = np.squeeze(logits)
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])

View File

@ -42,9 +42,12 @@ def sparse_tuple_to_texts(sp_tuple, alphabet):
def evaluate(test_csvs, create_model, try_loading):
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]

View File

@ -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.')