DMF

Reference:

Hong-Jian Xue et al. “Deep Matrix Factorization Models for Recommender Systems.” in IJCAI 2017.

class recbole.model.general_recommender.dmf.DMF(config, dataset)[source]

Bases: recbole.model.abstract_recommender.GeneralRecommender

DMF is an neural network enhanced matrix factorization model. The original interaction matrix of \(n_{users} \times n_{items}\) is set as model input, we carefully design the data interface and use sparse tensor to train and test efficiently. We just implement the model following the original author with a pointwise training mode.

Note

Our implementation is a improved version which is different from the original paper. For a better performance and stability, we replace cosine similarity to inner-product when calculate final score of user’s and item’s embedding.

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

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.

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_item_embedding()[source]

Get all item’s embedding with history interaction matrix.

Considering the RAM of device, we use matrix multiply on sparse tensor for generalization.

Returns

The embedding tensor of all item, shape: [n_items, embedding_size]

Return type

torch.FloatTensor

get_user_embedding(user)[source]

Get a batch of user’s embedding with the user’s id and history interaction matrix.

Parameters

user (torch.LongTensor) – The input tensor that contains user’s id, shape: [batch_size, ]

Returns

The embedding tensor of a batch of user, shape: [batch_size, embedding_size]

Return type

torch.FloatTensor

input_type = 1
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