code: def train_and_evaluate(
      working_dir,
      num_train_instances=NUM_TRAIN_INSTANCES,
      num_test_instances=NUM_TEST_INSTANCES,
  ):
      """Train the model on training data and evaluate on evaluation data.
  
      Args:
        working_dir: Directory to read transformed data and metadata from.
        num_train_instances: Number of instances in train set
        num_test_instances: Number of instances in test set
  
      Returns:
        The results from the estimator's 'evaluate' method
      """
      tf_transform_output = tft.TFTransformOutput(working_dir)
  
      run_config = tf_estimator.RunConfig()
  
      estimator = tf_estimator.LinearClassifier(
          feature_columns=get_feature_columns(tf_transform_output),
          config=run_config,
          loss_reduction=tf.losses.Reduction.SUM,
      )
  
      # Fit the model using the default optimizer.
      train_input_fn = _make_training_input_fn(
          tf_transform_output,
          os.path.join(
              working_dir, TRANSFORMED_TRAIN_DATA_FILEBASE + "*"
          ),
          batch_size=TRAIN_BATCH_SIZE,
      )
      estimator.train(
          input_fn=train_input_fn,
          max_steps=TRAIN_NUM_EPOCHS
          * num_train_instances
          / TRAIN_BATCH_SIZE,
      )
  
      # Evaluate model on eval dataset.
      eval_input_fn = _make_training_input_fn(
          tf_transform_output,
          os.path.join(
              working_dir, TRANSFORMED_TEST_DATA_FILEBASE + "*"
          ),
          batch_size=1,
      )
      result = estimator.evaluate(
          input_fn=eval_input_fn, steps=num_test_instances
      )
  
      # Export the model.
      serving_input_fn = _make_serving_input_fn(tf_transform_output)
      exported_model_dir = os.path.join(working_dir, EXPORTED_MODEL_DIR)
      estimator.export_saved_model(exported_model_dir, serving_input_fn)
  
      return result
  
file_path: transform/examples/sentiment_example.py
imports: import argparse
  import os
  import pprint
  import tempfile
  import apache_beam
  import tensorflow
  from tensorflow import estimator
  import tensorflow_transform
  import tensorflow_transform.beam
  from tfx_bsl.public import tfxio
label_desc: Use image node_id 8 for calling a global function with example usage: train_and_evaluate(working_dir, num_train_instances, num_test_instances) and returns: result