(
        examples, label_list, max_seq_length, tokenizer, output_file, num_passes=1)
Convert a set of `InputExample`s to a TFRecord file.
Convert a set of `InputExample`s to a TFRecord file.
Convert a set of InputExample s to a TFRecord file .
def file_based_convert_examples_to_features_for_inews(
        examples, label_list, max_seq_length, tokenizer, output_file, num_passes=1):
  """Convert a set of `InputExample`s to a TFRecord file."""

  writer = tf.python_io.TFRecordWriter(output_file)
  num_example = 0
  if num_passes > 1:
    examples *= num_passes

  for (ex_index, example) in enumerate(examples):
    if ex_index % 1000 == 0:
      tf.logging.info("Writing example %d of %d" % (ex_index, len(examples)))

    feature_list = convert_example_list_for_inews(ex_index, example, label_list,
                                                  max_seq_length, tokenizer)
    num_example += len(feature_list)

    def create_int_feature(values):
      f = tf.train.Feature(int64_list=tf.train.Int64List(value=list(values)))
      return f

    features = collections.OrderedDict()
    for feature in feature_list:
      features["input_ids"] = create_int_feature(feature.input_ids)
      features["input_mask"] = create_int_feature(feature.input_mask)
      features["segment_ids"] = create_int_feature(feature.segment_ids)
      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())
  tf.logging.info("feature num: %s", num_example)
  writer.close()
def file_based_convert_examples_to_features_for_inews ( examples , label_list , max_seq_length , tokenizer , output_file , num_passes = 1 ) : writer = tf . python_io . TFRecordWriter ( output_file ) num_example = 0 if num_passes > 1 : examples *= num_passes for ( ex_index , example ) in enumerate ( examples ) : if ex_index % 1000 == 0 : tf . logging . info ( "Writing example %d of %d" % ( ex_index , len ( examples ) ) ) feature_list = convert_example_list_for_inews ( ex_index , example , label_list , max_seq_length , tokenizer ) num_example += len ( feature_list ) def create_int_feature ( values ) : f = tf . train . Feature ( int64_list = tf . train . Int64List ( value = list ( values ) ) ) return f features = collections . OrderedDict ( ) for feature in feature_list : features [ "input_ids" ] = create_int_feature ( feature . input_ids ) features [ "input_mask" ] = create_int_feature ( feature . input_mask ) features [ "segment_ids" ] = create_int_feature ( feature . segment_ids ) 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 ( ) ) tf . logging . info ( "feature num: %s" , num_example ) writer . close ( )