Reputation: 843
Going over the documentation for tf.data.Datasets, I see that there is a frequent mention of "nested structures". What exactly is meant by that? Can any Python data type be considered a nested structure (e.g., (1,3, (7,6, (0), 5))
or dict(k=dict(3), 7, None
) or does this specifically refer to TensorFlow data types?
Upvotes: 4
Views: 3293
Reputation: 1273
The currently-supported types of structure are tuple
, dict
, and namedtuple
.
From https://www.tensorflow.org/api_docs/python/tf/data/Dataset:
Common Terms: Element: A single output from calling next() on a dataset iterator. Elements may be nested structures containing multiple components. For example, the element (1, (3, "apple")) has one tuple nested in another tuple. The components are 1, 3, and "apple". Component: The leaf in the nested structure of an element.
Supported types: Elements can be nested structures of tuples, named tuples, and dictionaries. Element components can be of any type representable by tf.TypeSpec, including tf.Tensor, tf.data.Dataset, tf.SparseTensor, tf.RaggedTensor, and tf.TensorArray.
Upvotes: 2
Reputation:
Providing answer here from the comment section for the benefit of the community.
Nested Structure
in TensorFlow
generally refers to a tuple
or a dict
containing tensor values, or other nested structures.
The typical case is a dataset where each element is a (x, y)
pair for training, but you could also have a dict {'x': x, 'y': y}
, or a nested tuple if you have more than one input ((x1, x2), y)
.
Datasets allow you to have structures of tensors in them for convenience.
See Dataset structure of the guide on tf.data
.
Upvotes: 1