recbole.model.abstract_recommender

class recbole.model.abstract_recommender.AbstractRecommender[source]

Bases: torch.nn.modules.module.Module

Base class for all models

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

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

load_other_parameter(para)[source]
other_parameter()[source]
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
class recbole.model.abstract_recommender.AutoEncoderMixin[source]

Bases: object

This is a common part of auto-encoders. All the auto-encoder models should inherit this class, including CDAE, MacridVAE, MultiDAE, MultiVAE, RaCT and RecVAE. The base AutoEncoderMixin class provides basic dataset information and rating matrix function.

build_histroy_items(dataset)[source]
get_rating_matrix(user)[source]

Get a batch of user’s feature 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 user’s feature of a batch of user, shape: [batch_size, n_items]

Return type

torch.FloatTensor

class recbole.model.abstract_recommender.ContextRecommender(config, dataset)[source]

Bases: recbole.model.abstract_recommender.AbstractRecommender

This is a abstract context-aware recommender. All the context-aware model should implement this class. The base context-aware recommender class provide the basic embedding function of feature fields which also contains a first-order part of feature fields.

concat_embed_input_fields(interaction)[source]
double_tower_embed_input_fields(interaction)[source]

Embed the whole feature columns in a double tower way.

Parameters

interaction (Interaction) – The input data collection.

Returns

The embedding tensor of token sequence columns in the first part. torch.FloatTensor: The embedding tensor of float sequence columns in the first part. torch.FloatTensor: The embedding tensor of token sequence columns in the second part. torch.FloatTensor: The embedding tensor of float sequence columns in the second part.

Return type

torch.FloatTensor

embed_float_fields(float_fields)[source]

Embed the float feature columns

Parameters

float_fields (torch.FloatTensor) – The input dense tensor. shape of [batch_size, num_float_field]

Returns

The result embedding tensor of float columns.

Return type

torch.FloatTensor

embed_float_seq_fields(float_seq_fields, mode='mean')[source]

Embed the float feature columns

Parameters
  • float_seq_fields (torch.LongTensor) – The input tensor. shape of [batch_size, seq_len]

  • mode (str) – How to aggregate the embedding of feature in this field. default=mean

Returns

The result embedding tensor of token sequence columns.

Return type

torch.FloatTensor

embed_input_fields(interaction)[source]

Embed the whole feature columns.

Parameters

interaction (Interaction) – The input data collection.

Returns

The embedding tensor of token sequence columns. torch.FloatTensor: The embedding tensor of float sequence columns.

Return type

torch.FloatTensor

embed_token_fields(token_fields)[source]

Embed the token feature columns

Parameters

token_fields (torch.LongTensor) – The input tensor. shape of [batch_size, num_token_field]

Returns

The result embedding tensor of token columns.

Return type

torch.FloatTensor

embed_token_seq_fields(token_seq_fields, mode='mean')[source]

Embed the token feature columns

Parameters
  • token_seq_fields (torch.LongTensor) – The input tensor. shape of [batch_size, seq_len]

  • mode (str) – How to aggregate the embedding of feature in this field. default=mean

Returns

The result embedding tensor of token sequence columns.

Return type

torch.FloatTensor

input_type = 1
training: bool
type = 3
class recbole.model.abstract_recommender.GeneralRecommender(config, dataset)[source]

Bases: recbole.model.abstract_recommender.AbstractRecommender

This is a abstract general recommender. All the general model should implement this class. The base general recommender class provide the basic dataset and parameters information.

training: bool
type = 1
class recbole.model.abstract_recommender.KnowledgeRecommender(config, dataset)[source]

Bases: recbole.model.abstract_recommender.AbstractRecommender

This is a abstract knowledge-based recommender. All the knowledge-based model should implement this class. The base knowledge-based recommender class provide the basic dataset and parameters information.

training: bool
type = 4
class recbole.model.abstract_recommender.SequentialRecommender(config, dataset)[source]

Bases: recbole.model.abstract_recommender.AbstractRecommender

This is a abstract sequential recommender. All the sequential model should implement This class.

gather_indexes(output, gather_index)[source]

Gathers the vectors at the specific positions over a minibatch

get_attention_mask(item_seq, bidirectional=False)[source]

Generate left-to-right uni-directional or bidirectional attention mask for multi-head attention.

training: bool
type = 2