CFKG¶
- Reference:
Qingyao Ai et al. “Learning heterogeneous knowledge base embeddings for explainable recommendation.” in MDPI 2018.
- class recbole.model.knowledge_aware_recommender.cfkg.CFKG(config, dataset)[source]¶
Bases:
recbole.model.abstract_recommender.KnowledgeRecommender
CFKG 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.
- calculate_loss(interaction)[source]¶
Calculate the training loss for a batch data.
- Parameters
interaction (Interaction) – Interaction class of the batch.
- Returns
Training loss, shape: []
- Return type
torch.Tensor
- forward(user, item)[source]¶
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- input_type = 2¶
- predict(interaction)[source]¶
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
- training: bool¶
- class recbole.model.knowledge_aware_recommender.cfkg.InnerProductLoss[source]¶
Bases:
torch.nn.modules.module.Module
This is the inner-product loss used in CFKG for optimization.
- forward(anchor, positive, negative)[source]¶
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- training: bool¶