hopwise.model.general_recommender.convncf¶
- Reference:
Xiangnan He et al. “Outer Product-based Neural Collaborative Filtering.” in IJCAI 2018.
- Reference code:
Classes¶
ConvNCFBPRLoss, based on Bayesian Personalized Ranking, |
|
ConvNCF is a a new neural network framework for collaborative filtering based on NCF. |
Module Contents¶
- class hopwise.model.general_recommender.convncf.ConvNCFBPRLoss[source]¶
Bases:
torch.nn.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()
- class hopwise.model.general_recommender.convncf.ConvNCF(config, dataset)[source]¶
Bases:
hopwise.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.
- input_type¶
- LABEL¶
- embedding_size¶
- cnn_channels¶
- cnn_kernels¶
- cnn_strides¶
- dropout_prob¶
- regs¶
- train_method¶
- pre_model_path¶
- cnn_layers¶
- predict_layers¶
- loss¶
- reg_loss()[source]¶
Calculate the L2 normalization loss of model parameters. Including embedding matrices and weight matrices of model.
- Returns:
The L2 Loss tensor. shape of [1,]
- Return type:
loss(torch.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
- 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