KTUP¶

Reference:

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

Reference code:

https://github.com/TaoMiner/joint-kg-recommender

class recbole.model.knowledge_aware_recommender.ktup.KTUP(config, dataset)[source]

KTUP is a knowledge-based recommendation model. It adopts the strategy of multi-task learning to jointly learn recommendation and KG-related 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 single-vector 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 one-hot matrix.

Returns

The one-hot 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 Straight-Through Gumbel-Softmax Estimation. It approximates the discrete sampling via Gumbel-Softmax trick and applies the biased ST estimator. In the forward propagation, it emits the discrete one-hot result, and in the backward propagation it approximates the categorical distribution via smooth Gumbel-Softmax distribution.

Parameters
• logits (Variable) – A un-normalized 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
recbole.model.knowledge_aware_recommender.ktup.alignLoss(emb1, emb2, L1_flag=False)[source]
recbole.model.knowledge_aware_recommender.ktup.orthogonalLoss(rel_embeddings, norm_embeddings)[source]