KGIN

Reference:

Xiang Wang et al. “Learning Intents behind Interactions with Knowledge Graph for Recommendation.” in WWW 2021.

Reference code:

https://github.com/huangtinglin/Knowledge_Graph_based_Intent_Network

class recbole.model.knowledge_aware_recommender.kgin.Aggregator[source]

Bases: torch.nn.modules.module.Module

Relational Path-aware Convolution Network

forward(entity_emb, user_emb, latent_emb, relation_emb, edge_index, edge_type, interact_mat, disen_weight_att)[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
class recbole.model.knowledge_aware_recommender.kgin.GraphConv(embedding_size, n_hops, n_users, n_factors, n_relations, edge_index, edge_type, interact_mat, ind, tmp, device, node_dropout_rate=0.5, mess_dropout_rate=0.1)[source]

Bases: torch.nn.modules.module.Module

Graph Convolutional Network

calculate_cor_loss(tensors)[source]
edge_sampling(edge_index, edge_type, rate=0.5)[source]
forward(user_emb, entity_emb, latent_emb)[source]

node dropout

training: bool
class recbole.model.knowledge_aware_recommender.kgin.KGIN(config, dataset)[source]

Bases: recbole.model.abstract_recommender.KnowledgeRecommender

KGIN is a knowledge-aware recommendation model. It combines knowledge graph and the user-item interaction graph to a new graph called collaborative knowledge graph (CKG). This model explores intents behind a user-item interaction by using auxiliary item knowledge.

calculate_loss(interaction)[source]

Calculate the training loss for a batch data of KG. :param interaction: Interaction class of the batch. :type interaction: Interaction

Returns

Training loss, shape: []

Return type

torch.Tensor

forward()[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.

full_sort_predict(interaction)[source]

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

get_edges(graph)[source]
get_norm_inter_matrix(mode='bi')[source]
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