1

我正在使用TensorFlow 中的 Seq2Seq 示例。我可以运行训练并查看开发集上的困惑输出。这很棒!

我只想scalar_summary在事件文件中添加摘要(尤其是开发集上的困惑)并在 TensorBoard 中监控它们。阅读文档后,我不明白如何translate.py使用摘要操作进行注释。

任何人都可以用简单的伪代码帮助我吗?

4

1 回答 1

3

看起来translate.py根本没有创建 TensorBoard 摘要日志。(部分原因可能是大部分评估发生在 Python 中,而不是在 TensorFlow 图中。)让我们看看如何添加一个。

  1. 您需要创建一个tf.train.SummaryWriter. 在进入训练循环之前添加以下内容(此处):

    summary_writer = tf.train.SummaryWriter("path/to/logs", sess.graph_def)
    
  2. 您需要为每个存储桶中的困惑创建摘要事件。这些值是在 Python 中计算的,因此您不能使用通常的tf.scalar_summary()操作。相反,您将tf.Summary通过修改此循环直接创建一个:

    perplexity_summary = tf.Summary()
    
    # Run evals on development set and print their perplexity.
    for bucket_id in xrange(len(_buckets)):
      encoder_inputs, decoder_inputs, target_weights = model.get_batch(
          dev_set, bucket_id)
      _, eval_loss, _ = model.step(sess, encoder_inputs, decoder_inputs,
                                   target_weights, bucket_id, True)
      eval_ppx = math.exp(eval_loss) if eval_loss < 300 else float('inf')
      print("  eval: bucket %d perplexity %.2f" % (bucket_id, eval_ppx))
    
      bucket_value = perplexity_summary.value.add()
      bucket_value.tag = "peplexity_bucket)%d" % bucket_id
      bucket_value.simple_value = eval_ppx
    
    summary_writer.add_summary(perplexity_summary, model.global_step.eval())
    
  3. 您可以通过自己构造tf.Summary值并调用来添加其他指标summary_writer.add_summary()

于 2016-03-12T21:00:39.667 回答