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

__init__(model_config, feature_configs, features, labels=None, is_training=False)[source]
property embedding_regularization
property kd
property l2_regularization
build_input_layer(model_config, feature_configs)[source]
abstract build_predict_graph()[source]
abstract build_loss_graph()[source]
abstract build_metric_graph(eval_config)[source]
abstract get_outputs()[source]
build_output_dict()[source]

For exporting: get standard output nodes.

build_feature_output_dict()[source]

For exporting: get output feature nodes.

build_rtp_output_dict()[source]

For exporting: get output nodes for RTP infering.

restore(ckpt_path, include_global_step=False, ckpt_var_map_path='', force_restore_shape_compatible=False)[source]

Restore variables from ckpt_path.

steps:
  1. list the variables in graph that need to be restored

  2. inspect checkpoint and find the variables that could restore from checkpoint substitute scope names in case necessary

  3. 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

classmethod create_class(name)
get_restore_filter()[source]

Get restore variable filter.

Returns

type of Filter in restore_filter.py scope_drop: type of ScopeDrop in restore_filter.py

Return type

filter

get_grouped_vars()[source]

Get grouped variables, each group will be optimized by a separate optimizer.

Returns

list of list of variables

Return type

grouped_vars

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: easy_rec.python.model.easy_rec_model.EasyRecModel

__init__(model_config, feature_configs, features, labels=None, is_training=False)[source]
build_rtp_output_dict()[source]

Forward tensor as rank_predict, which is a special node for RTP

build_loss_graph()[source]
build_metric_graph(eval_config)[source]
build_distribute_metric_graph(eval_config)[source]
classmethod create_class(name)
get_outputs()[source]

easy_rec.python.model.fm

class easy_rec.python.model.fm.FM(model_config, feature_configs, features, labels=None, is_training=False)[source]

Bases: easy_rec.python.model.rank_model.RankModel

__init__(model_config, feature_configs, features, labels=None, is_training=False)[source]
build_input_layer(model_config, feature_configs)[source]
build_predict_graph()[source]
classmethod create_class(name)

easy_rec.python.model.wide_and_deep

class easy_rec.python.model.wide_and_deep.WideAndDeep(model_config, feature_configs, features, labels=None, is_training=False)[source]

Bases: easy_rec.python.model.rank_model.RankModel

__init__(model_config, feature_configs, features, labels=None, is_training=False)[source]
build_input_layer(model_config, feature_configs)[source]
build_predict_graph()[source]
classmethod create_class(name)
get_grouped_vars()[source]

Group the vars into different optimization groups.

Each group will be optimized by a separate optimizer.

Returns

list of list of variables.

easy_rec.python.model.deepfm

class easy_rec.python.model.deepfm.DeepFM(model_config, feature_configs, features, labels=None, is_training=False)[source]

Bases: easy_rec.python.model.rank_model.RankModel

__init__(model_config, feature_configs, features, labels=None, is_training=False)[source]
build_input_layer(model_config, feature_configs)[source]
build_predict_graph()[source]
classmethod create_class(name)
build_feature_output_dict()[source]

For exporting: get output feature nodes.

easy_rec.python.model.multi_tower

class easy_rec.python.model.multi_tower.MultiTower(model_config, feature_configs, features, labels=None, is_training=False)[source]

Bases: easy_rec.python.model.rank_model.RankModel

__init__(model_config, feature_configs, features, labels=None, is_training=False)[source]
build_predict_graph()[source]
build_loss_graph()[source]
classmethod create_class(name)

easy_rec.python.model.dcn

class easy_rec.python.model.dcn.DCN(model_config, feature_configs, features, labels=None, is_training=False)[source]

Bases: easy_rec.python.model.rank_model.RankModel

__init__(model_config, feature_configs, features, labels=None, is_training=False)[source]
build_predict_graph()[source]
classmethod create_class(name)

easy_rec.python.model.autoint

class easy_rec.python.model.autoint.AutoInt(model_config, feature_configs, features, labels=None, is_training=False)[source]

Bases: easy_rec.python.model.rank_model.RankModel

__init__(model_config, feature_configs, features, labels=None, is_training=False)[source]
build_predict_graph()[source]
classmethod create_class(name)

easy_rec.python.model.dbmtl

class easy_rec.python.model.dbmtl.DBMTL(model_config, feature_configs, features, labels=None, is_training=False)[source]

