hopwise.model.general_recommender.ncl

Reference:

Zihan Lin*, Changxin Tian*, Yupeng Hou*, Wayne Xin Zhao. “Improving Graph Collaborative Filtering with Neighborhood-enriched Contrastive Learning.” in WWW 2022.

Classes

NCL

NCL is a neighborhood-enriched contrastive learning paradigm for graph collaborative filtering.

Module Contents

class hopwise.model.general_recommender.ncl.NCL(config, dataset)

Bases: hopwise.model.abstract_recommender.GeneralRecommender

NCL is a neighborhood-enriched contrastive learning paradigm for graph collaborative filtering. Both structural and semantic neighbors are explicitly captured as contrastive learning objects.

input_type
latent_dim
n_layers
reg_weight
ssl_temp
ssl_reg
hyper_layers
alpha
proto_reg
k
user_embedding
item_embedding
mf_loss
reg_loss
restore_user_e = None
restore_item_e = None
norm_adj_matrix
other_parameter_name = ['restore_user_e', 'restore_item_e']
user_centroids = None
user_2cluster = None
item_centroids = None
item_2cluster = None
e_step()
run_kmeans(x)

Run K-means algorithm to get k clusters of the input tensor x

get_ego_embeddings()

Get the embedding of users and items and combine to an embedding matrix.

Returns:

Tensor of the embedding matrix. Shape of [n_items+n_users, embedding_dim]

forward()
ProtoNCE_loss(node_embedding, user, item)
ssl_layer_loss(current_embedding, previous_embedding, user, item)
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

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