import tensorflow as tf

  """Trains model on train_data using optimizer."""

  tf.train.get_or_create_global_step()

  def model_loss(labels, chars, sequence_length):
    predictions = model((chars, sequence_length), training=True)
    loss_value = loss(labels, predictions)
    tf.contrib.summary.scalar("loss", loss_value)
    return loss_value

  for (batch, (labels, chars, sequence_length)) in enumerate(
      tfe.Iterator(train_data)):
    with tf.contrib.summary.record_summaries_every_n_global_steps(log_interval):
      batch_model_loss = functools.partial(model_loss, labels, chars,
