code: def train_and_eval():
      """Train and Evaluate."""
  
      features, labels = load_libsvm_data(
          FLAGS.train_path, FLAGS.list_size
      )
      train_input_fn, train_hook = get_train_inputs(
          features, labels, FLAGS.train_batch_size
      )
  
      features_vali, labels_vali = load_libsvm_data(
          FLAGS.vali_path, FLAGS.list_size
      )
      vali_input_fn, vali_hook = get_eval_inputs(
          features_vali, labels_vali
      )
  
      features_test, labels_test = load_libsvm_data(
          FLAGS.test_path, FLAGS.list_size
      )
      test_input_fn, test_hook = get_eval_inputs(
          features_test, labels_test
      )
  
      optimizer = tf.compat.v1.train.AdagradOptimizer(
          learning_rate=FLAGS.learning_rate
      )
  
      def _train_op_fn(loss):
          """Defines train op used in ranking head."""
          update_ops = tf.compat.v1.get_collection(
              tf.compat.v1.GraphKeys.UPDATE_OPS
          )
          minimize_op = optimizer.minimize(
              loss=loss,
              global_step=tf.compat.v1.train.get_global_step(),
          )
          train_op = tf.group([minimize_op, update_ops])
          return train_op
  
      if _use_multi_head():
          primary_head = tfr.head.create_ranking_head(
              loss_fn=tfr.losses.make_loss_fn(FLAGS.loss),
              eval_metric_fns=get_eval_metric_fns(),
              train_op_fn=_train_op_fn,
              name=_PRIMARY_HEAD,
          )
          secondary_head = tfr.head.create_ranking_head(
              loss_fn=tfr.losses.make_loss_fn(FLAGS.secondary_loss),
              eval_metric_fns=get_eval_metric_fns(),
              train_op_fn=_train_op_fn,
              name=_SECONDARY_HEAD,
          )
          ranking_head = tfr.head.create_multi_ranking_head(
              [primary_head, secondary_head],
              [1.0, FLAGS.secondary_loss_weight],
          )
      else:
          ranking_head = tfr.head.create_ranking_head(
              loss_fn=tfr.losses.make_loss_fn(FLAGS.loss),
              eval_metric_fns=get_eval_metric_fns(),
              train_op_fn=_train_op_fn,
          )
  
      estimator = tf_estimator.Estimator(
          model_fn=tfr.model.make_groupwise_ranking_fn(
              group_score_fn=make_score_fn(),
              group_size=FLAGS.group_size,
              transform_fn=make_transform_fn(),
              ranking_head=ranking_head,
          ),
          config=tf_estimator.RunConfig(
              FLAGS.output_dir, save_checkpoints_steps=1000
          ),
      )
  
      train_spec = tf_estimator.TrainSpec(
          input_fn=train_input_fn,
          hooks=[train_hook],
          max_steps=FLAGS.num_train_steps,
      )
      # Export model to accept tf.Example when group_size = 1.
      if FLAGS.group_size == 1:
          vali_spec = tf_estimator.EvalSpec(
              input_fn=vali_input_fn,
              hooks=[vali_hook],
              steps=1,
              exporters=tf_estimator.LatestExporter(
                  "latest_exporter",
                  serving_input_receiver_fn=make_serving_input_fn(),
              ),
              start_delay_secs=0,
              throttle_secs=30,
          )
      else:
          vali_spec = tf_estimator.EvalSpec(
              input_fn=vali_input_fn,
              hooks=[vali_hook],
              steps=1,
              start_delay_secs=0,
              throttle_secs=30,
          )
  
      # Train and validate
      tf_estimator.train_and_evaluate(estimator, train_spec, vali_spec)
  
      # Evaluate on the test data.
      estimator.evaluate(input_fn=test_input_fn, hooks=[test_hook])
  
imports: from absl import flags
  import numpy
  import six
  import tensorflow
  from tensorflow import estimator
  import tensorflow_ranking
label_desc: Use image node_id 10 for calling a global function with example usage: train_and_eval() and returns: train_op