code: def train_and_eval():
      """Trains and validates the Keras Model with the pipeline."""
      dataset_hparams = tfr.keras.pipeline.DatasetHparams(
          train_input_pattern=FLAGS.train_input_pattern,
          valid_input_pattern=FLAGS.valid_input_pattern,
          train_batch_size=FLAGS.train_batch_size,
          valid_batch_size=FLAGS.valid_batch_size,
          list_size=FLAGS.list_size,
          dataset_reader=tf.data.TFRecordDataset,
          convert_labels_to_binary=FLAGS.convert_labels_to_binary,
      )
      pipeline_hparams = tfr.keras.pipeline.PipelineHparams(
          model_dir=FLAGS.model_dir,
          num_epochs=FLAGS.num_epochs,
          steps_per_epoch=(FLAGS.num_train_steps // FLAGS.num_epochs),
          validation_steps=FLAGS.num_valid_steps,
          loss=FLAGS.loss,
          loss_reduction=tf.losses.Reduction.AUTO,
          optimizer=FLAGS.optimizer,
          learning_rate=FLAGS.learning_rate,
          steps_per_execution=FLAGS.steps_per_execution,
          export_best_model=FLAGS.export_best_model,
          strategy=FLAGS.strategy,
      )
  
      (
          context_feature_spec,
          example_feature_spec,
          label_spec,
      ) = _create_feature_spec()
  
      preprocess_dict = {}
      if FLAGS.use_log1p:
          preprocess_dict = {
              fname: lambda t: tf.math.log1p(t * tf.sign(t))
              * tf.sign(t)
              for fname in example_feature_spec.keys()
          }
  
      dnn_scorer = tfr.keras.model.DNNScorer(
          hidden_layer_dims=map(
              int, FLAGS.hidden_layer_dims.split(",")
          ),
          output_units=1,
          activation=tf.nn.relu,
          input_batch_norm=FLAGS.use_batch_norm,
          use_batch_norm=FLAGS.use_batch_norm,
          batch_norm_moment=FLAGS.batch_norm_moment,
          dropout=FLAGS.dropout,
      )
  
      model_builder = tfr.keras.model.ModelBuilder(
          input_creator=tfr.keras.model.FeatureSpecInputCreator(
              context_feature_spec, example_feature_spec
          ),
          preprocessor=tfr.keras.model.PreprocessorWithSpec(
              preprocess_dict
          ),
          scorer=dnn_scorer,
          mask_feature_name=_MASK,
          name="keras_dnn_model",
      )
  
      ranking_pipeline = tfr.keras.pipeline.SimplePipeline(
          model_builder=model_builder,
          dataset_builder=tfr.keras.pipeline.SimpleDatasetBuilder(
              context_feature_spec=context_feature_spec,
              example_feature_spec=example_feature_spec,
              mask_feature_name=_MASK,
              label_spec=label_spec,
              hparams=dataset_hparams,
          ),
          hparams=pipeline_hparams,
      )
  
      ranking_pipeline.train_and_validate()
  
file_path: ranking/tensorflow_ranking/examples/keras/keras_dnn_tfrecord.py
imports: from typing import Dict, Tuple
  from absl import app
  from absl import flags
  import tensorflow
  import tensorflow_ranking
label_desc: Use image node_id 2 for calling a global function with example usage: train_and_eval() without return types