Join us at TensorFlow World, Oct 28-31. Use code TF20 for 20% off select passes. Register now


TensorFlow 2.0 version View source on GitHub

Class DenseFeatures

A layer that produces a dense Tensor based on given feature_columns.


  • Class tf.compat.v1.keras.layers.DenseFeatures
  • Class tf.compat.v2.keras.layers.DenseFeatures

Generally a single example in training data is described with FeatureColumns. At the first layer of the model, this column oriented data should be converted to a single Tensor.

This layer can be called multiple times with different features.


price = numeric_column('price')
keywords_embedded = embedding_column(
    categorical_column_with_hash_bucket("keywords", 10K), dimensions=16)
columns = [price, keywords_embedded, ...]
feature_layer = DenseFeatures(columns)

features =, features=make_parse_example_spec(columns))
dense_tensor = feature_layer(features)
for units in [128, 64, 32]:
  dense_tensor = tf.compat.v1.layers.dense(dense_tensor, units, tf.nn.relu)
prediction = tf.compat.v1.layers.dense(dense_tensor, 1).


View source


Constructs a DenseFeatures.


  • feature_columns: An iterable containing the FeatureColumns to use as inputs to your model. All items should be instances of classes derived from DenseColumn such as numeric_column, embedding_column, bucketized_column, indicator_column. If you have categorical features, you can wrap them with an embedding_column or indicator_column.
  • trainable: Boolean, whether the layer's variables will be updated via gradient descent during training.
  • name: Name to give to the DenseFeatures.
  • **kwargs: Keyword arguments to construct a layer.


  • ValueError: if an item in feature_columns is not a DenseColumn.