easy_rec.python.model¶
easy_rec.python.model.easy_rec_model¶
- class easy_rec.python.model.easy_rec_model.EasyRecModel(model_config, feature_configs, features, labels=None, is_training=False)[source]¶
Bases:
object
- property has_backbone¶
- property backbone¶
- property embedding_regularization¶
- property kd¶
- property feature_groups¶
- property l2_regularization¶
- classmethod create_class(name)¶
- restore(ckpt_path, include_global_step=False, ckpt_var_map_path='', force_restore_shape_compatible=False)[source]¶
Restore variables from ckpt_path.
- steps:
list the variables in graph that need to be restored
inspect checkpoint and find the variables that could restore from checkpoint substitute scope names in case necessary
call tf.train.init_from_checkpoint to restore the variables
- Parameters:
ckpt_path – checkpoint path to restore from
include_global_step – whether to restore global_step variable
ckpt_var_map_path – variable map from graph variables to variables in a checkpoint each line consists of: variable name in graph variable name in ckpt
force_restore_shape_compatible – if variable shape is incompatible, clip or pad variables in checkpoint, and then restore
- Returns:
IncompatibleShapeRestoreHook if force_shape_compatible else None
easy_rec.python.model.rank_model¶
- class easy_rec.python.model.rank_model.RankModel(model_config, feature_configs, features, labels=None, is_training=False)[source]¶
Bases:
EasyRecModel
- classmethod create_class(name)¶
easy_rec.python.model.fm¶
easy_rec.python.model.wide_and_deep¶
easy_rec.python.model.deepfm¶
easy_rec.python.model.multi_tower¶
easy_rec.python.model.dcn¶
easy_rec.python.model.autoint¶
easy_rec.python.model.dbmtl¶
easy_rec.python.model.multi_tower_bst¶
easy_rec.python.model.multi_tower_din¶
easy_rec.python.model.dssm¶
easy_rec.python.model.mind¶
easy_rec.python.model.multi_task_model¶
easy_rec.python.model.mmoe¶
easy_rec.python.model.esmm¶
- class easy_rec.python.model.esmm.ESMM(model_config, feature_configs, features, labels=None, is_training=False)[source]¶
Bases:
MultiTaskModel
- build_loss_graph()[source]¶
Build loss graph.
- Returns:
Weighted loss of ctr and cvr.
- Return type:
self._loss_dict
- build_metric_graph(eval_config)[source]¶
Build metric graph.
- Parameters:
eval_config – Evaluation configuration.
- Returns:
Calculate AUC of ctr, cvr and ctrvr.
- Return type:
metric_dict
- build_predict_graph()[source]¶
Forward function.
- Returns:
Prediction result of two tasks.
- Return type:
self._prediction_dict
- classmethod create_class(name)¶
easy_rec.python.model.easy_rec_estimator¶
- class easy_rec.python.model.simple_multi_task.SimpleMultiTask(model_config, feature_configs, features, labels=None, is_training=False)[source]¶
Bases:
MultiTaskModel
- classmethod create_class(name)¶
easy_rec.python.model.easy_rec_estimator¶
- class easy_rec.python.model.easy_rec_estimator.EasyRecEstimator(pipeline_config, model_cls, run_config, params)[source]¶
Bases:
Estimator
- __init__(pipeline_config, model_cls, run_config, params)[source]¶
Constructs an Estimator instance.
- Parameters:
model_fn – Model function. Follows the signature: * features – This is the first item returned from the input_fn passed to train, evaluate, and predict. This should be a single tf.Tensor or dict of same. * labels – This is the second item returned from the input_fn passed to train, evaluate, and predict. This should be a single tf.Tensor or dict of same (for multi-head models). If mode is tf.estimator.ModeKeys.PREDICT, labels=None will be passed. If the model_fn’s signature does not accept mode, the model_fn must still be able to handle labels=None. * mode – Optional. Specifies if this is training, evaluation or prediction. See tf.estimator.ModeKeys. params – Optional dict of hyperparameters. Will receive what is passed to Estimator in params parameter. This allows to configure Estimators from hyper parameter tuning. * config – Optional estimator.RunConfig object. Will receive what is passed to Estimator as its config parameter, or a default value. Allows setting up things in your model_fn based on configuration such as num_ps_replicas, or model_dir. * Returns – tf.estimator.EstimatorSpec
model_dir – Directory to save model parameters, graph and etc. This can also be used to load checkpoints from the directory into an estimator to continue training a previously saved model. If PathLike object, the path will be resolved. If None, the model_dir in config will be used if set. If both are set, they must be same. If both are None, a temporary directory will be used.
config – estimator.RunConfig configuration object.
params – dict of hyper parameters that will be passed into model_fn. Keys are names of parameters, values are basic python types.
warm_start_from – Optional string filepath to a checkpoint or SavedModel to warm-start from, or a tf.estimator.WarmStartSettings object to fully configure warm-starting. If None, only TRAINABLE variables are warm-started. If the string filepath is provided instead of a tf.estimator.WarmStartSettings, then all variables are warm-started, and it is assumed that vocabularies and tf.Tensor names are unchanged.
- Raises:
ValueError – parameters of model_fn don’t match params.
ValueError – if this is called via a subclass and if that class overrides a member of Estimator.
- evaluate(input_fn, steps=None, hooks=None, checkpoint_path=None, name=None)[source]¶
Evaluates the model given evaluation data input_fn.
For each step, calls input_fn, which returns one batch of data. Evaluates until: - steps batches are processed, or - input_fn raises an end-of-input exception (tf.errors.OutOfRangeError or StopIteration).
- Parameters:
input_fn –
A function that constructs the input data for evaluation. See [Premade Estimators]( https://tensorflow.org/guide/premade_estimators#create_input_functions) for more information. The function should construct and return one of the following: * A tf.data.Dataset object: Outputs of Dataset object must be a
tuple (features, labels) with same constraints as below.
A tuple (features, labels): Where features is a tf.Tensor or a dictionary of string feature name to Tensor and labels is a Tensor or a dictionary of string label name to Tensor. Both features and labels are consumed by model_fn. They should satisfy the expectation of model_fn from inputs.
steps – Number of steps for which to evaluate model. If None, evaluates until input_fn raises an end-of-input exception.
hooks – List of tf.train.SessionRunHook subclass instances. Used for callbacks inside the evaluation call.
checkpoint_path – Path of a specific checkpoint to evaluate. If None, the latest checkpoint in model_dir is used. If there are no checkpoints in model_dir, evaluation is run with newly initialized Variables instead of ones restored from checkpoint.
name – Name of the evaluation if user needs to run multiple evaluations on different data sets, such as on training data vs test data. Metrics for different evaluations are saved in separate folders, and appear separately in tensorboard.
- Returns:
A dict containing the evaluation metrics specified in model_fn keyed by name, as well as an entry global_step which contains the value of the global step for which this evaluation was performed. For canned estimators, the dict contains the loss (mean loss per mini-batch) and the average_loss (mean loss per sample). Canned classifiers also return the accuracy. Canned regressors also return the label/mean and the prediction/mean.
- Raises:
ValueError – If steps <= 0.
- train(input_fn, hooks=None, steps=None, max_steps=None, saving_listeners=None)[source]¶
Trains a model given training data input_fn.
- Parameters:
input_fn –
A function that provides input data for training as minibatches. See [Premade Estimators]( https://tensorflow.org/guide/premade_estimators#create_input_functions)
for more information. The function should construct and return one of
- the following:
A tf.data.Dataset object: Outputs of Dataset object must be a tuple (features, labels) with same constraints as below.
A tuple (features, labels): Where features is a tf.Tensor or a dictionary of string feature name to Tensor and labels is a Tensor or a dictionary of string label name to Tensor. Both features and labels are consumed by model_fn. They should satisfy the expectation of model_fn from inputs.
hooks – List of tf.train.SessionRunHook subclass instances. Used for callbacks inside the training loop.
steps – Number of steps for which to train the model. If None, train forever or train until input_fn generates the tf.errors.OutOfRange error or StopIteration exception. steps works incrementally. If you call two times train(steps=10) then training occurs in total 20 steps. If OutOfRange or StopIteration occurs in the middle, training stops before 20 steps. If you don’t want to have incremental behavior please set max_steps instead. If set, max_steps must be None.
max_steps – Number of total steps for which to train model. If None, train forever or train until input_fn generates the tf.errors.OutOfRange error or StopIteration exception. If set, steps must be None. If OutOfRange or StopIteration occurs in the middle, training stops before max_steps steps. Two calls to train(steps=100) means 200 training iterations. On the other hand, two calls to train(max_steps=100) means that the second call will not do any iteration since first call did all 100 steps.
saving_listeners – list of CheckpointSaverListener objects. Used for callbacks that run immediately before or after checkpoint savings.
- Returns:
self, for chaining.
- Raises:
ValueError – If both steps and max_steps are not None.
ValueError – If either steps or max_steps <= 0.
- property feature_configs¶
- property model_config¶
- property eval_config¶
- property train_config¶
- property incr_save_config¶
- property export_config¶
- property embedding_parallel¶
- property saver_cls¶