Use this when your inputs are integers in the range [0, num_buckets), and
you want to use the input value itself as the categorical ID. Values outside
this range will result in default_value if specified, otherwise it will
fail.
Typically, this is used for contiguous ranges of integer indexes, but
it doesn't have to be. This might be inefficient, however, if many of IDs
are unused. Consider categorical_column_with_hash_bucket in that case.
For input dictionary features, features[key] is either Tensor or
SparseTensor. If Tensor, missing values can be represented by -1 for int
and '' for string, which will be dropped by this feature column.
In the following examples, each input in the range [0, 1000000) is assigned
the same value. All other inputs are assigned default_value 0. Note that a
literal 0 in inputs will result in the same default ID.
A unique string identifying the input feature. It is used as the column
name and the dictionary key for feature parsing configs, feature Tensor
objects, and feature columns.
num_buckets
Range of inputs and outputs is [0, num_buckets).
default_value
If set, values outside of range [0, num_buckets) will be
replaced with this value. If not set, values >= num_buckets will cause a
failure while values < 0 will be dropped.
Returns
A CategoricalColumn that returns identity values.
Raises
ValueError
if num_buckets is less than one.
ValueError
if default_value is not in range [0, num_buckets).
[[["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 2024-04-26 UTC."],[],[],null,["# tf.feature_column.categorical_column_with_identity\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/feature_column/feature_column_v2.py#L1441-L1516) |\n\nA `CategoricalColumn` that returns identity values. (deprecated)\n| **Warning:** tf.feature_column is not recommended for new code. Instead, feature preprocessing can be done directly using either [Keras preprocessing\n| layers](https://www.tensorflow.org/guide/migrate/migrating_feature_columns) or through the one-stop utility [`tf.keras.utils.FeatureSpace`](https://www.tensorflow.org/api_docs/python/tf/keras/utils/FeatureSpace) built on top of them. See the [migration guide](https://tensorflow.org/guide/migrate) for details.\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.feature_column.categorical_column_with_identity`](https://www.tensorflow.org/api_docs/python/tf/feature_column/categorical_column_with_identity)\n\n\u003cbr /\u003e\n\n tf.feature_column.categorical_column_with_identity(\n key, num_buckets, default_value=None\n )\n\n### Used in the notebooks\n\n| Used in the guide | Used in the tutorials |\n|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Migrate \\`tf.feature_column\\`s to Keras preprocessing layers](https://www.tensorflow.org/guide/migrate/migrating_feature_columns) - [Migrate from TPU embedding_columns to TPUEmbedding layer](https://www.tensorflow.org/guide/migrate/tpu_embedding) | - [TFX Estimator Component Tutorial](https://www.tensorflow.org/tfx/tutorials/tfx/components) - [Preprocessing data with TensorFlow Transform](https://www.tensorflow.org/tfx/tutorials/transform/census) |\n\n| **Deprecated:** THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use Keras preprocessing layers instead, either directly or via the [`tf.keras.utils.FeatureSpace`](../../tf/keras/utils/FeatureSpace) utility. Each of `tf.feature_column.*` has a functional equivalent in `tf.keras.layers` for feature preprocessing when training a Keras model.\n\nUse this when your inputs are integers in the range `[0, num_buckets)`, and\nyou want to use the input value itself as the categorical ID. Values outside\nthis range will result in `default_value` if specified, otherwise it will\nfail.\n\nTypically, this is used for contiguous ranges of integer indexes, but\nit doesn't have to be. This might be inefficient, however, if many of IDs\nare unused. Consider `categorical_column_with_hash_bucket` in that case.\n\nFor input dictionary `features`, `features[key]` is either `Tensor` or\n`SparseTensor`. If `Tensor`, missing values can be represented by `-1` for int\nand `''` for string, which will be dropped by this feature column.\n\nIn the following examples, each input in the range `[0, 1000000)` is assigned\nthe same value. All other inputs are assigned `default_value` 0. Note that a\nliteral 0 in inputs will result in the same default ID.\n\n#### Linear model:\n\n import tensorflow as tf\n video_id = tf.feature_column.categorical_column_with_identity(\n key='video_id', num_buckets=1000000, default_value=0)\n columns = [video_id]\n features = {'video_id': tf.sparse.from_dense([[2, 85, 0, 0, 0],\n [33,78, 2, 73, 1]])}\n linear_prediction = tf.compat.v1.feature_column.linear_model(features,\n columns)\n\nEmbedding for a DNN model: \n\n import tensorflow as tf\n video_id = tf.feature_column.categorical_column_with_identity(\n key='video_id', num_buckets=1000000, default_value=0)\n columns = [tf.feature_column.embedding_column(video_id, 9)]\n features = {'video_id': tf.sparse.from_dense([[2, 85, 0, 0, 0],\n [33,78, 2, 73, 1]])}\n input_layer = tf.keras.layers.DenseFeatures(columns)\n dense_tensor = input_layer(features)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `key` | A unique string identifying the input feature. It is used as the column name and the dictionary key for feature parsing configs, feature `Tensor` objects, and feature columns. |\n| `num_buckets` | Range of inputs and outputs is `[0, num_buckets)`. |\n| `default_value` | If set, values outside of range `[0, num_buckets)` will be replaced with this value. If not set, values \\\u003e= num_buckets will cause a failure while values \\\u003c 0 will be dropped. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `CategoricalColumn` that returns identity values. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|--------------------------------------------------------|\n| `ValueError` | if `num_buckets` is less than one. |\n| `ValueError` | if `default_value` is not in range `[0, num_buckets)`. |\n\n\u003cbr /\u003e"]]