def convert_instance_to_tf_example(tokenizer, instance, max_seq_length):
  """Convert instance object to TFExample.

  Args:
      tokenizer: instance of language.bert.tokenization.Tokenizer
      instance: TrainingInstance object
      max_seq_length: max number of tokens for fixed size model input

  Returns:
      A tuple containing a tfexample of the instance and the features used to
      create the tfexample in a dictionary
  """

  input_ids = tokenizer.convert_tokens_to_ids(instance.tokens)
  input_mask = [1] * len(input_ids)
  segment_ids = list(instance.segment_ids)
  assert len(input_ids) <= max_seq_length

  while len(input_ids) < max_seq_length:
    input_ids.append(0)
    input_mask.append(0)
    segment_ids.append(0)
  assert len(input_ids) == max_seq_length
  assert len(input_mask) == max_seq_length
  assert len(segment_ids) == max_seq_length

  features = collections.OrderedDict()
  features["input_ids"] = create_int_feature(input_ids)
  features["input_mask"] = create_int_feature(input_mask)
  features["segment_ids"] = create_int_feature(segment_ids)

  # These are not needed but are made to fit the BERT api
  masked_lm_positions = [0] * max_seq_length
  masked_lm_ids = [0] * max_seq_length
  masked_lm_weights = [1.0] * len(masked_lm_ids)
  features["masked_lm_positions"] = create_int_feature(masked_lm_positions)
  features["masked_lm_ids"] = create_int_feature(masked_lm_ids)
  features["masked_lm_weights"] = create_float_feature(masked_lm_weights)
  if isinstance(instance.label, list):
    features["order"] = create_int_feature(instance.label)
  else:
    features["next_sentence_labels"] = create_int_feature([instance.label])

  tf_example = tf.train.Example(features=tf.train.Features(feature=features))
  return tf_example, features
Convert instance object to TFExample.

  Args:
      tokenizer: instance of language.bert.tokenization.Tokenizer
      instance: TrainingInstance object
      max_seq_length: max number of tokens for fixed size model input

  Returns:
      A tuple containing a tfexample of the instance and the features used to
      create the tfexample in a dictionary
  
language/conpono/create_pretrain_data/preprocessing_utils.py