# tf.tpu.experimental.embedding.FeatureConfig

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/tpu/tpu_embedding_v2_utils.py#L1139-L1253) |

Configuration data for one embedding feature.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.tpu.experimental.embedding.FeatureConfig`](https://www.tensorflow.org/api_docs/python/tf/tpu/experimental/embedding/FeatureConfig)

<br />

    tf.tpu.experimental.embedding.FeatureConfig(
        table: https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/tpu/experimental/embedding/TableConfig,
        max_sequence_length: int = 0,
        validate_weights_and_indices: bool = True,
        output_shape: Optional[Union[List[int], https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/TensorShape]] = None,
        name: Optional[Text] = None
    )

This class holds the configuration data for a single embedding feature. The
main use is to assign features to [`tf.tpu.experimental.embedding.TableConfig`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/tpu/experimental/embedding/TableConfig)s
via the table parameter:

    table_config_one = tf.tpu.experimental.embedding.TableConfig(
        vocabulary_size=...,
        dim=...)
    table_config_two = tf.tpu.experimental.embedding.TableConfig(
        vocabulary_size=...,
        dim=...)
    feature_config = {
        'feature_one': tf.tpu.experimental.embedding.FeatureConfig(
            table=table_config_one),
        'feature_two': tf.tpu.experimental.embedding.FeatureConfig(
            table=table_config_one),
        'feature_three': tf.tpu.experimental.embedding.FeatureConfig(
            table=table_config_two)}
    embedding = tf.tpu.experimental.embedding.TPUEmbedding(
        feature_config=feature_config,
        batch_size=...
        optimizer=tf.tpu.experimental.embedding.Adam(0.1))

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.

> [!NOTE]
> **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.

When feeding features into `embedding.enqueue` they can be [`tf.Tensor`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/Tensor)s,
[`tf.SparseTensor`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/sparse/SparseTensor)s or [`tf.RaggedTensor`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/RaggedTensor)s. 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)`.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `table` | An instance of [`tf.tpu.experimental.embedding.TableConfig`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/tpu/experimental/embedding/TableConfig), describing the table in which this feature should be looked up. |
| `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. |
| `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 name for the feature, useful for debugging. |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | if `table` is not an instance of [`tf.tpu.experimental.embedding.TableConfig`](https://www.tensorflow.org/versions/r2.14/api_docs/python/tf/tpu/experimental/embedding/TableConfig). |
| `ValueError` | if `max_sequence_length` not an integer or is negative. |

<br />