hopwise.model.knowledge_aware_recommender.cfkg¶
- Reference:
Qingyao Ai et al. “Learning heterogeneous knowledge base embeddings for explainable recommendation.” in MDPI 2018.
Classes¶
CFKG is a knowledge-based recommendation model, it combines knowledge graph and the user-item interaction |
Module Contents¶
- class hopwise.model.knowledge_aware_recommender.cfkg.CFKG(config, dataset)¶
Bases:
hopwise.model.abstract_recommender.KnowledgeRecommenderCFKG is a knowledge-based recommendation model, it combines knowledge graph and the user-item interaction graph to a new graph. In this graph, user, item and related attribute are viewed as entities, and the interaction between user and item and the link between item and attribute are viewed as relations. It define a new score function as follows:
\[d (u_i + r_{buy}, v_j)\]Note
In the original paper, CFKG puts recommender data (u-i interaction) and knowledge data (h-r-t) together for sampling and mix them for training. In this version, we sample recommender data and knowledge data separately, and put them together for training.
- input_type¶
- embedding_size¶
- user_embedding¶
- entity_embedding¶
- relation_embedding¶
- rec_loss¶
- forward(user, item)¶
- _get_rec_embedding(user, pos_item, neg_item)¶
- _get_kg_embedding(head, pos_tail, neg_tail, relation)¶
- _get_score(h_e, t_e, r_e)¶
- 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