tf.feature_column.embedding_column
tf.feature_column.embedding_column
tf.feature_column.embedding_column
embedding_column( categorical_column, dimension, combiner='mean', initializer=None, ckpt_to_load_from=None, tensor_name_in_ckpt=None, max_norm=None, trainable=True )
Defined in tensorflow/python/feature_column/feature_column.py
.
_DenseColumn
that converts from sparse, categorical input.
Use this when your inputs are sparse, but you want to convert them to a dense representation (e.g., to feed to a DNN).
Inputs must be a _CategoricalColumn
created by any of the categorical_column_*
function. Here is an example embedding of an identity column for a DNN model:
video_id = categorical_column_with_identity( key='video_id', num_buckets=1000000, default_value=0) columns = [embedding_column(video_id, 9),...] features = tf.parse_example(..., features=make_parse_example_spec(columns)) dense_tensor = input_layer(features, columns)
Args:
-
categorical_column
: A_CategoricalColumn
created by acategorical_column_with_*
function. This column produces the sparse IDs that are inputs to the embedding lookup. -
dimension
: An integer specifying dimension of the embedding, must be > 0. -
combiner
: A string specifying how to reduce if there are multiple entries in a single row. Currently 'mean', 'sqrtn' and 'sum' are supported, with 'mean' the default. 'sqrtn' often achieves good accuracy, in particular with bag-of-words columns. Each of this can be thought as example level normalizations on the column. For more information, seetf.embedding_lookup_sparse
. -
initializer
: A variable initializer function to be used in embedding variable initialization. If not specified, defaults totf.truncated_normal_initializer
with mean0.0
and standard deviation1/sqrt(dimension)
. -
ckpt_to_load_from
: String representing checkpoint name/pattern from which to restore column weights. Required iftensor_name_in_ckpt
is notNone
. -
tensor_name_in_ckpt
: Name of theTensor
inckpt_to_load_from
from which to restore the column weights. Required ifckpt_to_load_from
is notNone
. -
max_norm
: If notNone
, embedding values are l2-normalized to this value. -
trainable
: Whether or not the embedding is trainable. Default is True.
Returns:
_DenseColumn
that converts from sparse input.
Raises:
-
ValueError
: ifdimension
not > 0. -
ValueError
: if exactly one ofckpt_to_load_from
andtensor_name_in_ckpt
is specified. -
ValueError
: ifinitializer
is specified and is not callable.
© 2017 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/feature_column/embedding_column