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

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

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.

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, embed=True)[source]

Embed the float feature columns

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

  • embed (bool) – Return the embedding of columns or just the columns itself. default=True

Returns

The result embedding tensor of float 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
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.

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.

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 spexific positions over a minibatch

type = 2