0

我尝试使用一个示例 LSTM,根据Tensorflow LSTM 示例进行训练。这个例子允许在整个测试集上获得困惑。但是我需要使用经过训练的模型分别对每个句子进行评分(获取 loglikes)(对 STT 解码器输出的假设进行评分)。我稍微修改了阅读器并使用了代码:

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。那么,你能告诉我实现目标的另一种方法吗?谢谢你。

4

1 回答 1

0

该模型似乎可以接受一批输入,默认情况下在所有情况下都设置为 20。您应该能够将大量句子提供给一个测试模型以获取所有句子的输出,而无需创建多个模型实例。这可能涉及对读者进行一些实验,您已经熟悉了。

于 2017-07-17T20:43:01.187 回答