code: def input_fn_builder(
      input_file, seq_length, is_training, drop_remainder
  ):
      """Creates an `input_fn` closure to be passed to TPUEstimator."""
  
      name_to_features = {
          "unique_ids": tf.FixedLenFeature([], tf.int64),
          "input_ids": tf.FixedLenFeature([seq_length], tf.int64),
          "input_mask": tf.FixedLenFeature([seq_length], tf.int64),
          "segment_ids": tf.FixedLenFeature([seq_length], tf.int64),
      }
  
      if is_training:
          name_to_features["start_positions"] = tf.FixedLenFeature(
              [], tf.int64
          )
          name_to_features["end_positions"] = tf.FixedLenFeature(
              [], tf.int64
          )
  
      def _decode_record(record, name_to_features):
          """Decodes a record to a TensorFlow example."""
          example = tf.parse_single_example(record, name_to_features)
  
          # tf.Example only supports tf.int64, but the TPU only supports tf.int32.
          # So cast all int64 to int32.
          for name in list(example.keys()):
              t = example[name]
              if t.dtype == tf.int64:
                  t = tf.to_int32(t)
              example[name] = t
  
          return example
  
      def input_fn(params):
          """The actual input function."""
          batch_size = params["batch_size"]
  
          # For training, we want a lot of parallel reading and shuffling.
          # For eval, we want no shuffling and parallel reading doesn't matter.
          d = tf.data.TFRecordDataset(input_file)
          if is_training:
              d = d.repeat()
              d = d.shuffle(buffer_size=100)
  
          d = d.apply(
              tf.data.experimental.map_and_batch(
                  lambda record: _decode_record(
                      record, name_to_features
                  ),
                  batch_size=batch_size,
                  drop_remainder=drop_remainder,
              )
          )
  
          return d
  
      return input_fn
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import json
  import math
  import os
  import random
  import mesh_tensorflow
  import mesh_tensorflow.bert.bert
  import mesh_tensorflow.bert.optimization
  import mesh_tensorflow.bert.tokenization
  import six
  from six.moves import range
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
label_desc: Use image node_id 7 for calling a global function with example usage: input_fn_builder(input_file, seq_length, is_training, drop_remainder) and returns: input_fn, example, d