deepctr.estimator.utils module

class deepctr.estimator.utils.Head(task, name=None)[source]

Bases: tensorflow_estimator.python.estimator.canned.head._Head

create_estimator_spec(features, mode, logits, labels=None, train_op_fn=None, training_chief_hooks=None)[source]

Returns EstimatorSpec that a model_fn can return.

Please note that, + All args must be passed via name.


features: Input dict of Tensor or SparseTensor objects. mode: Estimator’s ModeKeys. logits: logits Tensor to be used by the head. labels: Labels Tensor, or dict of same. optimizer: Optimizer instance to optimize the loss in TRAIN mode.

Namely, sets train_op = optimizer.minimize(loss, global_step), which updates variables and increments global_step.
train_op_fn: Function that takes a scalar loss Tensor and returns an op

to optimize the model with the loss in TRAIN mode. Used if optimizer is None. Exactly one of train_op_fn and optimizer must be set in TRAIN mode. None is allowed in other modes. If you want to optimize loss yourself you can pass lambda _: tf.no_op() and then use

EstimatorSpec.loss to compute and apply gradients.
regularization_losses: A list of additional scalar losses to be added to
the training loss, such as regularization losses.
create_loss(features, mode, logits, labels)[source]

Returns a loss Tensor from provided logits.

This function is designed to be used by framework developers. Almost all users should use create_estimator_spec(), which calls this internally. mode and features are most likely not used, but some Head implementations may require them.

features: Input dict of Tensor objects. mode: Estimator’s ModeKeys. logits: logits Tensor to be used for loss construction. labels: Labels Tensor, or dict of same.

A LossSpec that contains * the scalar Tensor representing reduced weighted training loss * the Tensor representing the unreduced unweighted loss * the Tensor representing the example weights * possibly processed labels (e.g. vocabulary lookup, shape manipulation,


To be extendable in the future.


Size of the last dimension of the logits Tensor.

Typically, logits is of shape [batch_size, logits_dimension].

The expected size of the logits tensor.

The name of this head.

A string.
deepctr.estimator.utils.deepctr_model_fn(features, mode, logits, labels, task, linear_optimizer, dnn_optimizer, training_chief_hooks)[source]
deepctr.estimator.utils.get_collection(key, scope=None)[source]
deepctr.estimator.utils.get_train_op_fn(linear_optimizer, dnn_optimizer)[source]
deepctr.estimator.utils.input_layer(features, feature_columns)[source]
deepctr.estimator.utils.summary_scalar(name, data)[source]
deepctr.estimator.utils.to_float(x, name='ToFloat')[source]