beta_rec.models package¶
beta_rec.models.cmn module¶
-
class
beta_rec.models.cmn.
CollaborativeMemoryNetwork
(config, user_embeddings, item_embeddings, item_user_list, device)[source]¶ Bases:
torch.nn.modules.module.Module
CollaborativeMemoryNetwork Class.
-
class
beta_rec.models.cmn.
cmnEngine
(config, user_embeddings, item_embeddings, item_user_list)[source]¶ Bases:
beta_rec.models.torch_engine.ModelEngine
CMN Engine.
beta_rec.models.gmf module¶
-
class
beta_rec.models.gmf.
GMFEngine
(config)[source]¶ Bases:
beta_rec.models.torch_engine.ModelEngine
Engine for training & evaluating GMF model.
beta_rec.models.lightgcn module¶
-
class
beta_rec.models.lightgcn.
LightGCN
(config, norm_adj)[source]¶ Bases:
torch.nn.modules.module.Module
Model initialisation, embedding generation and prediction of NGCF.
-
class
beta_rec.models.lightgcn.
LightGCNEngine
(config)[source]¶ Bases:
beta_rec.models.torch_engine.ModelEngine
LightGCNEngine Class.
beta_rec.models.mf module¶
-
class
beta_rec.models.mf.
MF
(config)[source]¶ Bases:
torch.nn.modules.module.Module
A pytorch Module for Matrix Factorization.
-
class
beta_rec.models.mf.
MFEngine
(config)[source]¶ Bases:
beta_rec.models.torch_engine.ModelEngine
MFEngine Class.
beta_rec.models.mlp module¶
-
class
beta_rec.models.mlp.
MLPEngine
(config)[source]¶ Bases:
beta_rec.models.torch_engine.ModelEngine
Engine for training & evaluating GMF model.
beta_rec.models.narm module¶
-
class
beta_rec.models.narm.
NARM
(config)[source]¶ Bases:
torch.nn.modules.module.Module
Neural Attentive Session Based Recommendation Model Class.
Parameters: - n_items (int) – the number of items.
- hidden_size (int) – the hidden size of gru.
- embedding_dim (int) – the dimension of item embedding.
- batch_size (int) –
- n_layers (int) – the number of gru layers.
Initialize hidden layers.
-
class
beta_rec.models.narm.
NARMEngine
(config)[source]¶ Bases:
beta_rec.models.torch_engine.ModelEngine
Engine for training & evaluating NARM model.
-
predict
(user_profile, batch=1)[source]¶ Predict the next item given user profile.
Parameters: - user_profile (List) – Contains the item IDs of the events.
- batch (int) – Prediction batch size.
Returns: Prediction scores for selected items for every event of the batch.
Return type: preds (List)
-
beta_rec.models.ncf module¶
-
class
beta_rec.models.ncf.
NeuMFEngine
(config)[source]¶ Bases:
beta_rec.models.torch_engine.ModelEngine
Engine for training & evaluating GMF model.
beta_rec.models.ngcf module¶
-
class
beta_rec.models.ngcf.
NGCF
(config, norm_adj)[source]¶ Bases:
torch.nn.modules.module.Module
Model initialisation, embedding generation and prediction of NGCF.
-
forward
(norm_adj)[source]¶ Perform GNN function on users and item embeddings.
Parameters: norm_adj (torch sparse tensor) – the norm adjacent matrix of the user-item interaction matrix. Returns: processed user embeddings. i_g_embeddings (tensor): processed item embeddings. Return type: u_g_embeddings (tensor)
-
-
class
beta_rec.models.ngcf.
NGCFEngine
(config)[source]¶ Bases:
beta_rec.models.torch_engine.ModelEngine
NGCFEngine Class.
-
bpr_loss
(users, pos_items, neg_items)[source]¶ Bayesian Personalised Ranking (BPR) pairwise loss function.
Note that the sizes of pos_scores and neg_scores should be equal.
Parameters: - pos_scores (tensor) – Tensor containing predictions for known positive items.
- neg_scores (tensor) – Tensor containing predictions for sampled negative items.
Returns: loss.
-
beta_rec.models.pairwise_ngcf module¶
beta_rec.models.torch_engine module¶
-
class
beta_rec.models.torch_engine.
ModelEngine
(config)[source]¶ Bases:
object
Meta Engine for training & evaluating NCF model.
Note: Subclass should implement self.model!
-
bce_loss
(scores, ratings)[source]¶ Binary Cross-Entropy (BCE) pointwise loss, also known as log loss or logistic loss.
Parameters: - scores (tensor) – Tensor containing predictions for both positive and negative items.
- ratings (tensor) – Tensor containing ratings for both positive and negative items.
Returns: loss.
-
bpr_loss
(pos_scores, neg_scores)[source]¶ Bayesian Personalised Ranking (BPR) pairwise loss function.
Note that the sizes of pos_scores and neg_scores should be equal.
Parameters: - pos_scores (tensor) – Tensor containing predictions for known positive items.
- neg_scores (tensor) – Tensor containing predictions for sampled negative items.
Returns: loss.
-
beta_rec.models.triple2vec module¶
-
class
beta_rec.models.triple2vec.
Triple2vec
(config)[source]¶ Bases:
torch.nn.modules.module.Module
Triple2vec Class.
-
class
beta_rec.models.triple2vec.
Triple2vecEngine
(config)[source]¶ Bases:
beta_rec.models.torch_engine.ModelEngine
Engine for training Triple model.
beta_rec.models.vbcar module¶
-
class
beta_rec.models.vbcar.
VBCAR
(config)[source]¶ Bases:
torch.nn.modules.module.Module
VBCAR Class.
-
class
beta_rec.models.vbcar.
VBCAREngine
(config)[source]¶ Bases:
beta_rec.models.torch_engine.ModelEngine
Engine for training & evaluating GMF model.
beta_rec.models.vlml module¶
-
class
beta_rec.models.vlml.
VariableLengthMemoryLayer
(hops, emb_dim, device)[source]¶ Bases:
torch.nn.modules.module.Module
VariableLengthMemoryLayer Class.
-
apply_attention_memory
(memory, output_memory, query, memory_mask=None, maxlen=None)[source]¶ Apply attention memory.
:param : param memory: [batch size, max length, embedding size], typically Matrix M. :param : param output_memory: [batch size, max length, embedding size], typically Matrix C. :param : param query: [batch size, embed size], typically u. :param : param memory_mask: [batch size] dim Tensor, the length of each sequence if variable length. :param : param maxlen: int/Tensor, the maximum sequence padding length; if None it infers based on the max of
memory_mask.- :param : returns: AttentionOutput
output: [batch size, embedding size]. weight: [batch size, max length], the attention weights applied to
the output representation.
-
mask_mod
(inputs, mask_length, maxlen=None)[source]¶ Use a memory mask.
Apply a memory mask such that the values we mask result in being the minimum possible value we can represent with a float32.
Parameters: - inputs – [batch size, length], dtype=tf.float32.
- memory_mask – [batch_size] shape Tensor of ints indicating the length of inputs.
- maxlen – Sets the maximum length of the sequence; if None, inferred from inputs.
Returns: [batch size, length] dim Tensor with the mask applied.
-
Module contents¶
Models Module.