tf.feature_column.categorical_column_with_identity
Stay organized with collections
Save and categorize content based on your preferences.
A CategoricalColumn
that returns identity values.
tf.feature_column.categorical_column_with_identity(
key, num_buckets, default_value=None
)
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.
Linear model:
video_id = categorical_column_with_identity(
key='video_id', num_buckets=1000000, default_value=0)
columns = [video_id, ...]
features = tf.io.parse_example(..., features=make_parse_example_spec(columns))
linear_prediction, _, _ = linear_model(features, columns)
Embedding for a DNN model:
columns = [embedding_column(video_id, 9),...]
features = tf.io.parse_example(..., features=make_parse_example_spec(columns))
dense_tensor = input_layer(features, columns)
Args |
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.
|
num_buckets
|
Range of inputs and outputs is [0, num_buckets) .
|
default_value
|
If None , this column's graph operations will fail for
out-of-range inputs. Otherwise, this value must be in the range
[0, num_buckets) , and will replace inputs in that range.
|
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) .
|
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 2020-10-01 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 2020-10-01 UTC."],[],[],null,["# tf.feature_column.categorical_column_with_identity\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/feature_column/categorical_column_with_identity) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/feature_column/feature_column_v2.py#L1812-L1877) |\n\nA `CategoricalColumn` that returns identity values.\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`](/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\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 video_id = categorical_column_with_identity(\n key='video_id', num_buckets=1000000, default_value=0)\n columns = [video_id, ...]\n features = tf.io.parse_example(..., features=make_parse_example_spec(columns))\n linear_prediction, _, _ = linear_model(features, columns)\n\nEmbedding for a DNN model: \n\n columns = [embedding_column(video_id, 9),...]\n features = tf.io.parse_example(..., features=make_parse_example_spec(columns))\n dense_tensor = input_layer(features, columns)\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 `None`, this column's graph operations will fail for out-of-range inputs. Otherwise, this value must be in the range `[0, num_buckets)`, and will replace inputs in that range. |\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"]]