tf.keras.layers.DenseFeatures api as the candidate of hb.feature_column.DenseFeatures can not work with tf.feature_column.shared_embedding_columns
Closed this issue · 1 comments
Current behavior
HB version: HybridBackend 0.7.0-e277c15f3843f98901f0795bc9b7d0768056d5a3; tf1.15.5-v1.15.5+nv22.06-0-g55be3962f8; g++ 7.5.0; CUDA 11.4 (70,75,80,86)
new hb package removes the hb.feature_column.DenseFeatures api. However, tf.keras.layers.DenseFeatures api can not deal with
tf.feature_column.shared_embedding_columns.
Expected behavior
I want a new way to run the code successfully without hb.feature_column.DenseFeatures.
System information
- GPU model and memory:
- OS Platform:
- Docker version:
- GCC/CUDA/cuDNN version:
- Python/conda version:
- TensorFlow/PyTorch version:
Code to reproduce
Willing to contribute
Yes
We recommend you to use the tf.feature_column.input_layer
instead of tf.keras.layers.DenseFeatures
when the feature columns are generated by using tf.feature_column.shared_embedding_columns
. Please refer to the code example as follows:
...
self._embedding_columns = tf.feature_column.shared_embedding_columns(
[tf.feature_column.categorical_column_with_identity(
key=f,
num_buckets=self._args.data_spec.embedding_sizes[f],
default_value=self._args.data_spec.defaults[f])
for f in self._categorical_fields],
dimension=self._args.embedding_dim,
initializer=tf.random_uniform_initializer(-1e-3, 1e-3)
)
cols_to_output_tensors = {}
tf.feature_column.input_layer(
{f: features[f] for f in self._categorical_fields},
self._embedding_columns,
cols_to_output_tensors=cols_to_output_tensors)
...
Internally, the tf.feature_column.input_layer
API does accept feature columns with a type of _FeatureColumn
while the API of tf.keras.layers.DenseFeatures
only accepts a type derived from FeatureColumn
which is not compatible with that of a shared embedding.