sparse_feature_a = sparse_column_with_hash_bucket(...)
sparse_feature_b = sparse_column_with_hash_bucket(...)
sparse_feature_a_emb = embedding_column(sparse_id_column=sparse_feature_a,
sparse_feature_b_emb = embedding_column(sparse_id_column=sparse_feature_b,
To create a DNNEstimator for binary classification, where
estimator = DNNEstimator(
hidden_units=[1024, 512, 256])
If your label is keyed with "y" in your labels dict, and weights are keyed
with "w" in features dict, and you want to enable centered bias,
head = tf.contrib.learn.multi_class_head(
estimator = DNNEstimator(
hidden_units=[1024, 512, 256])
# Input builders
def input_fn_train: # returns x, y (where y represents label's class index).
def input_fn_eval: # returns x, y (where y represents label's class index).
estimator.predict(x=x) # returns predicted labels (i.e. label's class index).
Input of fit and evaluate should have following features,
otherwise there will be a KeyError:
if weight_column_name is not None, a feature with
key=weight_column_name whose value is a Tensor.
for each column in feature_columns:
if column is a SparseColumn, a feature with key=column.name
whose value is a SparseTensor.
if column is a WeightedSparseColumn, two features: the first with
key the id column name, the second with key the weight column name.
Both features' value must be a SparseTensor.
if column is a RealValuedColumn, a feature with key=column.name
whose value is a Tensor.
List of hidden units per layer. All layers are fully
connected. Ex. [64, 32] means first layer has 64 nodes and second one
An iterable containing all the feature columns used by
the model. All items in the set should be instances of classes derived
Directory to save model parameters, graph and etc. This can
also be used to load checkpoints from the directory into a estimator to
continue training a previously saved model.
An instance of tf.Optimizer used to train the model. If
None, will use an Adagrad optimizer.
Activation function applied to each layer. If None, will
use tf.nn.relu. Note that a string containing the unqualified name of
the op may also be provided, e.g., "relu", "tanh", or "sigmoid".
When not None, the probability we will drop out a given
A float > 0. If provided, gradients are
clipped to their global norm with this clipping ratio. See
tf.clip_by_global_norm for more details.
RunConfig object to configure the runtime settings.
Feature engineering function. Takes features and
labels which are the output of input_fn and
returns features and labels which will be fed
into the model.
Optional. A dictionary from EmbeddingColumn to
a float multiplier. Multiplier will be used to multiply with
learning rate for the embedding variables.
Optional. The min slice size of input layer
partitions. If not provided, will use the default of 64M.
Returns a path in which the eval process will look for checkpoints.
Returns the model_fn which is bound to self.params.
Exports inference graph into given dir. (deprecated)
A string containing a directory to write the exported graph
If use_deprecated_input_fn is true, then a function that given
Tensor of Example strings, parses it into features that are then
passed to the model. Otherwise, a function that takes no argument and
returns a tuple of (features, labels), where features is a dict of
string key to Tensor and labels is a Tensor that's currently not
used (and so can be None).
Only used if use_deprecated_input_fn is false. String
key into the features dict returned by input_fn that corresponds to a
the raw Example strings Tensor that the exported model will take as
input. Can only be None if you're using a custom signature_fn that
does not use the first arg (examples).
Determines the signature format of input_fn.
Function that returns a default signature and a named
signature map, given Tensor of Example strings, dict of Tensors
for features and Tensor or dict of Tensors for predictions.
The key for a tensor in the predictions dict (output
from the model_fn) to use as the predictions input to the
signature_fn. Optional. If None, predictions will pass to
signature_fn without filtering.
Default batch size of the Example placeholder.
Number of exports to keep.
the checkpoint path of the model to be exported. If it is
None (which is default), will use the latest checkpoint in
The string path to the exported directory. NB: this functionality was
added ca. 2016/09/25; clients that depend on the return value may need
to handle the case where this function returns None because subclasses
are not returning a value.
Exports inference graph as a SavedModel into given dir.
A string containing a directory to write the exported
graph and checkpoints.
A function that takes no argument and
returns an InputFnOps.
the name of the head to serve when none is
specified. Not needed for single-headed models.
A dict specifying how to populate the assets.extra directory
within the exported SavedModel. Each key should give the destination
path (including the filename) relative to the assets.extra directory.
The corresponding value gives the full path of the source file to be
copied. For example, the simple case of copying a single file without
renaming it is specified as
whether to write the SavedModel proto in text format.
The checkpoint path to export. If None (the default),
the most recent checkpoint found within the model directory is chosen.
an iterable of GraphRewriteSpec. Each element will
produce a separate MetaGraphDef within the exported SavedModel, tagged
and rewritten as specified. Defaults to a single entry using the
default serving tag ("serve") and no rewriting.
Incremental fit on a batch of samples. (deprecated arguments)
This method is expected to be called several times consecutively
on different or the same chunks of the dataset. This either can
implement iterative training or out-of-core/online training.
This is especially useful when the whole dataset is too big to
fit in memory at the same time. Or when model is taking long time
to converge, and you want to split up training into subparts.
Matrix of shape [n_samples, n_features...]. Can be iterator that
returns arrays of features. The training input samples for fitting the
model. If set, input_fn must be None.
Vector or matrix [n_samples] or [n_samples, n_outputs]. Can be
iterator that returns array of labels. The training label values
(class labels in classification, real numbers in regression). If set,
input_fn must be None.
Input function. If set, x, y, and batch_size must be
Number of steps for which to train model. If None, train forever.
minibatch size to use on the input, defaults to first
dimension of x. Must be None if input_fn is provided.
List of BaseMonitor subclass instances. Used for callbacks
inside the training loop.
self, for chaining.
If at least one of x and y is provided, and input_fn is