KTUP¶
 Reference:
Yixin Cao et al. “Unifying Knowledge Graph Learning and Recommendation:Towards a Better Understanding of User Preferences.” in WWW 2019.
 Reference code:

class
recbole.model.knowledge_aware_recommender.ktup.
KTUP
(config, dataset)[source]¶ Bases:
recbole.model.abstract_recommender.KnowledgeRecommender
KTUP is a knowledgebased recommendation model. It adopts the strategy of multitask learning to jointly learn recommendation and KGrelated tasks, with the goal of understanding the reasons that a user interacts with an item. This method utilizes an attention mechanism to combine all preferences into a singlevector representation.

calculate_kg_loss
(interaction)[source]¶ 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

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

convert_to_one_hot
(indices, num_classes)[source]¶  Parameters
indices (Variable) – A vector containing indices, whose size is (batch_size,).
num_classes (Variable) – The number of classes, which would be the second dimension of the resulting onehot matrix.
 Returns
The onehot matrix of size (batch_size, num_classes).
 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

st_gumbel_softmax
(logits, temperature=1.0)[source]¶ Return the result of StraightThrough GumbelSoftmax Estimation. It approximates the discrete sampling via GumbelSoftmax trick and applies the biased ST estimator. In the forward propagation, it emits the discrete onehot result, and in the backward propagation it approximates the categorical distribution via smooth GumbelSoftmax distribution.
 Parameters
logits (Variable) – A unnormalized probability values, which has the size (batch_size, num_classes)
temperature (float) – A temperature parameter. The higher the value is, the smoother the distribution is.
 Returns
The sampled output, which has the property explained above.
 Return type
torch.Tensor

training
: bool¶
