Data¶
UsersInteractions¶
-
class
recoder.data.UsersInteractions(users, interactions_matrix)[source]¶ Holds the interactions of a set of users in an interactions sparse matrix
Parameters: - users (np.array) – users being represented.
- interactions_matrix (scipy.sparse.csr_matrix) – user-item interactions matrix, where
interactions_matrix[i]correspond to the interactions ofusers[i].
RecommendationDataset¶
-
class
recoder.data.RecommendationDataset(interactions_matrix, target_interactions_matrix=None)[source]¶ Represents a
torch.utils.data.Datasetthat iterates through the users interactions with items.Indexing this dataset returns a
UsersInteractionscontaining the interactions of the users in the index.Parameters: - interactions_matrix (scipy.sparse.csr_matrix) – the user-item interactions matrix.
- target_interactions_matrix (scipy.sparse.csr_matrix, optional) – the target user-item interactions matrix. Mainly used for evaluation, representing the items to recommend.
RecommendationDataLoader¶
-
class
recoder.data.RecommendationDataLoader(dataset, batch_size, negative_sampling=False, num_sampling_users=0, num_workers=0, collate_fn=None)[source]¶ A
DataLoadersimilar totorch.utils.data.DataLoaderthat handlesRecommendationDatasetand generate batches with negative sampling.By default, if no
collate_fnis provided, theBatchCollator.collate()will be used, and iterating through this dataloader will return aBatchat each iteration.Parameters: - dataset (RecommendationDataset) – dataset from which to load the data
- batch_size (int) – number of samples per batch
- negative_sampling (bool, optional) – whether to apply mini-batch based negative sampling or not.
- num_sampling_users (int, optional) – number of users to consider for mini-batch based negative sampling. This is useful for increasing the number of negative samples while keeping the batch-size small. If 0, then num_sampling_users will be equal to batch_size.
- num_workers (int, optional) – how many subprocesses to use for data loading.
- collate_fn (callable, optional) – A function that transforms a
UsersInteractionsinto a mini-batch.
Batch¶
-
class
recoder.data.Batch(users, items, indices, values, size)[source]¶ Represents a sparse batch of users and items interactions.
Parameters: - users (torch.LongTensor) – users that are in the batch
- items (torch.LongTensor) – items that are in the batch
- indices (torch.LongTensor) – the indices of the interactions in the sparse matrix
- values (torch.LongTensor) – the values of the interactions
- size (torch.Size) – the size of the sparse interactions matrix
BatchCollator¶
-
class
recoder.data.BatchCollator(batch_size, negative_sampling=False)[source]¶ Collator of
UsersInteractions. It collates the users interactions into multipleBatchbased onbatch_size.Parameters: - batch_size (int) – number of samples per batch
- negative_sampling (bool, optional) – whether to apply mini-batch based negative sampling or not.
-
collate(users_interactions)[source]¶ Collates
UsersInteractionsinto batches of sizebatch_size.Parameters: users_interactions (UsersInteractions) – a UsersInteractions.Returns: list of batches. Return type: list[Batch]