This class holds the configuration data for a single embedding feature. The
main use is to assign features to tf.tpu.experimental.embedding.TableConfigs
via the table parameter:
The above configuration has 2 tables, and three features. The first two
features will be looked up in the first table and the third feature will be
looked up in the second table.
You can also specify the output shape for each feature. The output shape
should be the expected activation shape excluding the table dimension. For
dense and sparse tensor, the output shape should be the same as the input
shape excluding the last dimension. For ragged tensor, the output shape can
mismatch the input shape.
When feeding features into embedding.enqueue they can be tf.Tensors,
tf.SparseTensors or tf.RaggedTensors. When the argument
max_sequence_length is 0, the default, you should expect a output of
embedding.dequeue for this feature of shape (batch_size, dim). If
max_sequence_length is greater than 0, the feature is embedded as a sequence
and padded up to the given length. The shape of the output for this feature
will be (batch_size, max_sequence_length, dim).
If positive, the feature is a sequence feature with
the corresponding maximum sequence length. If the sequence is longer
than this, it will be truncated. If 0, the feature is not a sequence
feature.
validate_weights_and_indices
If true, uses safe_embedding_lookup during
serving which ensures there are no empty rows and all weights and ids
are positive at the expense of extra compute cost.
output_shape
Optional argument to config the output shape of the feature
activation. If provided, the feature feeding to the embedding.enqueue
has to match the shape (for ragged tensor, the input shape and output
shape can mismatch). If not provided, the shape can be either provided
to the embedding.build or auto detected at the runtime.
name
An optional string used to name the table. Must be defined if
running on SparseCore.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.tpu.experimental.embedding.FeatureConfig\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/tpu/tpu_embedding_v2_utils.py#L1188-L1303) |\n\nConfiguration data for one embedding feature.\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.tpu.experimental.embedding.FeatureConfig`](https://www.tensorflow.org/api_docs/python/tf/tpu/experimental/embedding/FeatureConfig)\n\n\u003cbr /\u003e\n\n tf.tpu.experimental.embedding.FeatureConfig(\n table: ../../../../tf/tpu/experimental/embedding/TableConfig,\n max_sequence_length: int = 0,\n validate_weights_and_indices: bool = True,\n output_shape: Optional[Union[List[int], ../../../../tf/TensorShape]] = None,\n name: Optional[Text] = None\n )\n\n### Used in the notebooks\n\n| Used in the guide | Used in the tutorials |\n|----------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|\n| - [Migrate from TPU embedding_columns to TPUEmbedding layer](https://www.tensorflow.org/guide/migrate/tpu_embedding) | - [TensorFlow 2 TPUEmbeddingLayer: Quick Start](https://www.tensorflow.org/recommenders/examples/tpu_embedding_layer) |\n\nThis class holds the configuration data for a single embedding feature. The\nmain use is to assign features to [`tf.tpu.experimental.embedding.TableConfig`](../../../../tf/tpu/experimental/embedding/TableConfig)s\nvia the table parameter: \n\n table_config_one = tf.tpu.experimental.embedding.TableConfig(\n vocabulary_size=...,\n dim=...)\n table_config_two = tf.tpu.experimental.embedding.TableConfig(\n vocabulary_size=...,\n dim=...)\n feature_config = {\n 'feature_one': tf.tpu.experimental.embedding.FeatureConfig(\n table=table_config_one),\n 'feature_two': tf.tpu.experimental.embedding.FeatureConfig(\n table=table_config_one),\n 'feature_three': tf.tpu.experimental.embedding.FeatureConfig(\n table=table_config_two)}\n embedding = tf.tpu.experimental.embedding.TPUEmbedding(\n feature_config=feature_config,\n batch_size=...\n optimizer=tf.tpu.experimental.embedding.Adam(0.1))\n\nThe above configuration has 2 tables, and three features. The first two\nfeatures will be looked up in the first table and the third feature will be\nlooked up in the second table.\n\nYou can also specify the output shape for each feature. The output shape\nshould be the expected activation shape excluding the table dimension. For\ndense and sparse tensor, the output shape should be the same as the input\nshape excluding the last dimension. For ragged tensor, the output shape can\nmismatch the input shape.\n| **Note:** The `max_sequence_length` will be only used when the input tensor has rank 2 and the `output_shape` is not set in the feature config.\n\nWhen feeding features into `embedding.enqueue` they can be [`tf.Tensor`](../../../../tf/Tensor)s,\n[`tf.SparseTensor`](../../../../tf/sparse/SparseTensor)s or [`tf.RaggedTensor`](../../../../tf/RaggedTensor)s. When the argument\n`max_sequence_length` is 0, the default, you should expect a output of\n`embedding.dequeue` for this feature of shape `(batch_size, dim)`. If\n`max_sequence_length` is greater than 0, the feature is embedded as a sequence\nand padded up to the given length. The shape of the output for this feature\nwill be `(batch_size, max_sequence_length, dim)`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `table` | An instance of [`tf.tpu.experimental.embedding.TableConfig`](../../../../tf/tpu/experimental/embedding/TableConfig), describing the table in which this feature should be looked up. |\n| `max_sequence_length` | If positive, the feature is a sequence feature with the corresponding maximum sequence length. If the sequence is longer than this, it will be truncated. If 0, the feature is not a sequence feature. |\n| `validate_weights_and_indices` | If true, uses safe_embedding_lookup during serving which ensures there are no empty rows and all weights and ids are positive at the expense of extra compute cost. |\n| `output_shape` | Optional argument to config the output shape of the feature activation. If provided, the feature feeding to the `embedding.enqueue` has to match the shape (for ragged tensor, the input shape and output shape can mismatch). If not provided, the shape can be either provided to the `embedding.build` or auto detected at the runtime. |\n| `name` | An optional string used to name the table. Must be defined if running on SparseCore. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|----------------------------------------------------------------------------------------------------------------------------------------|\n| `ValueError` | if `table` is not an instance of [`tf.tpu.experimental.embedding.TableConfig`](../../../../tf/tpu/experimental/embedding/TableConfig). |\n| `ValueError` | if `max_sequence_length` not an integer or is negative. |\n\n\u003cbr /\u003e"]]