tf.RaggedTensorSpec
Stay organized with collections
Save and categorize content based on your preferences.
Type specification for a tf.RaggedTensor
.
Inherits From: TypeSpec
tf.RaggedTensorSpec(
shape=None,
dtype=tf.dtypes.float32
,
ragged_rank=None,
row_splits_dtype=tf.dtypes.int64
,
flat_values_spec=None
)
Args |
shape
|
The shape of the RaggedTensor, or None to allow any shape. If a
shape is specified, then all ragged dimensions must have size None .
|
dtype
|
tf.DType of values in the RaggedTensor.
|
ragged_rank
|
Python integer, the number of times the RaggedTensor's
flat_values is partitioned. Defaults to shape.ndims - 1 .
|
row_splits_dtype
|
dtype for the RaggedTensor's row_splits tensor. One
of tf.int32 or tf.int64 .
|
flat_values_spec
|
TypeSpec for flat_value of the RaggedTensor. It shall be
provided when the flat_values is a CompositeTensor rather then Tensor.
If both dtype and flat_values_spec and are provided, dtype must
be the same as flat_values_spec.dtype . (experimental)
|
Attributes |
dtype
|
The tf.dtypes.DType specified by this type for the RaggedTensor.
rt = tf.ragged.constant([["a"], ["b", "c"]], dtype=tf.string)
tf.type_spec_from_value(rt).dtype
tf.string
|
flat_values_spec
|
The TypeSpec of the flat_values of RaggedTensor.
|
ragged_rank
|
The number of times the RaggedTensor's flat_values is partitioned.
Defaults to shape.ndims - 1 .
values = tf.ragged.constant([[1, 2, 3], [4], [5, 6], [7, 8, 9, 10]])
tf.type_spec_from_value(values).ragged_rank
1
rt1 = tf.RaggedTensor.from_uniform_row_length(values, 2)
tf.type_spec_from_value(rt1).ragged_rank
2
|
row_splits_dtype
|
The tf.dtypes.DType of the RaggedTensor's row_splits .
rt = tf.ragged.constant([[1, 2, 3], [4]], row_splits_dtype=tf.int64)
tf.type_spec_from_value(rt).row_splits_dtype
tf.int64
|
shape
|
The statically known shape of the RaggedTensor.
rt = tf.ragged.constant([[0], [1, 2]])
tf.type_spec_from_value(rt).shape
TensorShape([2, None])
rt = tf.ragged.constant([[[0, 1]], [[1, 2], [3, 4]]], ragged_rank=1)
tf.type_spec_from_value(rt).shape
TensorShape([2, None, 2])
|
value_type
|
The Python type for values that are compatible with this TypeSpec.
In particular, all values that are compatible with this TypeSpec must be an
instance of this type.
|
Methods
from_value
View source
@classmethod
from_value(
value
)
is_compatible_with
View source
is_compatible_with(
spec_or_value
)
Returns true if spec_or_value
is compatible with this TypeSpec.
most_specific_compatible_type
View source
most_specific_compatible_type(
other: 'TypeSpec'
) -> 'TypeSpec'
Returns the most specific TypeSpec compatible with self
and other
.
Raises |
ValueError
|
If there is no TypeSpec that is compatible with both self
and other .
|
__eq__
View source
__eq__(
other
) -> bool
Return self==value.
__ne__
View source
__ne__(
other
) -> bool
Return self!=value.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2022-11-04 UTC.
[null,null,["Last updated 2022-11-04 UTC."],[],[],null,["# tf.RaggedTensorSpec\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.7.4/tensorflow/python/ops/ragged/ragged_tensor.py#L2281-L2598) |\n\nType specification for a [`tf.RaggedTensor`](../tf/RaggedTensor).\n\nInherits From: [`TypeSpec`](../tf/TypeSpec)\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.RaggedTensorSpec`](https://www.tensorflow.org/api_docs/python/tf/RaggedTensorSpec)\n\n\u003cbr /\u003e\n\n tf.RaggedTensorSpec(\n shape=None,\n dtype=../tf/dtypes#float32,\n ragged_rank=None,\n row_splits_dtype=../tf/dtypes#int64,\n flat_values_spec=None\n )\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `shape` | The shape of the RaggedTensor, or `None` to allow any shape. If a shape is specified, then all ragged dimensions must have size `None`. |\n| `dtype` | [`tf.DType`](../tf/dtypes/DType) of values in the RaggedTensor. |\n| `ragged_rank` | Python integer, the number of times the RaggedTensor's flat_values is partitioned. Defaults to `shape.ndims - 1`. |\n| `row_splits_dtype` | `dtype` for the RaggedTensor's `row_splits` tensor. One of [`tf.int32`](../tf#int32) or [`tf.int64`](../tf#int64). |\n| `flat_values_spec` | TypeSpec for flat_value of the RaggedTensor. It shall be provided when the flat_values is a CompositeTensor rather then Tensor. If both `dtype` and `flat_values_spec` and are provided, `dtype` must be the same as `flat_values_spec.dtype`. (experimental) |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|--------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `dtype` | The [`tf.dtypes.DType`](../tf/dtypes/DType) specified by this type for the RaggedTensor. \u003cbr /\u003e rt = tf.ragged.constant([[\"a\"], [\"b\", \"c\"]], dtype=tf.string) tf.type_spec_from_value(rt).dtype tf.string \u003cbr /\u003e |\n| `flat_values_spec` | The `TypeSpec` of the flat_values of RaggedTensor. |\n| `ragged_rank` | The number of times the RaggedTensor's flat_values is partitioned. \u003cbr /\u003e Defaults to `shape.ndims - 1`. values = tf.ragged.constant([[1, 2, 3], [4], [5, 6], [7, 8, 9, 10]]) tf.type_spec_from_value(values).ragged_rank 1 rt1 = tf.RaggedTensor.from_uniform_row_length(values, 2) tf.type_spec_from_value(rt1).ragged_rank 2 \u003cbr /\u003e |\n| `row_splits_dtype` | The [`tf.dtypes.DType`](../tf/dtypes/DType) of the RaggedTensor's `row_splits`. \u003cbr /\u003e rt = tf.ragged.constant([[1, 2, 3], [4]], row_splits_dtype=tf.int64) tf.type_spec_from_value(rt).row_splits_dtype tf.int64 \u003cbr /\u003e |\n| `shape` | The statically known shape of the RaggedTensor. \u003cbr /\u003e rt = tf.ragged.constant([[0], [1, 2]]) tf.type_spec_from_value(rt).shape TensorShape([2, None]) rt = tf.ragged.constant([[[0, 1]], [[1, 2], [3, 4]]], ragged_rank=1) tf.type_spec_from_value(rt).shape TensorShape([2, None, 2]) \u003cbr /\u003e |\n| `value_type` | The Python type for values that are compatible with this TypeSpec. \u003cbr /\u003e In particular, all values that are compatible with this TypeSpec must be an instance of this type. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `from_value`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.7.4/tensorflow/python/ops/ragged/ragged_tensor.py#L2583-L2598) \n\n @classmethod\n from_value(\n value\n )\n\n### `is_compatible_with`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.7.4/tensorflow/python/ops/ragged/ragged_tensor.py#L2429-L2438) \n\n is_compatible_with(\n spec_or_value\n )\n\nReturns true if `spec_or_value` is compatible with this TypeSpec.\n\n### `most_specific_compatible_type`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.7.4/tensorflow/python/framework/type_spec.py#L119-L141) \n\n most_specific_compatible_type(\n other: 'TypeSpec'\n ) -\u003e 'TypeSpec'\n\nReturns the most specific TypeSpec compatible with `self` and `other`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|---------|---------------|\n| `other` | A `TypeSpec`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|--------------|--------------------------------------------------------------------------|\n| `ValueError` | If there is no TypeSpec that is compatible with both `self` and `other`. |\n\n\u003cbr /\u003e\n\n### `__eq__`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.7.4/tensorflow/python/framework/type_spec.py#L321-L324) \n\n __eq__(\n other\n ) -\u003e bool\n\nReturn self==value.\n\n### `__ne__`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.7.4/tensorflow/python/framework/type_spec.py#L326-L327) \n\n __ne__(\n other\n ) -\u003e bool\n\nReturn self!=value."]]