easyrec.models¶
easyrec.models.afm¶
- class easyrec.models.afm.AFM(*args, **kwargs)¶
Bases:
keras.engine.training.Model
Attentional Factorization Machines (AFM). Reference: Jun Xiao et al. Attentional Factorization Machines:Learning the Weight of Feature Interactions via Attention Networks. arXiv. 2017.
- Parameters
one_hot_feature_columns – List[CategoricalColumn] encodes one hot feature fields, such as sex_id.
k – Dimension of the second-order weights.
- call(inputs, training=None, mask=None)¶
Calls the model on new inputs.
In this case call just reapplies all ops in the graph to the new inputs (e.g. build a new computational graph from the provided inputs).
Note: This method should not be called directly. It is only meant to be overridden when subclassing tf.keras.Model. To call a model on an input, always use the __call__ method, i.e. model(inputs), which relies on the underlying call method.
- Parameters
inputs – Input tensor, or dict/list/tuple of input tensors.
training – Boolean or boolean scalar tensor, indicating whether to run the Network in training mode or inference mode.
mask – A mask or list of masks. A mask can be either a tensor or None (no mask).
- Returns
A tensor if there is a single output, or a list of tensors if there are more than one outputs.
easyrec.models.autoint¶
- class easyrec.models.autoint.AutoInt(*args, **kwargs)¶
Bases:
keras.engine.training.Model
Automatic Feature Interaction (AutoInt). Reference: AutoInt: Automatic Feature Interaction Learning via Self-Attentive Neural Networks. CIKM. 2019.
- Parameters
one_hot_feature_columns – List[CategoricalColumn] encodes one hot feature fields, such as sex_id.
multi_hot_feature_columns – List[CategoricalColumn] encodes multi hot feature fields, such as historical_item_ids.
dense_feature_columns – List[NumericalColumn] encodes numerical feature fields, such as age.
embedding_dimension – Dimension of embedded Column.
num_heads – Number of heads.
attention_qkv_dimension – Dimension of Query, Key and Value in self attention.
attention_output_dimension – Dimension of output in self attention.
- call(inputs, training=None, mask=None)¶
Calls the model on new inputs.
In this case call just reapplies all ops in the graph to the new inputs (e.g. build a new computational graph from the provided inputs).
Note: This method should not be called directly. It is only meant to be overridden when subclassing tf.keras.Model. To call a model on an input, always use the __call__ method, i.e. model(inputs), which relies on the underlying call method.
- Parameters
inputs – Input tensor, or dict/list/tuple of input tensors.
training – Boolean or boolean scalar tensor, indicating whether to run the Network in training mode or inference mode.
mask – A mask or list of masks. A mask can be either a tensor or None (no mask).
- Returns
A tensor if there is a single output, or a list of tensors if there are more than one outputs.
easyrec.models.dcn¶
- class easyrec.models.dcn.DCN(*args, **kwargs)¶
Bases:
keras.engine.training.Model
Deep & Cross Network (DCN). Reference: Ruoxi Wang et al. Deep & Cross Network for ad Click Predictions. ADKDD. 2017.
- Parameters
one_hot_feature_columns – List[CategoricalColumn] encodes one hot feature fields, such as sex_id.
multi_hot_feature_columns – List[CategoricalColumn] encodes multi hot feature fields, such as historical_item_ids.
dense_feature_columns – List[NumericalColumn] encodes numerical feature fields, such as age.
embedding_dimension – Dimension of embedded CategoricalColumn.
num_crosses – Number of crosses.
deep_units_list – Dimension of fully connected stack outputs in deep dense block.
deep_activation – Activation to use in deep dense block.
- call(inputs, training=None, mask=None)¶
Calls the model on new inputs.
In this case call just reapplies all ops in the graph to the new inputs (e.g. build a new computational graph from the provided inputs).
Note: This method should not be called directly. It is only meant to be overridden when subclassing tf.keras.Model. To call a model on an input, always use the __call__ method, i.e. model(inputs), which relies on the underlying call method.
- Parameters
inputs – Input tensor, or dict/list/tuple of input tensors.
training – Boolean or boolean scalar tensor, indicating whether to run the Network in training mode or inference mode.
mask – A mask or list of masks. A mask can be either a tensor or None (no mask).
- Returns
A tensor if there is a single output, or a list of tensors if there are more than one outputs.
easyrec.models.deep_crossing¶
- class easyrec.models.deep_crossing.DeepCrossing(*args, **kwargs)¶
Bases:
keras.engine.training.Model
Deep Crossing. Reference: Ying Shan et al. Deep Crossing: Web-Scale Modeling without Manually Crafted Combinatorial Features. KDD. 2016.
- Parameters
feature_columns – List[FeatureColumn] to directly feed into tf.keras.layers.DenseFeatures, which basically contains all feature fields.
num_residual_blocks – Number of residual blocks.
residual_units_list – Dimension of fully connected stack outputs in residual block.
residual_activation – Activation to use in residual block.
- call(inputs, training=None, mask=None)¶
Calls the model on new inputs.
In this case call just reapplies all ops in the graph to the new inputs (e.g. build a new computational graph from the provided inputs).
Note: This method should not be called directly. It is only meant to be overridden when subclassing tf.keras.Model. To call a model on an input, always use the __call__ method, i.e. model(inputs), which relies on the underlying call method.
- Parameters
inputs – Input tensor, or dict/list/tuple of input tensors.
training – Boolean or boolean scalar tensor, indicating whether to run the Network in training mode or inference mode.
mask – A mask or list of masks. A mask can be either a tensor or None (no mask).
- Returns
A tensor if there is a single output, or a list of tensors if there are more than one outputs.
easyrec.models.deepfm¶
- class easyrec.models.deepfm.DeepFM(*args, **kwargs)¶
Bases:
keras.engine.training.Model
Deep Factorization Machine (DeepFM). Reference: Huifeng Guo et al. DeepFM: A Factorization-Machine based Neural Network for CTR Prediction. arXiv. 2017.
- Parameters
one_hot_feature_columns – List[CategoricalColumn] encodes one hot feature fields, such as sex_id.
k – Dimension of the second-order weights.
deep_units_list – Dimension of fully connected stack outputs in deep block.
deep_activation – Activation to use in deep block.
- call(inputs, training=None, mask=None)¶
Calls the model on new inputs.
In this case call just reapplies all ops in the graph to the new inputs (e.g. build a new computational graph from the provided inputs).
Note: This method should not be called directly. It is only meant to be overridden when subclassing tf.keras.Model. To call a model on an input, always use the __call__ method, i.e. model(inputs), which relies on the underlying call method.
- Parameters
inputs – Input tensor, or dict/list/tuple of input tensors.
training – Boolean or boolean scalar tensor, indicating whether to run the Network in training mode or inference mode.
mask – A mask or list of masks. A mask can be either a tensor or None (no mask).
- Returns
A tensor if there is a single output, or a list of tensors if there are more than one outputs.
easyrec.models.dssm¶
- class easyrec.models.dssm.DSSM(*args, **kwargs)¶
Bases:
keras.engine.training.Model
Deep Structured Semantic Model (DSSM). Po-Sen Huang et al. Learning Deep Structured Semantic Models for Web Search using Clickthrough Data. CIKM. 2013.
- Parameters
user_feature_columns – List[FeatureColumn] to directly feed into tf.keras.layers.DenseFeatures, which basically contains user feature fields.
item_feature_columns – List[FeatureColumn] to directly feed into tf.keras.layers.DenseFeatures, which basically contains item feature fields.
user_units_list – Dimension of fully connected stack outputs in user dense block.
user_activation – Activation to use in user dense block.
item_units_list – Dimension of fully connected stack outputs in item dense block.
item_activation – Activation to use in item dense block.
score_function – Final output function to combine the user embedding and item embedding.
- call(inputs, training=None, mask=None)¶
Calls the model on new inputs.
In this case call just reapplies all ops in the graph to the new inputs (e.g. build a new computational graph from the provided inputs).
Note: This method should not be called directly. It is only meant to be overridden when subclassing tf.keras.Model. To call a model on an input, always use the __call__ method, i.e. model(inputs), which relies on the underlying call method.
- Parameters
inputs – Input tensor, or dict/list/tuple of input tensors.
training – Boolean or boolean scalar tensor, indicating whether to run the Network in training mode or inference mode.
mask – A mask or list of masks. A mask can be either a tensor or None (no mask).
- Returns
A tensor if there is a single output, or a list of tensors if there are more than one outputs.
easyrec.models.ffm¶
- class easyrec.models.ffm.FFM(*args, **kwargs)¶
Bases:
keras.engine.training.Model
Field-aware Factorization Machine (FFM). Reference: Yuchin Juan et al. Field-aware Factorization Machines for CTR Prediction. RecSys. 2016.
- Parameters
one_hot_feature_columns – List[CategoricalColumn] encodes one hot feature fields, such as sex_id.
k – Dimension of the second-order weights.
- call(inputs, training=None, mask=None)¶
Calls the model on new inputs.
In this case call just reapplies all ops in the graph to the new inputs (e.g. build a new computational graph from the provided inputs).
Note: This method should not be called directly. It is only meant to be overridden when subclassing tf.keras.Model. To call a model on an input, always use the __call__ method, i.e. model(inputs), which relies on the underlying call method.
- Parameters
inputs – Input tensor, or dict/list/tuple of input tensors.
training – Boolean or boolean scalar tensor, indicating whether to run the Network in training mode or inference mode.
mask – A mask or list of masks. A mask can be either a tensor or None (no mask).
- Returns
A tensor if there is a single output, or a list of tensors if there are more than one outputs.
easyrec.models.fm¶
- class easyrec.models.fm.FM(*args, **kwargs)¶
Bases:
keras.engine.training.Model
Factorization Machine (FM). Reference: Steffen Rendle. Factorization Machines. ICDM. 2010.
- Parameters
one_hot_feature_columns – List[CategoricalColumn] encodes one hot feature fields, such as sex_id.
k – Dimension of the second-order weights.
- call(inputs, training=None, mask=None)¶
Calls the model on new inputs.
In this case call just reapplies all ops in the graph to the new inputs (e.g. build a new computational graph from the provided inputs).
Note: This method should not be called directly. It is only meant to be overridden when subclassing tf.keras.Model. To call a model on an input, always use the __call__ method, i.e. model(inputs), which relies on the underlying call method.
- Parameters
inputs – Input tensor, or dict/list/tuple of input tensors.
training – Boolean or boolean scalar tensor, indicating whether to run the Network in training mode or inference mode.
mask – A mask or list of masks. A mask can be either a tensor or None (no mask).
- Returns
A tensor if there is a single output, or a list of tensors if there are more than one outputs.
easyrec.models.fnn¶
- class easyrec.models.fnn.FNN(*args, **kwargs)¶
Bases:
keras.engine.training.Model
Factorization-machine supported Neural Network (FNN). Reference: Weinan Zhang. Deep Learning over Multi-field Categorical Data – A Case Study on User Response Prediction. ECIR. 2016.
fm: Pretrained Factorization Machines. one_hot_feature_columns: List[CategoricalColumn] encodes one hot feature fields, such as sex_id. units_list: Dimension of fully connected stack outputs. activation: Activation to use.
- call(inputs, pretraining=True, training=None, mask=None)¶
Calls the model on new inputs.
In this case call just reapplies all ops in the graph to the new inputs (e.g. build a new computational graph from the provided inputs).
Note: This method should not be called directly. It is only meant to be overridden when subclassing tf.keras.Model. To call a model on an input, always use the __call__ method, i.e. model(inputs), which relies on the underlying call method.
- Parameters
inputs – Input tensor, or dict/list/tuple of input tensors.
training – Boolean or boolean scalar tensor, indicating whether to run the Network in training mode or inference mode.
mask – A mask or list of masks. A mask can be either a tensor or None (no mask).
- Returns
A tensor if there is a single output, or a list of tensors if there are more than one outputs.
easyrec.models.lr¶
- class easyrec.models.lr.LR(*args, **kwargs)¶
Bases:
keras.engine.training.Model
Logisitic Regression (LR).
- Parameters
feature_columns – List[FeatureColumn] to directly feed into tf.keras.layers.DenseFeatures, which basically contains all feature fields.
- call(inputs, training=None, mask=None)¶
Calls the model on new inputs.
In this case call just reapplies all ops in the graph to the new inputs (e.g. build a new computational graph from the provided inputs).
Note: This method should not be called directly. It is only meant to be overridden when subclassing tf.keras.Model. To call a model on an input, always use the __call__ method, i.e. model(inputs), which relies on the underlying call method.
- Parameters
inputs – Input tensor, or dict/list/tuple of input tensors.
training – Boolean or boolean scalar tensor, indicating whether to run the Network in training mode or inference mode.
mask – A mask or list of masks. A mask can be either a tensor or None (no mask).
- Returns
A tensor if there is a single output, or a list of tensors if there are more than one outputs.
easyrec.models.mlp¶
- class easyrec.models.mlp.MLP(*args, **kwargs)¶
Bases:
keras.engine.training.Model
Multi-layer Perceptron (MLP).
- Parameters
feature_columns – List[FeatureColumn] to directly feed into tf.keras.layers.DenseFeatures, which basically contains all feature fields.
units_list – Dimension of fully connected stack outputs.
activation – Activation to use.
- call(inputs, training=None, mask=None)¶
Calls the model on new inputs.
In this case call just reapplies all ops in the graph to the new inputs (e.g. build a new computational graph from the provided inputs).
Note: This method should not be called directly. It is only meant to be overridden when subclassing tf.keras.Model. To call a model on an input, always use the __call__ method, i.e. model(inputs), which relies on the underlying call method.
- Parameters
inputs – Input tensor, or dict/list/tuple of input tensors.
training – Boolean or boolean scalar tensor, indicating whether to run the Network in training mode or inference mode.
mask – A mask or list of masks. A mask can be either a tensor or None (no mask).
- Returns
A tensor if there is a single output, or a list of tensors if there are more than one outputs.
easyrec.models.mmoe¶
- class easyrec.models.mmoe.MMOE(*args, **kwargs)¶
Bases:
keras.engine.training.Model
Multi-gate Mixture-of-Experts. Reference: Jiaqi Ma et al. Modeling Task Relationships in Multi-task Learning with Multi-gate Mixture-of-Experts. KDD. 2018.
- Parameters
feature_columns – List[FeatureColumn] to directly feed into tf.keras.layers.DenseFeatures, which basically contains all feature fields.
num_experts – Number of experts.
expert_units_list – Dimension of fully connected stack outputs in expert dense block.
expert_activation – Activation to use in expert dense block.
num_towers – Number of towers (tasks).
tower_units_list – Dimension of fully connected stack outputs in tower dense block.
tower_activation – Activation to use in tower dense block.
- call(inputs, use_tower=0, training=None, mask=None)¶
Calls the model on new inputs.
In this case call just reapplies all ops in the graph to the new inputs (e.g. build a new computational graph from the provided inputs).
Note: This method should not be called directly. It is only meant to be overridden when subclassing tf.keras.Model. To call a model on an input, always use the __call__ method, i.e. model(inputs), which relies on the underlying call method.
- Parameters
inputs – Input tensor, or dict/list/tuple of input tensors.
training – Boolean or boolean scalar tensor, indicating whether to run the Network in training mode or inference mode.
mask – A mask or list of masks. A mask can be either a tensor or None (no mask).
- Returns
A tensor if there is a single output, or a list of tensors if there are more than one outputs.
easyrec.models.neumf¶
- class easyrec.models.neumf.NeuMF(*args, **kwargs)¶
Bases:
keras.engine.training.Model
Neural Matrix Factorization (NeuMF). Xiangnan He et al. Neural Factorization Machines for Sparse Predictive Analytics. SIGIR. 2017.
- Parameters
user_feature_column – CategoricalColumn to represent user_id.
item_feature_column – CategoricalColumn to represent item_id.
user_embedding_dimension – Dimension of user embedding.
item_embedding_dimension – Dimension of item embedding.
units_list – Dimension of fully connected stack outputs.
activation – Activation to use.
alpha – Tendency parameter for GMF, thus, 1 - alpha is used for MLP.
- call(inputs, training=None, mask=None)¶
Calls the model on new inputs.
In this case call just reapplies all ops in the graph to the new inputs (e.g. build a new computational graph from the provided inputs).
Note: This method should not be called directly. It is only meant to be overridden when subclassing tf.keras.Model. To call a model on an input, always use the __call__ method, i.e. model(inputs), which relies on the underlying call method.
- Parameters
inputs – Input tensor, or dict/list/tuple of input tensors.
training – Boolean or boolean scalar tensor, indicating whether to run the Network in training mode or inference mode.
mask – A mask or list of masks. A mask can be either a tensor or None (no mask).
- Returns
A tensor if there is a single output, or a list of tensors if there are more than one outputs.
easyrec.models.nfm¶
- class easyrec.models.nfm.NFM(*args, **kwargs)¶
Bases:
keras.engine.training.Model
Neural Factorization Machine (NFM). Xiangnan He et al. Neural Factorization Machines for Sparse Predictive Analytics. SIGIR. 2017.
- Parameters
one_hot_feature_columns – List[CategoricalColumn] encodes one hot feature fields, such as sex_id.
k – Dimension of the second-order weights.
- call(inputs, training=None, mask=None)¶
Calls the model on new inputs.
In this case call just reapplies all ops in the graph to the new inputs (e.g. build a new computational graph from the provided inputs).
Note: This method should not be called directly. It is only meant to be overridden when subclassing tf.keras.Model. To call a model on an input, always use the __call__ method, i.e. model(inputs), which relies on the underlying call method.
- Parameters
inputs – Input tensor, or dict/list/tuple of input tensors.
training – Boolean or boolean scalar tensor, indicating whether to run the Network in training mode or inference mode.
mask – A mask or list of masks. A mask can be either a tensor or None (no mask).
- Returns
A tensor if there is a single output, or a list of tensors if there are more than one outputs.
easyrec.models.pnn¶
- class easyrec.models.pnn.PNN(*args, **kwargs)¶
Bases:
keras.engine.training.Model
Product-based Neural Network (PNN). Reference: Yanru Qu et al. Product-based Neural Networks for User Response Prediction. ICDM. 2016.
- Parameters
one_hot_feature_columns – List[CategoricalColumn] encodes one hot feature fields, such as sex_id.
multi_hot_feature_columns – List[CategoricalColumn] encodes multi hot feature fields, such as historical_item_ids.
embedding_dimension – embedding dimension of each field.
use_inner_product – whether to use IPNN.
use_outer_product – whether to use OPNN.
units_list – Dimension of fully connected stack outputs.
activation – Activation to use.
- call(inputs, training=None, mask=None)¶
Calls the model on new inputs.
In this case call just reapplies all ops in the graph to the new inputs (e.g. build a new computational graph from the provided inputs).
Note: This method should not be called directly. It is only meant to be overridden when subclassing tf.keras.Model. To call a model on an input, always use the __call__ method, i.e. model(inputs), which relies on the underlying call method.
- Parameters
inputs – Input tensor, or dict/list/tuple of input tensors.
training – Boolean or boolean scalar tensor, indicating whether to run the Network in training mode or inference mode.
mask – A mask or list of masks. A mask can be either a tensor or None (no mask).
- Returns
A tensor if there is a single output, or a list of tensors if there are more than one outputs.
easyrec.models.wide_and_deep¶
- class easyrec.models.wide_and_deep.WideAndDeep(*args, **kwargs)¶
Bases:
keras.engine.training.Model
Wide & Deep. Reference: Heng-Tze Cheng et al. Wide & Deep Learning for Recommender Systems. RecSys. 2016.
- Parameters
one_hot_feature_columns – List[CategoricalColumn] encodes one hot feature fields, such as sex_id.
multi_hot_feature_columns – List[CategoricalColumn] encodes multi hot feature fields, such as historical_item_ids.
dense_feature_columns – List[NumericalColumn] encodes numerical feature fields, such as age.
embedding_dimension – Dimension of embedded CategoricalColumn.
deep_units_list – Dimension of fully connected stack outputs in deep dense block.
deep_activation – Activation to use in deep dense block.
- call(inputs, training=None, mask=None)¶
Calls the model on new inputs.
In this case call just reapplies all ops in the graph to the new inputs (e.g. build a new computational graph from the provided inputs).
Note: This method should not be called directly. It is only meant to be overridden when subclassing tf.keras.Model. To call a model on an input, always use the __call__ method, i.e. model(inputs), which relies on the underlying call method.
- Parameters
inputs – Input tensor, or dict/list/tuple of input tensors.
training – Boolean or boolean scalar tensor, indicating whether to run the Network in training mode or inference mode.
mask – A mask or list of masks. A mask can be either a tensor or None (no mask).
- Returns
A tensor if there is a single output, or a list of tensors if there are more than one outputs.
easyrec.models.xdeepfm¶
- class easyrec.models.xdeepfm.xDeepFM(*args, **kwargs)¶
Bases:
keras.engine.training.Model
Extreme Deep Factorization Machine (xDeepFM). Reference: Jianxun Lian et al. xDeepFM: Combining Explicit and Implicit Feature Interactions for Recommender Systems. KDD. 2018.
- Parameters
one_hot_feature_columns – List[CategoricalColumn] encodes one hot feature fields, such as sex_id.
multi_hot_feature_columns – List[CategoricalColumn] encodes multi hot feature fields, such as historical_item_ids.
k – Dimension of the second-order weights.
deep_units_list – Dimension of fully connected stack outputs in deep block.
deep_activation – Activation to use in deep block.
cross_units_list – Number of fields in the cross layer.
- call(inputs, training=None, mask=None)¶
Calls the model on new inputs.
In this case call just reapplies all ops in the graph to the new inputs (e.g. build a new computational graph from the provided inputs).
Note: This method should not be called directly. It is only meant to be overridden when subclassing tf.keras.Model. To call a model on an input, always use the __call__ method, i.e. model(inputs), which relies on the underlying call method.
- Parameters
inputs – Input tensor, or dict/list/tuple of input tensors.
training – Boolean or boolean scalar tensor, indicating whether to run the Network in training mode or inference mode.
mask – A mask or list of masks. A mask can be either a tensor or None (no mask).
- Returns
A tensor if there is a single output, or a list of tensors if there are more than one outputs.