tf.compat.v1.keras.layers.DenseFeatures
Stay organized with collections
Save and categorize content based on your preferences.
A layer that produces a dense Tensor
based on given feature_columns
.
Inherits From: Layer
, Module
tf.compat.v1.keras.layers.DenseFeatures(
feature_columns, trainable=True, name=None, partitioner=None, **kwargs
)
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.
This is the V1 version of this layer that uses variable_scope's or
partitioner to create variables which works well with PartitionedVariables.
Variable scopes are deprecated in V2, so the V2 version uses name_scopes
instead. But currently that lacks support for partitioned variables. Use
this if you need partitioned variables. Use the partitioner argument if you
have a Keras model and uses
tf.compat.v1.keras.estimator.model_to_estimator
for training.
Example:
price = tf.feature_column.numeric_column('price')
keywords_embedded = tf.feature_column.embedding_column(
tf.feature_column.categorical_column_with_hash_bucket("keywords", 10K),
dimension=16)
columns = [price, keywords_embedded, ...]
partitioner = tf.compat.v1.fixed_size_partitioner(num_shards=4)
feature_layer = tf.compat.v1.keras.layers.DenseFeatures(
feature_columns=columns, partitioner=partitioner)
features = tf.io.parse_example(
..., features=tf.feature_column.make_parse_example_spec(columns))
dense_tensor = feature_layer(features)
for units in [128, 64, 32]:
dense_tensor = tf.compat.v1.keras.layers.Dense(
units, activation='relu')(dense_tensor)
prediction = tf.compat.v1.keras.layers.Dense(1)(dense_tensor)
Args |
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.
|
partitioner
|
Partitioner for input layer. Defaults to None .
|
**kwargs
|
Keyword arguments to construct a layer.
|
Raises |
ValueError
|
if an item in feature_columns is not a DenseColumn .
|
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. Some content is licensed under the numpy license.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[],[],null,["# tf.compat.v1.keras.layers.DenseFeatures\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v2.13.1/keras/feature_column/dense_features.py#L33-L191) |\n\nA layer that produces a dense `Tensor` based on given `feature_columns`.\n\nInherits From: [`Layer`](../../../../../tf/keras/layers/Layer), [`Module`](../../../../../tf/Module) \n\n tf.compat.v1.keras.layers.DenseFeatures(\n feature_columns, trainable=True, name=None, partitioner=None, **kwargs\n )\n\nGenerally a single example in training data is described with\nFeatureColumns. At the first layer of the model, this column-oriented data\nshould be converted to a single `Tensor`.\n\nThis layer can be called multiple times with different features.\n\nThis is the V1 version of this layer that uses variable_scope's or\npartitioner to create variables which works well with PartitionedVariables.\nVariable scopes are deprecated in V2, so the V2 version uses name_scopes\ninstead. But currently that lacks support for partitioned variables. Use\nthis if you need partitioned variables. Use the partitioner argument if you\nhave a Keras model and uses\n[`tf.compat.v1.keras.estimator.model_to_estimator`](../../../../../tf/compat/v1/keras/estimator/model_to_estimator) for training.\n\n#### Example:\n\n price = tf.feature_column.numeric_column('price')\n keywords_embedded = tf.feature_column.embedding_column(\n tf.feature_column.categorical_column_with_hash_bucket(\"keywords\", 10K),\n dimension=16)\n columns = [price, keywords_embedded, ...]\n partitioner = tf.compat.v1.fixed_size_partitioner(num_shards=4)\n feature_layer = tf.compat.v1.keras.layers.DenseFeatures(\n feature_columns=columns, partitioner=partitioner)\n\n features = tf.io.parse_example(\n ..., features=tf.feature_column.make_parse_example_spec(columns))\n dense_tensor = feature_layer(features)\n for units in [128, 64, 32]:\n dense_tensor = tf.compat.v1.keras.layers.Dense(\n units, activation='relu')(dense_tensor)\n prediction = tf.compat.v1.keras.layers.Dense(1)(dense_tensor)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `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`. |\n| `trainable` | Boolean, whether the layer's variables will be updated via gradient descent during training. |\n| `name` | Name to give to the DenseFeatures. |\n| `partitioner` | Partitioner for input layer. Defaults to `None`. |\n| `**kwargs` | Keyword arguments to construct a layer. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|---------------------------------------------------------|\n| `ValueError` | if an item in `feature_columns` is not a `DenseColumn`. |\n\n\u003cbr /\u003e"]]