code: def main():
      """Entrypoint."""
      train_data = tx.data.PairedTextData(hparams=config_data.train)
      val_data = tx.data.PairedTextData(hparams=config_data.val)
      test_data = tx.data.PairedTextData(hparams=config_data.test)
      data_iterator = tx.data.TrainTestDataIterator(
          train=train_data, val=val_data, test=test_data
      )
  
      batch = data_iterator.get_next()
  
      train_op, infer_outputs = build_model(batch, train_data)
  
      def _train_epoch(sess):
          data_iterator.switch_to_train_data(sess)
  
          step = 0
          while True:
              try:
                  loss = sess.run(train_op)
                  if step % config_data.display == 0:
                      print("step={}, loss={:.4f}".format(step, loss))
                  step += 1
              except tf.errors.OutOfRangeError:
                  break
  
      def _eval_epoch(sess, mode):
          if mode == "val":
              data_iterator.switch_to_val_data(sess)
          else:
              data_iterator.switch_to_test_data(sess)
  
          refs, hypos = [], []
          while True:
              try:
                  fetches = [
                      batch["target_text"][:, 1:],
                      infer_outputs.predicted_ids[:, :, 0],
                  ]
                  feed_dict = {
                      tx.global_mode(): tf.estimator.ModeKeys.EVAL
                  }
                  target_texts_ori, output_ids = sess.run(
                      fetches, feed_dict=feed_dict
                  )
  
                  target_texts = tx.utils.strip_special_tokens(
                      target_texts_ori, is_token_list=True
                  )
                  output_texts = tx.utils.map_ids_to_strs(
                      ids=output_ids, vocab=val_data.target_vocab
                  )
  
                  for hypo, ref in zip(output_texts, target_texts):
                      hypos.append(hypo)
                      refs.append([ref])
              except tf.errors.OutOfRangeError:
                  break
  
          return tx.evals.corpus_bleu_moses(
              list_of_references=refs, hypotheses=hypos
          )
  
      with tf.Session() as sess:
          sess.run(tf.global_variables_initializer())
          sess.run(tf.local_variables_initializer())
          sess.run(tf.tables_initializer())
  
          best_val_bleu = -1.0
          for i in range(config_data.num_epochs):
              _train_epoch(sess)
  
              val_bleu = _eval_epoch(sess, "val")
              best_val_bleu = max(best_val_bleu, val_bleu)
              print(
                  "val epoch={}, BLEU={:.4f}; best-ever={:.4f}".format(
                      i, val_bleu, best_val_bleu
                  )
              )
  
              test_bleu = _eval_epoch(sess, "test")
              print("test epoch={}, BLEU={:.4f}".format(i, test_bleu))
  
              print("=" * 50)
  
imports: import importlib
  import tensorflow
  import texar.tf
label_desc: Use image node_id 2 for calling a global function with example usage: main() and returns: tx