tf.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: DenseFeatures
, Layer
, Module
tf.keras.layers.DenseFeatures(
feature_columns, trainable=True, name=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 V2 version of this layer that uses name_scopes to create
variables instead of variable_scopes. But this approach currently lacks
support for partitioned variables. In that case, use the V1 version instead.
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),
dimensions=16)
columns = [price, keywords_embedded, ...]
feature_layer = tf.keras.layers.DenseFeatures(columns)
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.keras.layers.Dense(units, activation='relu')(dense_tensor)
prediction = tf.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.
|
**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 2022-10-27 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 2022-10-27 UTC."],[],[]]