hopwise.model.knowledge_aware_recommender.ripplenet¶
- Reference:
Hongwei Wang et al. “RippleNet: Propagating User Preferences on the Knowledge Graph for Recommender Systems.” in CIKM 2018.
Classes¶
RippleNet is an knowledge enhanced matrix factorization model. |
Module Contents¶
- class hopwise.model.knowledge_aware_recommender.ripplenet.RippleNet(config, dataset)¶
Bases:
hopwise.model.abstract_recommender.KnowledgeRecommenderRippleNet is an knowledge enhanced matrix factorization model. The original interaction matrix of \(n_{users} \times n_{items}\) and related knowledge graph is set as model input, we carefully design the data interface and use ripple set to train and test efficiently. We just implement the model following the original author with a pointwise training mode.
- input_type¶
- LABEL¶
- embedding_size¶
- kg_weight¶
- reg_weight¶
- n_hop¶
- n_memory¶
- interaction_matrix¶
- kg¶
- user_dict¶
- ripple_set¶
- entity_embedding¶
- relation_embedding¶
- transform_matrix¶
- softmax¶
- sigmoid¶
- rec_loss¶
- l2_loss¶
- loss¶
- other_parameter_name = ['ripple_set']¶
- _build_ripple_set()¶
Get the normalized interaction matrix of users and items according to A_values. Get the ripple hop-wise ripple set for every user, w.r.t. their interaction history
- Returns:
ripple_set (dict)
- forward(interaction)¶
- _key_addressing()¶
Conduct reasoning for specific item and user ripple set
- Returns:
list of torch.cuda.FloatTensor n_hop * [batch_size, embedding_size]
- Return type:
o_list (dict -> torch.cuda.FloatTensor)
- calculate_loss(interaction)¶
Calculate the training loss for a batch data.
- Parameters:
interaction (Interaction) – Interaction class of the batch.
- Returns:
Training loss, shape: []
- Return type:
torch.Tensor
- predict(interaction)¶
Predict the scores between users and items.
- Parameters:
interaction (Interaction) – Interaction class of the batch.
- Returns:
Predicted scores for given users and items, shape: [batch_size]
- Return type:
torch.Tensor
- _key_addressing_full()¶
Conduct reasoning for specific item and user ripple set
- Returns:
- list of torch.cuda.FloatTensor
n_hop * [batch_size, n_item, embedding_size]
- Return type:
o_list (dict -> torch.cuda.FloatTensor)
- full_sort_predict(interaction)¶
Full sort prediction function. Given users, calculate the scores between users and all candidate items.
- Parameters:
interaction (Interaction) – Interaction class of the batch.
- Returns:
Predicted scores for given users and all candidate items, shape: [n_batch_users * n_candidate_items]
- Return type:
torch.Tensor