deepctr.estimator.utils module¶
-
class
deepctr.estimator.utils.
Head
(task, name=None)[source]¶ Bases:
tensorflow.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.
- Args:
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.
- Returns:
- EstimatorSpec.
-
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.
- Args:
- 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.
- Returns:
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,
etc.)To be extendable in the future.
-
logits_dimension
¶ Size of the last dimension of the logits Tensor.
Typically, logits is of shape [batch_size, logits_dimension].
- Returns:
- The expected size of the logits tensor.
-
name
¶ The name of this head.
- Returns:
- A string.
-