|TensorFlow 1 version||View source on GitHub|
Represents a ragged tensor.
Compat aliases for migration
See Migration guide for more details.
tf.RaggedTensor( values, row_partition, internal=False )
Used in the notebooks
|Used in the guide||Used in the tutorials|
RaggedTensor is a tensor with one or more ragged dimensions, which are
dimensions whose slices may have different lengths. For example, the inner
(column) dimension of
rt=[[3, 1, 4, 1], , [5, 9, 2], , ] is ragged,
since the column slices (
rt[0, :], ...,
rt[4, :]) have different lengths.
Dimensions whose slices all have the same length are called uniform
dimensions. The outermost dimension of a
RaggedTensor is always uniform,
since it consists of a single slice (and so there is no possibility for
differing slice lengths).
The total number of dimensions in a
RaggedTensor is called its rank,
and the number of ragged dimensions in a
RaggedTensor is called its
RaggedTensor's ragged-rank is fixed at graph creation
time: it can't depend on the runtime values of
Tensors, and can't vary
dynamically for different session runs.
Potentially Ragged Tensors
Many ops support both
RaggedTensors. The term "potentially
ragged tensor" may be used to refer to a tensor that might be either a
Tensor or a
RaggedTensor. The ragged-rank of a
Tensor is zero.
Documenting RaggedTensor Shapes
When documenting the shape of a RaggedTensor, ragged dimensions can be
indicated by enclosing them in parentheses. For example, the shape of
RaggedTensor that stores the fixed-size word embedding for each
word in a sentence, for each sentence in a batch, could be written as
[num_sentences, (num_words), embedding_size]. The parentheses around
(num_words) indicate that dimension is ragged, and that the length
of each element list in that dimension may vary for each item.
RaggedTensor consists of a concatenated list of values that
are partitioned into variable-length rows. In particular, each
valuestensor, which concatenates the variable-length rows into a flattened list. For example, the
[[3, 1, 4, 1], , [5, 9, 2], , ]is
[3, 1, 4, 1, 5, 9, 2, 6].
row_splitsvector, which indicates how those flattened values are divided into rows. In particular, the values for row
rt[i]are stored in the slice
values=[3, 1, 4, 1, 5, 9, 2, 6],
row_splits=[0, 4, 4, 7, 8, 8]))
<tf.RaggedTensor [[3, 1, 4, 1], , [5, 9, 2], , ]>
Alternative Row-Partitioning Schemes
In addition to
row_splits, ragged tensors provide support for five other
row_lengths: a vector with shape
[nrows], which specifies the length of each row.
value_rowidsis a vector with shape
[nvals], corresponding one-to-one with