docs: def train(num_training_iterations, report_interval,
            reduce_learning_rate_interval):
    """Trains a deep LSTM model on the Tiny Shakespeare dataset."""
  
    # Build the computation graph.
    graph_tensors, dataset_train = build_graph(
        lstm_depth=FLAGS.lstm_depth, batch_size=FLAGS.batch_size,
        num_embedding=FLAGS.num_embedding, num_hidden=FLAGS.num_hidden,
        truncation_length=FLAGS.truncation_length,
        sample_length=FLAGS.sample_length, max_grad_norm=FLAGS.max_grad_norm,
        initial_learning_rate=FLAGS.learning_rate,
        reduce_learning_rate_multiplier=FLAGS.reduce_learning_rate_multiplier,
        optimizer_epsilon=FLAGS.optimizer_epsilon)
  
    # Configure a checkpoint saver.
    saver_hook = _configure_saver(FLAGS.checkpoint_dir,
                                  FLAGS.checkpoint_interval)
  
    # Train the network.
    with tf.train.SingularMonitoredSession(
        hooks=[saver_hook], checkpoint_dir=FLAGS.checkpoint_dir) as sess:
  
      start_iteration = sess.run(graph_tensors["global_step"])
  
      for train_iteration in range(start_iteration, num_training_iterations):
        if (train_iteration + 1) % report_interval == 0:
          train_loss_v, valid_loss_v, _ = sess.run(
              (graph_tensors["train_loss"],
               graph_tensors["valid_loss"],
               graph_tensors["train_step"]))
  
          train_generated_string_v = sess.run(
              graph_tensors["train_generated_string"])
  
          train_generated_string_human = dataset_train.to_human_readable(
              (train_generated_string_v, 0), indices=[0])
  
          tf.logging.info("%d: Training loss %f. Validation loss %f. Sample = %s",
                          train_iteration,
                          train_loss_v,
                          valid_loss_v,
                          train_generated_string_human)
        else:
          train_loss_v, _ = sess.run((graph_tensors["train_loss"],
                                      graph_tensors["train_step"]))
          tf.logging.info("%d: Training loss %f.", train_iteration, train_loss_v)
  
        if (train_iteration + 1) % reduce_learning_rate_interval == 0:
          sess.run(graph_tensors["reduce_learning_rate"])
          tf.logging.info("Reducing learning rate.")
  
      test_loss = sess.run(graph_tensors["test_loss"])
      tf.logging.info("Test loss %f", test_loss)