Bases: easy_rec.python.model.multi_task_model.MultiTaskModel

__init__(model_config, feature_configs, features, labels=None, is_training=False)[source]
build_predict_graph()[source]
classmethod create_class(name)

easy_rec.python.model.multi_tower_bst

class easy_rec.python.model.multi_tower_bst.MultiTowerBST(model_config, feature_configs, features, labels=None, is_training=False)[source]

Bases: easy_rec.python.model.rank_model.RankModel

__init__(model_config, feature_configs, features, labels=None, is_training=False)[source]
dnn_net(net, dnn_units, name)[source]
attention_net(net, dim, cur_seq_len, seq_size, name)[source]
multi_head_att_net(id_cols, head_count, emb_dim, seq_len, seq_size)[source]
add_and_norm(net_1, net_2, emb_dim, name)[source]
bst(bst_fea, seq_size, head_count, name)[source]
build_predict_graph()[source]
classmethod create_class(name)

easy_rec.python.model.multi_tower_din

class easy_rec.python.model.multi_tower_din.MultiTowerDIN(model_config, feature_configs, features, labels=None, is_training=False)[source]

Bases: easy_rec.python.model.rank_model.RankModel

__init__(model_config, feature_configs, features, labels=None, is_training=False)[source]
din(dnn_config, deep_fea, name)[source]
build_predict_graph()[source]
classmethod create_class(name)

easy_rec.python.model.dssm

class easy_rec.python.model.dssm.DSSM(model_config, feature_configs, features, labels=None, is_training=False)[source]

Bases: easy_rec.python.model.easy_rec_model.EasyRecModel

__init__(model_config, feature_configs, features, labels=None, is_training=False)[source]
sim(user_emb, item_emb)[source]
norm(fea)[source]
build_predict_graph()[source]
build_loss_graph()[source]
build_metric_graph(eval_config)[source]
get_outputs()[source]
build_output_dict()[source]

For exporting: get standard output nodes.

classmethod create_class(name)
build_rtp_output_dict()[source]

For exporting: get output nodes for RTP infering.

easy_rec.python.model.mind

class easy_rec.python.model.mind.MIND(model_config, feature_configs, features, labels=None, is_training=False)[source]

Bases: easy_rec.python.model.easy_rec_model.EasyRecModel

__init__(model_config, feature_configs, features, labels=None, is_training=False)[source]
sim(user_emb, item_emb)[source]
norm(fea)[source]
build_predict_graph()[source]
build_loss_graph()[source]
build_metric_graph(eval_config)[source]
classmethod create_class(name)
get_outputs()[source]

easy_rec.python.model.multi_task_model

class easy_rec.python.model.multi_task_model.MultiTaskModel(model_config, feature_configs, features, labels=None, is_training=False)[source]

Bases: easy_rec.python.model.rank_model.RankModel

__init__(model_config, feature_configs, features, labels=None, is_training=False)[source]
build_metric_graph(eval_config)[source]

Build metric graph for multi task model.

build_loss_graph()[source]

Build loss graph for multi task model.

classmethod create_class(name)
get_outputs()[source]

easy_rec.python.model.mmoe

class easy_rec.python.model.mmoe.MMoE(model_config, feature_configs, features, labels=None, is_training=False)[source]

Bases: easy_rec.python.model.multi_task_model.MultiTaskModel

__init__(model_config, feature_configs, features, labels=None, is_training=False)[source]
build_predict_graph()[source]
classmethod create_class(name)

easy_rec.python.model.esmm

class easy_rec.python.model.esmm.ESMM(model_config, feature_configs, features, labels=None, is_training=False)[source]

Bases: easy_rec.python.model.multi_task_model.MultiTaskModel

__init__(model_config, feature_configs, features, labels=None, is_training=False)[source]
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)
get_outputs()[source]

Get model outputs.

Returns

The list of tensor names output by the model.

Return type

outputs

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: easy_rec.python.model.multi_task_model.MultiTaskModel

__init__(model_config, feature_configs, features, labels=None, is_training=False)[source]
build_predict_graph()[source]
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: tensorflow_estimator.python.estimator.estimator.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.

  • configestimator.RunConfig configuration object.

  • paramsdict 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.

property feature_configs
property model_config
property eval_config
property train_config
property export_config
export_checkpoint(export_path=None, serving_input_receiver_fn=None, checkpoint_path=None, mode='infer')[source]