def main(model_dir, test_sentences_file, test_pos_file, out_file, beam_size):
model, params, hyper_params, all_s2i = load_model(model_dir)
if beam_size:
hyper_params['beam_size'] = beam_size
beam = BeamDecoder(params, all_s2i, hyper_params['beam_size'])
pos_tags = load_pos_tags(test_pos_file)
sentences = load_sentences(test_sentences_file)
test_data = zip(sentences, pos_tags)
word_count = 0
time_started = time()
with open(out_file, "w") as fh:
processed = 0
for word_seq, pos_seq in test_data:
word_count += len(word_seq)
predicted_conf, predicted_tree = beam.decode(word_seq, pos_seq)
processed += 1
print(predicted_tree.to_export(processed), file=fh)
if processed % 5 == 0:
print("processed %d"%processed, file=stderr)
stderr.flush()
time_ended = time()
sents_per_sec = len(sentences)/(time_ended-time_started)
words_per_sec = word_count/(time_ended-time_started)
print("sents/sec: %f words/sec: %f"%(sents_per_sec, words_per_sec), file=stderr)
评论列表
文章目录