0
我尝试使用示例LSTM,根据Tensorflow LSTM example进行了培训。这个例子可以让整个测试集都很困惑。但我需要使用训练好的模型分别对每个句子进行评分(得到loglikes)(评分STT解码器输出的假设)。我修改reader一点,并使用代码:使用Tensorflow LSTM PTB示例对句子进行评分
mtests=list()
with tf.name_scope("Test"):
for test_data_item in test_data:
test_input.append(PTBInput(config=eval_config, data=test_data_item, name="TestInput"))
with tf.variable_scope("Model", reuse=True, initializer=initializer):
for test_input_item in test_input:
mtests.append(PTBModel(is_training=False, config=eval_config,
input_=test_input_item))
sv = tf.train.Supervisor(logdir=FLAGS.model_dir)
with sv.managed_session() as session:
checkpoint=tf.train.latest_checkpoint(FLAGS.model_dir)
sv.saver.restore(session, checkpoint)
sys.stderr.write("model restored\n")
for mtest in mtests:
score, test_perplexity = run_epoch_test(session, mtest)
print(score)
因此,使用这些代码,我得到独立每个句子的得分。如果我通过5个句子,它可以正常工作。但是,如果我将1k句子传递给此代码,它工作起来非常缓慢并且使用了大量内存,因为我创建了1k模型mtest。那么,你能告诉我另一种达到目标的方式吗?谢谢。