Join the newly launched Discord
community for real-time discussions, peer support, and direct interaction with the Meridian team!
meridian.backend.ExtensionType
Stay organized with collections
Save and categorize content based on your preferences.
Base class for TensorFlow ExtensionType
classes.
meridian
.
backend
.
ExtensionType
(
*
args
,
**
kwargs
)
Tensorflow ExtensionType
classes are specialized Python classes that can be
used transparently with TensorFlow -- e.g., they can be used with ops
such as tf.cond
or tf.while_loop
and used as inputs or outputs for tf.function
and Keras layers.
New ExtensionType
classes are defined by creating a subclass of tf.ExtensionType
that
contains type annotations for all instance variables. The following type
annotations are supported:
Fields annotated with typing.Mapping
will be stored using an immutable
mapping type.
ExtensionType values are immutable -- i.e., once constructed, you can not
modify or delete any of their instance members.
Examples
>>> class
MaskedTensor
( ExtensionType
):
... values:
tf
. Tensor
... mask:
tf
. Tensor
>>> class
Toy
( ExtensionType
):
... name:
str
... price:
tensor
. Tensor
... features:
typing
. Mapping
[ str
, tf
. Tensor
]
>>> class
ToyStore
( ExtensionType
):
... name:
str
... toys:
typing
. Tuple
[ Toy
, ...]
Methods
__eq__
__eq__
(
other
)
Return self==value.
__ne__
__ne__
(
other
)
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.
Last updated 2025-09-05 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-05 UTC."],[],[],null,["\u003cbr /\u003e\n\nBase class for TensorFlow `ExtensionType` classes. \n\n meridian.backend.ExtensionType(\n *args, **kwargs\n )\n\nTensorflow `ExtensionType` classes are specialized Python classes that can be\nused transparently with TensorFlow -- e.g., they can be used with ops\nsuch as `tf.cond` or `tf.while_loop` and used as inputs or outputs for\n`tf.function` and Keras layers.\n\nNew `ExtensionType` classes are defined by creating a subclass of\n`tf.ExtensionType` that\ncontains type annotations for all instance variables. The following type\nannotations are supported:\n\n| Type | Example |\n|--------------------------|----------------------------------------------|\n| Python integers | `i: int` |\n| Python floats | `f: float` |\n| Python strings | `s: str` |\n| Python booleans | `b: bool` |\n| Python None | `n: None` |\n| Python tuple | `params: tuple[int, float, int, int]` |\n| Python tuple w/ Ellipsis | `lengths: tuple[int, ...]` |\n| Tensors | `t: tf.Tensor` |\n| Composite Tensors | `rt: tf.RaggedTensor` |\n| Extension Types | `m: MyMaskedTensor` |\n| Tensor shapes | `shape: tf.TensorShape` |\n| Tensor dtypes | `dtype: tf.DType` |\n| Type unions | `length: typing.Union[int, float]` |\n| Tuples | `params: typing.Tuple[int, float, int, int]` |\n| Tuples w/ Ellipsis | `lengths: typing.Tuple[int, ...]` |\n| Mappings | `tags: typing.Mapping[str, str]` |\n\nFields annotated with `typing.Mapping` will be stored using an immutable\nmapping type.\n\nExtensionType values are immutable -- i.e., once constructed, you can not\nmodify or delete any of their instance members.\n\nExamples \n\n \u003e\u003e\u003e class MaskedTensor(ExtensionType):\n ... values: tf.Tensor\n ... mask: tf.Tensor\n\n \u003e\u003e\u003e class Toy(ExtensionType):\n ... name: str\n ... price: tensor.Tensor\n ... features: typing.Mapping[str, tf.Tensor]\n\n \u003e\u003e\u003e class ToyStore(ExtensionType):\n ... name: str\n ... toys: typing.Tuple[Toy, ...]\n\nMethods\n\n`__eq__` \n\n __eq__(\n other\n )\n\nReturn self==value.\n\n`__ne__` \n\n __ne__(\n other\n )\n\nReturn self!=value."]]