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。那麼,你能告訴我另一種達到目標的方式嗎?謝謝。