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_list = [
      tokenizer.convert_tokens_to_ids(tokens) for tokens in instance.tokens
  ]
  input_mask_list = [[1] * len(input_ids) for input_ids in input_ids_list]
  segment_ids_list = list(instance.segment_ids)

  for input_ids in input_ids_list:
    assert len(input_ids) <= max_seq_length

  features = collections.OrderedDict()
  for i in range(len(input_ids_list)):
    while len(input_ids_list[i]) < max_seq_length:
      input_ids_list[i].append(0)
      input_mask_list[i].append(0)
      segment_ids_list[i].append(0)
    assert len(input_ids_list[i]) == max_seq_length
    assert len(input_mask_list[i]) == max_seq_length
    assert len(segment_ids_list[i]) == max_seq_length

    features["input_ids" + str(i)] = create_int_feature(input_ids_list[i])
    features["input_mask" + str(i)] = create_int_feature(input_mask_list[i])
    features["segment_ids" + str(i)] = create_int_feature(segment_ids_list[i])

  # 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)

  features["labels"] = create_int_feature(instance.label)
  features["label_types"] = create_int_feature(instance.label_types)

  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/cpc/preproc/preprocessing_utils.py