ConvNCF

Reference:

Xiangnan He et al. “Outer Product-based Neural Collaborative Filtering.” in IJCAI 2018.

Reference code:

https://github.com/duxy-me/ConvNCF

class recbole.model.general_recommender.convncf.ConvNCF(config, dataset)[source]

Bases: recbole.model.abstract_recommender.GeneralRecommender

ConvNCF is a a new neural network framework for collaborative filtering based on NCF. It uses an outer product operation above the embedding layer, which results in a semantic-rich interaction map that encodes pairwise correlations between embedding dimensions. 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.

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.

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

reg_loss()[source]

Calculate the L2 normalization loss of model parameters. Including embedding matrixes and weight matrixes of model.

Returns

The L2 Loss tensor. shape of [1,]

Return type

loss(torch.FloatTensor)

class recbole.model.general_recommender.convncf.ConvNCFBPRLoss[source]

Bases: torch.nn.modules.module.Module

ConvNCFBPRLoss, based on Bayesian Personalized Ranking,

Shape:
  • Pos_score: (N)

  • Neg_score: (N), same shape as the Pos_score

  • Output: scalar.

Examples:

>>> loss = ConvNCFBPRLoss()
>>> pos_score = torch.randn(3, requires_grad=True)
>>> neg_score = torch.randn(3, requires_grad=True)
>>> output = loss(pos_score, neg_score)
>>> output.backward()
forward(pos_score, neg_score)[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.