SimpleX

Reference:

Kelong Mao et al. “SimpleX: A Simple and Strong Baseline for Collaborative Filtering.” in CIKM 2021.

Reference code:

https://github.com/xue-pai/TwoToweRS

class recbole.model.general_recommender.simplex.SimpleX(config, dataset)[source]

Bases: recbole.model.abstract_recommender.GeneralRecommender

SimpleX is a simple, unified collaborative filtering model.

SimpleX presents a simple and easy-to-understand model. Its advantage lies in its loss function, which uses a larger number of negative samples and sets a threshold to filter out less informative samples, it also uses relative weights to control the balance of positive-sample loss and negative-sample loss.

We implement the model following the original author with a pairwise training mode.

calculate_loss(interaction)[source]

Data processing and call function forward(), return loss

To use SimpleX, a user must have a historical transaction record, a pos item and a sequence of neg items. Based on the RecBole framework, the data in the interaction object is ordered, so we can get the data quickly.

forward(user, pos_item, history_item, history_len, neg_item_seq)[source]

Get the loss

Parameters
  • user (torch.Tensor) – User’s id, shape: [user_num]

  • pos_item (torch.Tensor) – Positive item’s id, shape: [user_num]

  • history_item (torch.Tensor) – Id of historty item, shape: [user_num, max_history_len]

  • history_len (torch.Tensor) – History item’s length, shape: [user_num]

  • neg_item_seq (torch.Tensor) – Negative item seq’s id, shape: [user_num, neg_seq_len]

Returns

Loss, shape: []

Return type

torch.Tensor

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

get_UI_aggregation(user_e, history_item_e, history_len)[source]

Get the combined vector of user and historically interacted items

Parameters
  • user_e (torch.Tensor) – User’s feature vector, shape: [user_num, embedding_size]

  • history_item_e (torch.Tensor) – History item’s feature vector, shape: [user_num, max_history_len, embedding_size]

  • history_len (torch.Tensor) – User’s history length, shape: [user_num]

Returns

Combined vector of user and item sequences, shape: [user_num, embedding_size]

Return type

torch.Tensor

get_cos(user_e, item_e)[source]

Get the cosine similarity between user and item

Parameters
  • user_e (torch.Tensor) – User’s feature vector, shape: [user_num, embedding_size]

  • item_e (torch.Tensor) – Item’s feature vector, shape: [user_num, item_num, embedding_size]

Returns

Cosine similarity between user and item, shape: [user_num, item_num]

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