Skip to content

Instantly share code, notes, and snippets.

@chetanambi
Created August 4, 2020 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chetanambi/cc70502b89e72ef54c57ff9032885b4d to your computer and use it in GitHub Desktop.
Save chetanambi/cc70502b89e72ef54c57ff9032885b4d to your computer and use it in GitHub Desktop.
tfrecord
import pandas as pd
import tensorflow as tf
input_dict = dict(
inputs=[inp],
targets=[""]
)
save_path = "pegasus/data/testdata/test_pattern_1.tfrecord"
data = pd.DataFrame(input_dict)
with tf.io.TFRecordWriter(save_path) as writer:
for row in data.values:
inputs, targets = row[:-1], row[-1]
example = tf.train.Example(
features=tf.train.Features(
feature={
"inputs": tf.train.Feature(bytes_list=tf.train.BytesList(value=[inputs[0].encode('utf-8')])),
"targets": tf.train.Feature(bytes_list=tf.train.BytesList(value=[targets.encode('utf-8')])),
}
)
)
writer.write(example.SerializeToString())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment