hopwise.model.knowledge_aware_recommender.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

Classes

Aggregator

Relational Path-aware Convolution Network

GraphConv

Graph Convolutional Network

KGIN

KGIN is a knowledge-aware recommendation model. It combines knowledge graph and the user-item interaction

Module Contents

class hopwise.model.knowledge_aware_recommender.kgin.Aggregator

Bases: torch.nn.Module

Relational Path-aware Convolution Network

forward(entity_emb, user_emb, latent_emb, relation_emb, edge_index, edge_type, interact_mat, disen_weight_att)
class hopwise.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)

Bases: torch.nn.Module

Graph Convolutional Network

embedding_size
n_hops
n_relations
n_users
n_factors
edge_index
edge_type
interact_mat
node_dropout_rate = 0.5
mess_dropout_rate = 0.1
ind
temperature
device
relation_embedding
disen_weight_att
convs
node_dropout
mess_dropout
edge_sampling(edge_index, edge_type, rate=0.5)
forward(user_emb, entity_emb, latent_emb)

Node dropout

calculate_cor_loss(tensors)
class hopwise.model.knowledge_aware_recommender.kgin.KGIN(config, dataset)

Bases: hopwise.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.

input_type
embedding_size
n_factors
context_hops
node_dropout_rate
mess_dropout_rate
ind
sim_decay
reg_weight
temperature
interact_mat
kg_graph
n_nodes
user_embedding
entity_embedding
latent_embedding
gcn
mf_loss
reg_loss
restore_user_e = None
restore_entity_e = None
get_edges(graph)
forward()
calculate_loss(interaction)

Calculate the training loss for a batch data of KG.

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

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