categorical_column_with_identity => Modified the Example code such that it is executable

Github Gist for working code is https://colab.research.google.com/gist/rmothukuru/282a8d27fabc233a1cea7479e846bd68/categorical_column_with_identity.ipynb

Fixes 

PiperOrigin-RevId: 353275642
Change-Id: I72662eaab3ad041e4846ef476cea7a47383770c4
This commit is contained in:
A. Unique TensorFlower 2021-01-22 10:56:27 -08:00 committed by TensorFlower Gardener
parent 101b68041c
commit c3767f71b8

View File

@ -1560,19 +1560,27 @@ def categorical_column_with_identity(key, num_buckets, default_value=None):
Linear model:
```python
video_id = categorical_column_with_identity(
import tensorflow as tf
video_id = tf.feature_column.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)
columns = [video_id]
features = {'video_id': tf.sparse.from_dense([[2, 85, 0, 0, 0],
[33,78, 2, 73, 1]])}
linear_prediction = tf.compat.v1.feature_column.linear_model(features,
columns)
```
Embedding for a DNN model:
```python
columns = [embedding_column(video_id, 9),...]
features = tf.io.parse_example(..., features=make_parse_example_spec(columns))
dense_tensor = input_layer(features, columns)
import tensorflow as tf
video_id = tf.feature_column.categorical_column_with_identity(
key='video_id', num_buckets=1000000, default_value=0)
columns = [tf.feature_column.embedding_column(video_id, 9)]
features = {'video_id': tf.sparse.from_dense([[2, 85, 0, 0, 0],
[33,78, 2, 73, 1]])}
input_layer = tf.keras.layers.DenseFeatures(columns)
dense_tensor = input_layer(features)
```
Args: