class, interactions_matrix)[source]

Holds the interactions of a set of users in an interactions sparse matrix

  • users (np.array) – users being represented.
  • interactions_matrix (scipy.sparse.csr_matrix) – user-item interactions matrix, where interactions_matrix[i] correspond to the interactions of users[i].


class, target_interactions_matrix=None)[source]

Represents a that iterates through the users interactions with items.

Indexing this dataset returns a UsersInteractions containing the interactions of the users in the index.

  • 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.


class, batch_size, negative_sampling=False, num_sampling_users=0, num_workers=0, collate_fn=None)[source]

A DataLoader similar to that handles RecommendationDataset and generate batches with negative sampling.

By default, if no collate_fn is provided, the BatchCollator.collate() will be used, and iterating through this dataloader will return a Batch at each iteration.

  • 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 UsersInteractions into a mini-batch.


class, items, indices, values, size)[source]

Represents a sparse batch of users and items interactions.

  • 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


class, negative_sampling=False)[source]

Collator of UsersInteractions. It collates the users interactions into multiple Batch based on batch_size.

  • batch_size (int) – number of samples per batch
  • negative_sampling (bool, optional) – whether to apply mini-batch based negative sampling or not.

Collates UsersInteractions into batches of size batch_size.

Parameters:users_interactions (UsersInteractions) – a UsersInteractions.
Returns:list of batches.
Return type:list[Batch]