TensorFlow 中的嵌套结构是什么?

What is a nested structure in TensorFlow?

查看 tf.data.Datasets 的文档,我发现经常提到 "nested structures"。那到底是什么意思呢?任何 Python 数据类型都可以被视为嵌套结构(例如,(1,3, (7,6, (0), 5))dict(k=dict(3), 7, None)还是专门指代 TensorFlow 数据类型?

为了社区的利益,在评论部分提供答案。

TensorFlow中的

Nested Structure一般是指包含张量值的tupledict,或其他嵌套结构。
典型的情况是一个数据集,其中每个元素都是一对 (x, y) 用于训练,但如果你有多个输入 ((x1, x2), y),你也可以有一个 dict {'x': x, 'y': y} 或一个嵌套元组。 =23=] 为了方便起见,数据集允许您在其中包含张量结构。
请参阅 tf.data 指南的 Dataset structure

目前支持的结构类型有tupledictnamedtuple

来自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.