hopwise.model.knowledge_aware_recommender.pgpr¶
- Reference:
Xian et al. “Reinforcement Knowledge Graph Reasoning for Explainable Recommendation.” in SIGIR 2019.
- Reference code:
Classes¶
Module Contents¶
- class hopwise.model.knowledge_aware_recommender.pgpr.PGPR(config, dataset)¶
Bases:
hopwise.model.abstract_recommender.KnowledgeRecommender,hopwise.model.abstract_recommender.ExplainableRecommenderThis is a abstract knowledge-based recommender. All the knowledge-based model should implement this class. The base knowledge-based recommender class provide the basic dataset and parameters information.
- input_type¶
- user_num¶
- device¶
- topk¶
- state_history¶
- max_acts¶
- gamma¶
- action_dropout¶
- act_dim¶
- max_num_nodes¶
- weight_factor¶
- path_pattern¶
- beam_search_hop¶
- fix_scores_sorting_bug¶
- ui_relation_id¶
- graph_dict¶
- positives¶
- user_embedding¶
- entity_embedding¶
- relation_embedding¶
- embedding_size¶
- state_gen¶
- l1¶
- l2¶
- actor¶
- critic¶
- self_loop_embedding¶
- rid2relation¶
- node_type2emb¶
- u_p_scales¶
- patterns = []¶
- _batch_path = None¶
- _batch_curr_actions = None¶
- _batch_curr_state = None¶
- _batch_curr_reward = None¶
- _done = False¶
- saved_actions = []¶
- rewards = []¶
- entropy = []¶
- rng¶
- select_action(batch_state, batch_act_mask)¶
- update()¶
- forward(inputs)¶
- 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
- _has_pattern(path)¶
- _get_next_node_type(current_node_type, relation_id)¶
- reset(user)¶
- _batch_get_actions(batch_path, done)¶
- _get_actions(path, done)¶
- _batch_get_state(batch_path)¶
- _get_state(path)¶
- _batch_get_reward(batch_path)¶
- _get_reward(path)¶
- _is_done()¶
- batch_step(batch_act_idx)¶
- batch_action_mask(dropout)¶
- _batch_acts_to_masks(batch_acts)¶
- 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
- explain(interaction)¶
Support function used for case study.
- Parameters:
interaction – test interaction data
- Returns:
explanation results with columns: “user”, “item”, “score”, “path”
- Return type:
pd.Dataframe
- decode_path(path)¶
Decode the path into a string. Path decoding is specific to each model.
- Parameters:
path (list) – The path data.
- Returns:
The decoded path string.
- Return type:
str
- beam_search(users)¶
- collect_scores(users, paths, probs)¶