code: def file_based_convert_examples_to_features(
      examples,
      max_seq_length,
      tokenizer,
      output_file,
      label_length=1,
      do_mask=True,
      max_predictions_per_seq=10,
  ):
      """Convert a set of `InputExample`s to a TFRecord file."""
  
      writer = tf.python_io.TFRecordWriter(output_file)
  
      for ex_index, example in enumerate(examples):
          if ex_index % 10000 == 0:
              tf.logging.info(
                  "Writing example %d of %d" % (ex_index, len(examples))
              )
  
          feature = convert_single_example(
              ex_index,
              example,
              max_seq_length,
              tokenizer,
              label_length=label_length,
              do_mask=do_mask,
              max_predictions_per_seq=max_predictions_per_seq,
          )
  
          # Flatten here
          def create_int_feature(values):
              f = tf.train.Feature(
                  int64_list=tf.train.Int64List(value=list(values))
              )
              return f
  
          # We will have as input
          # [a0 a1 a2 a3]
          # [b0 b1 b2 b3]
          # seq_length is the last dimension
          def create_int_feature_flat(values):
              f = tf.train.Feature(
                  int64_list=tf.train.Int64List(
                      value=[v for x in values for v in x]
                  )
              )
              return f
  
          def create_float_feature_flat(values):
              f = tf.train.Feature(
                  float_list=tf.train.FloatList(
                      value=[v for x in values for v in x]
                  )
              )
              return f
  
          features = collections.OrderedDict()
          features["input_ids"] = create_int_feature_flat(
              feature.input_ids
          )
          features["input_mask"] = create_int_feature_flat(
              feature.input_mask
          )
          features["segment_ids"] = create_int_feature_flat(
              feature.segment_ids
          )
          if do_mask:
              features["masked_lm_positions"] = create_int_feature_flat(
                  feature.masked_lm_positions
              )
              features["masked_lm_ids"] = create_int_feature_flat(
                  feature.masked_lm_ids
              )
              features["masked_lm_weights"] = create_float_feature_flat(
                  feature.masked_lm_weights
              )
  
          features["label_ids"] = create_int_feature([feature.label_id])
          features["is_real_example"] = create_int_feature(
              [int(feature.is_real_example)]
          )
  
          tf_example = tf.train.Example(
              features=tf.train.Features(feature=features)
          )
          writer.write(tf_example.SerializeToString())
      writer.close()
  
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 8 for calling a global function with example usage: file_based_convert_examples_to_features(examples, max_seq_length, tokenizer, output_file, label_length, do_mask, max_predictions_per_seq) and returns: f, f, f