code: def file_based_input_fn_builder(
      input_file,
      seq_length,
      label_length,
      is_training,
      drop_remainder,
      max_predictions_per_seq=10,
      do_mask=True,
      buffer_size=100,
  ):
      """Creates an `input_fn` closure to be passed to TPUEstimator."""
  
      name_to_features = {
          "input_ids": tf.FixedLenFeature(
              [label_length, seq_length], tf.int64
          ),
          "input_mask": tf.FixedLenFeature(
              [label_length, seq_length], tf.int64
          ),
          "segment_ids": tf.FixedLenFeature(
              [label_length, seq_length], tf.int64
          ),
          "label_ids": tf.FixedLenFeature([], tf.int64),
          "is_real_example": tf.FixedLenFeature([], tf.int64),
      }
  
      if do_mask:
          name_to_features["masked_lm_positions"] = tf.FixedLenFeature(
              [label_length, max_predictions_per_seq], tf.int64
          )
          name_to_features["masked_lm_ids"] = tf.FixedLenFeature(
              [label_length, max_predictions_per_seq], tf.int64
          )
          name_to_features["masked_lm_weights"] = tf.FixedLenFeature(
              [label_length, max_predictions_per_seq], tf.float32
          )
  
      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=buffer_size)
  
          d = d.apply(
              tf.contrib.data.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: import collections
  import csv
  import os
  import zipfile
  import requests
  import tensorflow
  from adversarial_filtering.bert import modeling
  from adversarial_filtering.bert import tokenization
  import random
  import gcsfs
  import numpy
  from tensorflow.python.lib.io import file_io
label_desc: Use image node_id 9 for calling a global function with example usage: file_based_input_fn_builder(input_file, seq_length, label_length, is_training, drop_remainder, max_predictions_per_seq, do_mask, buffer_size) and returns: input_fn, example, d