-
-
Save TheodoreGalanos/b66344605f42344e95e86077ef9c48fb to your computer and use it in GitHub Desktop.
A quick script for shuffling tfrecord datasets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
from tqdm import tqdm | |
index = open("data/openwebtext2_new_inputs.train.index").read().splitlines() | |
dataset = tf.data.Dataset.from_tensor_slices(index) | |
dataset = dataset.interleave(tf.data.TFRecordDataset, cycle_length=128, num_parallel_calls=tf.data.experimental.AUTOTUNE) | |
d = dataset.shuffle(10000).prefetch(100) | |
i = 0 | |
for idx, example in enumerate(tqdm(d)): | |
if idx % 100000 == 0: | |
try: | |
writer.close() | |
except: | |
pass | |
writer = tf.io.TFRecordWriter(f"gs://neo-datasets/openwebtext2_new_inputs_shuffled/train/openwebtext_{i}.tfrecords") | |
i += 1 | |
writer.write(example.numpy()) | |
writer.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment