def obtain_stream(dataset, batch_size, size=1): if size == 1: data_stream = dataset.get_example_stream() data_stream = transformers.Batch(data_stream, iteration_scheme=schemes.ConstantScheme(batch_size)) # add padding and masks to the dataset data_stream = transformers.Padding(data_stream, mask_sources=('data')) return data_stream else: data_streams = [dataset.get_example_stream() for _ in xrange(size)] data_streams = [transformers.Batch(data_stream, iteration_scheme=schemes.ConstantScheme(batch_size)) for data_stream in data_streams] data_streams = [transformers.Padding(data_stream, mask_sources=('data')) for data_stream in data_streams] return data_streams
def output_stream(dataset, batch_size, size=1): data_stream = dataset.get_example_stream() data_stream = transformers.Batch(data_stream, iteration_scheme=schemes.ConstantScheme(batch_size)) # add padding and masks to the dataset data_stream = transformers.Padding(data_stream, mask_sources=('source', 'target', 'target_c')) return data_stream