From e7568dbb9e48bad396844a18d45577cf576bd5d6 Mon Sep 17 00:00:00 2001 From: Thomas Hagebols Date: Wed, 17 Apr 2019 21:01:07 +0200 Subject: [PATCH 1/6] updated zip example --- tensorflow/python/data/ops/dataset_ops.py | 24 +++++++++++------------ 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/tensorflow/python/data/ops/dataset_ops.py b/tensorflow/python/data/ops/dataset_ops.py index 2b20fccf393bb4..0095f564256b48 100644 --- a/tensorflow/python/data/ops/dataset_ops.py +++ b/tensorflow/python/data/ops/dataset_ops.py @@ -566,27 +566,25 @@ def zip(datasets): For example: ```python - # NOTE: The following examples use `{ ... }` to represent the - # contents of a dataset. - a = { 1, 2, 3 } - b = { 4, 5, 6 } - c = { (7, 8), (9, 10), (11, 12) } - d = { 13, 14 } + a = Dataset.range(1, 4) # [ 1, 2, 3 ] + b = Dataset.range(4, 7) # [ 4, 5, 6 ] + c = Dataset.from_tensor_slices(tf.reshape(tf.range(7,13), (3,2))) # [ [7, 8], [9, 10], [11, 12] ] + d = Dataset.range(13, 15) # [ 13, 14 ] # The nested structure of the `datasets` argument determines the # structure of elements in the resulting dataset. - Dataset.zip((a, b)) == { (1, 4), (2, 5), (3, 6) } - Dataset.zip((b, a)) == { (4, 1), (5, 2), (6, 3) } + Dataset.zip((a, b)) # ==> [ (1, 4), (2, 5), (3, 6) ] + Dataset.zip((b, a)) # ==> [ (4, 1), (5, 2), (6, 3) ] # The `datasets` argument may contain an arbitrary number of # datasets. - Dataset.zip((a, b, c)) == { (1, 4, (7, 8)), - (2, 5, (9, 10)), - (3, 6, (11, 12)) } - + Dataset.zip((a, b, c)) # ==> [ (1, 4, [7, 8]), + # (2, 5, [9, 10]), + # (3, 6, [11, 12]) ] + # The number of elements in the resulting dataset is the same as # the size of the smallest dataset in `datasets`. - Dataset.zip((a, d)) == { (1, 13), (2, 14) } + Dataset.zip((a, d)) # ==> [ (1, 13), (2, 14) ] ``` Args: From b40f0781b86d7f136f9fb06920c88452de21482a Mon Sep 17 00:00:00 2001 From: Thomas Hagebols Date: Wed, 17 Apr 2019 22:09:19 +0200 Subject: [PATCH 2/6] updated concatenate example + fix for zip example --- tensorflow/python/data/ops/dataset_ops.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tensorflow/python/data/ops/dataset_ops.py b/tensorflow/python/data/ops/dataset_ops.py index 0095f564256b48..8a9761569b8d05 100644 --- a/tensorflow/python/data/ops/dataset_ops.py +++ b/tensorflow/python/data/ops/dataset_ops.py @@ -568,7 +568,7 @@ def zip(datasets): ```python a = Dataset.range(1, 4) # [ 1, 2, 3 ] b = Dataset.range(4, 7) # [ 4, 5, 6 ] - c = Dataset.from_tensor_slices(tf.reshape(tf.range(7,13), (3,2))) # [ [7, 8], [9, 10], [11, 12] ] + c = Dataset.from_tensor_slices([[7, 8], [9, 10], [11, 12]]) d = Dataset.range(13, 15) # [ 13, 14 ] # The nested structure of the `datasets` argument determines the @@ -599,18 +599,16 @@ def concatenate(self, dataset): """Creates a `Dataset` by concatenating given dataset with this dataset. ```python - # NOTE: The following examples use `{ ... }` to represent the - # contents of a dataset. - a = { 1, 2, 3 } - b = { 4, 5, 6, 7 } + a = Dataset.range(1, 4) # [ 1, 2, 3 ] + b = Dataset.range(4, 8) # [ 4, 5, 6, 7 ] # Input dataset and dataset to be concatenated should have same # nested structures and output types. - # c = { (8, 9), (10, 11), (12, 13) } - # d = { 14.0, 15.0, 16.0 } + # c = Dataset.from_tensor_slices([[8, 9], [10, 11], [12, 13]]) + # d = Dataset.from_tensor_slices([14.0, 15.0, 16.0]) # a.concatenate(c) and a.concatenate(d) would result in error. - a.concatenate(b) == { 1, 2, 3, 4, 5, 6, 7 } + a.concatenate(b) # ==> [ 1, 2, 3, 4, 5, 6, 7 ] ``` Args: From 719de5e481c8e2d01f69cff0187e1ae30d477fac Mon Sep 17 00:00:00 2001 From: Thomas Hagebols Date: Wed, 17 Apr 2019 22:37:52 +0200 Subject: [PATCH 3/6] updated interleave doc example --- tensorflow/python/data/ops/dataset_ops.py | 26 ++++++++++------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/tensorflow/python/data/ops/dataset_ops.py b/tensorflow/python/data/ops/dataset_ops.py index 8a9761569b8d05..1bfbb851a7224f 100644 --- a/tensorflow/python/data/ops/dataset_ops.py +++ b/tensorflow/python/data/ops/dataset_ops.py @@ -1084,24 +1084,20 @@ def interleave(self, For example: ```python - # NOTE: The following examples use `{ ... }` to represent the - # contents of a dataset. - a = { 1, 2, 3, 4, 5 } + a = Dataset.range(1, 6) # [ 1, 2, 3, 4, 5 ] # NOTE: New lines indicate "block" boundaries. a.interleave(lambda x: Dataset.from_tensors(x).repeat(6), - cycle_length=2, block_length=4) == { - 1, 1, 1, 1, - 2, 2, 2, 2, - 1, 1, - 2, 2, - 3, 3, 3, 3, - 4, 4, 4, 4, - 3, 3, - 4, 4, - 5, 5, 5, 5, - 5, 5, - } + cycle_length=2, block_length=4) # ==> [1, 1, 1, 1, + # 2, 2, 2, 2, + # 1, 1, + # 2, 2, + # 3, 3, 3, 3, + # 4, 4, 4, 4, + # 3, 3, + # 4, 4, + # 5, 5, 5, 5, + # 5, 5] ``` NOTE: The order of elements yielded by this transformation is From e8712d4f48f2797579deb1fb8471d89ed89ddcd9 Mon Sep 17 00:00:00 2001 From: Thomas Hagebols Date: Wed, 17 Apr 2019 23:24:17 +0200 Subject: [PATCH 4/6] updated map doc example --- tensorflow/python/data/ops/dataset_ops.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tensorflow/python/data/ops/dataset_ops.py b/tensorflow/python/data/ops/dataset_ops.py index 1bfbb851a7224f..0338aef1475a70 100644 --- a/tensorflow/python/data/ops/dataset_ops.py +++ b/tensorflow/python/data/ops/dataset_ops.py @@ -932,17 +932,17 @@ def map(self, map_func, num_parallel_calls=None): For example: ```python - # NOTE: The following examples use `{ ... }` to represent the - # contents of a dataset. - a = { 1, 2, 3, 4, 5 } + a = Dataset.range(1, 6) # [ 1, 2, 3, 4, 5 ] - a.map(lambda x: x + 1) = { 2, 3, 4, 5, 6 } + a.map(lambda x: x + 1) # ==> [ 2, 3, 4, 5, 6 ] ``` The input signature of `map_func` is determined by the structure of each element in this dataset. For example: ```python + # NOTE: The following examples use `{ ... }` to represent the + # contents of a dataset. # Each element is a `tf.Tensor` object. a = { 1, 2, 3, 4, 5 } # `map_func` takes a single argument of type `tf.Tensor` with the same From e7a8c54b4f324bc0c55809009e360f89c79feefe Mon Sep 17 00:00:00 2001 From: Thomas Hagebols Date: Wed, 17 Apr 2019 23:44:59 +0200 Subject: [PATCH 5/6] Updated flat_map doc example --- tensorflow/python/data/ops/dataset_ops.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tensorflow/python/data/ops/dataset_ops.py b/tensorflow/python/data/ops/dataset_ops.py index 0338aef1475a70..c31b3d16759c79 100644 --- a/tensorflow/python/data/ops/dataset_ops.py +++ b/tensorflow/python/data/ops/dataset_ops.py @@ -1028,12 +1028,10 @@ def flat_map(self, map_func): dataset of their elements: ```python - # NOTE: The following examples use `{ ... }` to represent the - # contents of a dataset. '[...]' represents a tensor. - a = {[1,2,3,4,5], [6,7,8,9], [10]} + a = Dataset.from_tensor_slices([ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]) - a.flat_map(lambda x: Dataset.from_tensor_slices(x)) == - {[1,2,3,4,5,6,7,8,9,10]} + a.flat_map(lambda x: Dataset.from_tensor_slices(x + 1)) # ==> + # [ 2, 3, 4, 5, 6, 7, 8, 9, 10 ] ``` `tf.data.Dataset.interleave()` is a generalization of `flat_map`, since From e4d040636ade8d91af6a70ad66643b899bc745be Mon Sep 17 00:00:00 2001 From: Thomas Hagebols Date: Thu, 18 Apr 2019 19:12:38 +0200 Subject: [PATCH 6/6] fix code formatting (spacing+example) --- tensorflow/python/data/ops/dataset_ops.py | 50 +++++++++++------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/tensorflow/python/data/ops/dataset_ops.py b/tensorflow/python/data/ops/dataset_ops.py index c31b3d16759c79..d0908d296db1b2 100644 --- a/tensorflow/python/data/ops/dataset_ops.py +++ b/tensorflow/python/data/ops/dataset_ops.py @@ -566,22 +566,22 @@ def zip(datasets): For example: ```python - a = Dataset.range(1, 4) # [ 1, 2, 3 ] - b = Dataset.range(4, 7) # [ 4, 5, 6 ] - c = Dataset.from_tensor_slices([[7, 8], [9, 10], [11, 12]]) - d = Dataset.range(13, 15) # [ 13, 14 ] + a = Dataset.range(1, 4) # ==> [ 1, 2, 3 ] + b = Dataset.range(4, 7) # ==> [ 4, 5, 6 ] + c = Dataset.range(7, 13).batch(2) # ==> [ [7, 8], [9, 10], [11, 12] ] + d = Dataset.range(13, 15) # ==> [ 13, 14 ] # The nested structure of the `datasets` argument determines the # structure of elements in the resulting dataset. - Dataset.zip((a, b)) # ==> [ (1, 4), (2, 5), (3, 6) ] - Dataset.zip((b, a)) # ==> [ (4, 1), (5, 2), (6, 3) ] + Dataset.zip((a, b)) # ==> [ (1, 4), (2, 5), (3, 6) ] + Dataset.zip((b, a)) # ==> [ (4, 1), (5, 2), (6, 3) ] # The `datasets` argument may contain an arbitrary number of # datasets. Dataset.zip((a, b, c)) # ==> [ (1, 4, [7, 8]), # (2, 5, [9, 10]), # (3, 6, [11, 12]) ] - + # The number of elements in the resulting dataset is the same as # the size of the smallest dataset in `datasets`. Dataset.zip((a, d)) # ==> [ (1, 13), (2, 14) ] @@ -599,16 +599,16 @@ def concatenate(self, dataset): """Creates a `Dataset` by concatenating given dataset with this dataset. ```python - a = Dataset.range(1, 4) # [ 1, 2, 3 ] - b = Dataset.range(4, 8) # [ 4, 5, 6, 7 ] + a = Dataset.range(1, 4) # ==> [ 1, 2, 3 ] + b = Dataset.range(4, 8) # ==> [ 4, 5, 6, 7 ] # Input dataset and dataset to be concatenated should have same # nested structures and output types. - # c = Dataset.from_tensor_slices([[8, 9], [10, 11], [12, 13]]) + # c = Dataset.range(8, 14).batch(2) # ==> [ [8, 9], [10, 11], [12, 13] ] # d = Dataset.from_tensor_slices([14.0, 15.0, 16.0]) # a.concatenate(c) and a.concatenate(d) would result in error. - a.concatenate(b) # ==> [ 1, 2, 3, 4, 5, 6, 7 ] + a.concatenate(b) # ==> [ 1, 2, 3, 4, 5, 6, 7 ] ``` Args: @@ -932,7 +932,7 @@ def map(self, map_func, num_parallel_calls=None): For example: ```python - a = Dataset.range(1, 6) # [ 1, 2, 3, 4, 5 ] + a = Dataset.range(1, 6) # ==> [ 1, 2, 3, 4, 5 ] a.map(lambda x: x + 1) # ==> [ 2, 3, 4, 5, 6 ] ``` @@ -1082,20 +1082,20 @@ def interleave(self, For example: ```python - a = Dataset.range(1, 6) # [ 1, 2, 3, 4, 5 ] + a = Dataset.range(1, 6) # ==> [ 1, 2, 3, 4, 5 ] # NOTE: New lines indicate "block" boundaries. a.interleave(lambda x: Dataset.from_tensors(x).repeat(6), - cycle_length=2, block_length=4) # ==> [1, 1, 1, 1, - # 2, 2, 2, 2, - # 1, 1, - # 2, 2, - # 3, 3, 3, 3, - # 4, 4, 4, 4, - # 3, 3, - # 4, 4, - # 5, 5, 5, 5, - # 5, 5] + cycle_length=2, block_length=4) # ==> [1, 1, 1, 1, + # 2, 2, 2, 2, + # 1, 1, + # 2, 2, + # 3, 3, 3, 3, + # 4, 4, 4, 4, + # 3, 3, + # 4, 4, + # 5, 5, 5, 5, + # 5, 5] ``` NOTE: The order of elements yielded by this transformation is @@ -1133,13 +1133,13 @@ def filter(self, predicate): ```python d = tf.data.Dataset.from_tensor_slices([1, 2, 3]) - d = d.filter(lambda x: x < 3) # [1, 2] + d = d.filter(lambda x: x < 3) # ==> [1, 2] # `tf.math.equal(x, y)` is required for equality comparison def filter_fn(x): return tf.math.equal(x, 1) - d = d.filter(filter_fn) # [1] + d = d.filter(filter_fn) # ==> [1] ``` Args: