# DGCF¶

Reference:

Wang Xiang et al. “Disentangled Graph Collaborative Filtering.” in SIGIR 2020.

Reference code:

https://github.com/xiangwang1223/disentangled_graph_collaborative_filtering

class recbole.model.general_recommender.dgcf.DGCF(config, dataset)[source]

DGCF is a disentangled representation enhanced matrix factorization model. The interaction matrix of $$n_{users} \times n_{items}$$ is decomposed to $$n_{factors}$$ intent graph, we carefully design the data interface and use sparse tensor to train and test efficiently. We implement the model following the original author with a pairwise training mode.

build_matrix(A_values)[source]

Get the normalized interaction matrix of users and items according to A_values.

Construct the square matrix from the training data and normalize it using the laplace matrix.

Parameters

A_values (torch.cuda.FloatTensor) – (num_edge, n_factors)

$A_{hat} = D^{-0.5} \times A \times D^{-0.5}$
Returns

Sparse tensor of the normalized interaction matrix. shape: (num_edge, n_factors)

Return type

torch.cuda.FloatTensor

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

create_cor_loss(cor_u_embeddings, cor_i_embeddings)[source]

Calculate the correlation loss for a sampled users and items.

Parameters
• cor_u_embeddings (torch.cuda.FloatTensor) – (cor_batch_size, n_factors)

• cor_i_embeddings (torch.cuda.FloatTensor) – (cor_batch_size, n_factors)

Returns

correlation loss.

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

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
recbole.model.general_recommender.dgcf.sample_cor_samples(n_users, n_items, cor_batch_size)[source]

This is a function that sample item ids and user ids.

Parameters
• n_users (int) – number of users in total

• n_items (int) – number of items in total

• cor_batch_size (int) – number of id to sample

Returns

cor_users, cor_items. The result sampled ids with both as cor_batch_size long.

Return type

list

Note

We have to sample some embedded representations out of all nodes. Because we have no way to store cor-distance for each pair.