Skip to content

Instantly share code, notes, and snippets.

@IlievskiV
Created March 27, 2019 09:49
Show Gist options
  • Save IlievskiV/2d8cc7c9e8f87589f9aa2a98e5e22b35 to your computer and use it in GitHub Desktop.
Save IlievskiV/2d8cc7c9e8f87589f9aa2a98e5e22b35 to your computer and use it in GitHub Desktop.
Load data using the TensorFlow Dataset API
import tensorflow as tf
def make_dataset():
sentences = ['The cat sat on the mat', 'The quick brown fox jumped over the lazy dog']
dataset = tf.data.Dataset.from_tensor_slices(sentences) #
dataset = dataset.shuffle(buffer_size=1000)
dataset = dataset.map(lambda sentence: text_to_sequence(sentence), num_parallel_calls=4)
dataset = dataset.batch(batch_size=32)
dataset = dataset.prefetch(1)
return dataset
def make_iterator():
train_dataset = make_dataset()
iterator = tf.data.Iterator.from_structure(output_types=train_dataset.output_types,
output_shapes=train_dataset.output_shapes)
training_init_op = iterator.make_initializer(train_dataset)
return iterator, training_init_op
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment