Collaborative Filtering - API Reference¶
Auto-generated documentation for all collaborative filtering model classes.
Autoencoders¶
warprec.recommenders.collaborative_filtering_recommender.autoencoder.ease.EASE
¶
Bases: ItemSimRecommender
Implementation of EASE algorithm from Embarrassingly Shallow Autoencoders for Sparse Data 2019.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
The dictionary with the model params. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Argument for PyTorch nn.Module. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Keyword argument for PyTorch nn.Module. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
l2 |
float
|
The normalization value. |
Source code in warprec/recommenders/collaborative_filtering_recommender/autoencoder/ease.py
warprec.recommenders.collaborative_filtering_recommender.autoencoder.elsa.ELSA
¶
Bases: IterativeRecommender
Implementation of ELSA algorithm from "Scalable Linear Shallow Autoencoder for Collaborative Filtering" in RecSys 22.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
The dictionary with the model params. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Argument for PyTorch nn.Module. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Keyword argument for PyTorch nn.Module. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
n_dims |
int
|
The number of dimensions for the latent space. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
Source code in warprec/recommenders/collaborative_filtering_recommender/autoencoder/elsa.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
forward(x)
¶
Forward pass of ELSA. Computes (xAA^T - x)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Batch of user-item interactions [batch_size, n_items]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Predicted scores [batch_size, n_items]. |
Source code in warprec/recommenders/collaborative_filtering_recommender/autoencoder/elsa.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction in the form of X@B where B is a {item x item} similarity matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/autoencoder/elsa.py
warprec.recommenders.collaborative_filtering_recommender.autoencoder.cdae.CDAE
¶
Bases: IterativeRecommender
Implementation of CDAE algorithm from "Collaborative Denoising Auto-Encoders for Top-N Recommender Systems." in WSDM 2016.
This model learns latent representations by training a denoising autoencoder on corrupted user-item interaction vectors, incorporating a user-specific embedding to guide the reconstruction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The dimension of the user embeddings and the hidden layer. |
corruption |
float
|
The probability of dropout applied to the input layer (denoising). |
hid_activation |
str
|
The activation function for the hidden layer ('relu', 'tanh', 'sigmoid'). |
out_activation |
str
|
The activation function for the output layer ('relu', 'sigmoid'). |
loss_type |
str
|
The loss function to use for backpropagation ('bce', 'mse'). |
reg_weight |
float
|
The L2 regularization weight. |
weight_decay |
float
|
The value of weight decay used in the optimizer. |
batch_size |
int
|
The batch size used during training. |
epochs |
int
|
The number of training epochs. |
learning_rate |
float
|
The learning rate value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the loss_type is not supported. |
Source code in warprec/recommenders/collaborative_filtering_recommender/autoencoder/cdae.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
forward(user_history, user_indices, *args, **kwargs)
¶
Performs the forward pass of the CDAE model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_history
|
Tensor
|
The user-item interaction vector [batch_size, n_items]. |
required |
user_indices
|
Tensor
|
The user indices for the batch [batch_size]. |
required |
*args
|
Any
|
List of arguments. |
()
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The reconstructed interaction vector (logits) [batch_size, n_items]. |
Source code in warprec/recommenders/collaborative_filtering_recommender/autoencoder/cdae.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the the encoder and decoder modules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/autoencoder/cdae.py
warprec.recommenders.collaborative_filtering_recommender.autoencoder.macridvae.MacridVAE
¶
Bases: IterativeRecommender
Implementation of MacridVAE algorithm from Learning Disentangled Representations for Recommendation (NeurIPS 2019).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The embedding size of user and item. |
encoder_hidden_dims |
List[int]
|
The hidden dimensions of the encoder MLP. |
k_fac |
int
|
The number of macro concepts (K). |
tau |
float
|
The temperature for cosine similarity. |
corruption |
float
|
The input corruption rate. |
nogb |
bool
|
If True, use Softmax instead of Gumbel-Soft |
std |
float
|
The standard deviation for reparameterization. |
anneal_cap |
float
|
The maximum value for KL annealing. |
total_anneal_steps |
int
|
The number of annealing steps. |
reg_weight |
float
|
The L2 regularization weight. |
weight_decay |
float
|
The weight decay for optimizer. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
Source code in warprec/recommenders/collaborative_filtering_recommender/autoencoder/macridvae.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
forward(rating_matrix)
¶
Forward pass handling Macro-Disentanglement logic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rating_matrix
|
Tensor
|
(Batch, n_items) |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor, Tensor]
|
Tuple[Tensor, Tensor, Tensor]: A tuple containing: logits: (Batch, n_items) - Log probabilities of reconstruction z_mean: (Batch, K, D) z_log_var: (Batch, K, D) |
Source code in warprec/recommenders/collaborative_filtering_recommender/autoencoder/macridvae.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the the encoder and decoder modules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/autoencoder/macridvae.py
warprec.recommenders.collaborative_filtering_recommender.autoencoder.multidae.MultiDAE
¶
Bases: IterativeRecommender
Implementation of MultiDAE algorithm from Variational Autoencoders for Collaborative Filtering 2018.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
intermediate_dim |
int
|
Intermediate dimension size. |
latent_dim |
int
|
Latent dimension size. |
corruption |
float
|
The probability of dropout applied to the input layer (denoising). |
weight_decay |
float
|
The value of weight decay used in the optimizer. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
Source code in warprec/recommenders/collaborative_filtering_recommender/autoencoder/multidae.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
forward(rating_matrix)
¶
Forward pass with normalization and dropout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rating_matrix
|
Tensor
|
The input rating matrix. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The reconstructed rating matrix. |
Source code in warprec/recommenders/collaborative_filtering_recommender/autoencoder/multidae.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the the encoder and decoder modules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/autoencoder/multidae.py
warprec.recommenders.collaborative_filtering_recommender.autoencoder.multivae.MultiVAE
¶
Bases: IterativeRecommender
Implementation of MultiVAE algorithm from Variational Autoencoders for Collaborative Filtering 2018.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
intermediate_dim |
int
|
Intermediate dimension size. |
latent_dim |
int
|
Latent dimension size. |
corruption |
float
|
The probability of dropout applied to the input layer (denoising). |
weight_decay |
float
|
The value of weight decay used in the optimizer. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
anneal_cap |
float
|
Annealing cap for KL divergence. |
anneal_step |
int
|
Annealing step for KL divergence. |
Source code in warprec/recommenders/collaborative_filtering_recommender/autoencoder/multivae.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
forward(rating_matrix)
¶
Returns reconstruction and KL divergence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rating_matrix
|
Tensor
|
The input rating matrix. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor]
|
Tuple[Tensor, Tensor]: - Tensor: The reconstructed rating matrix. - Tensor: The KL divergence loss. |
Source code in warprec/recommenders/collaborative_filtering_recommender/autoencoder/multivae.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the the encoder and decoder modules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/autoencoder/multivae.py
warprec.recommenders.collaborative_filtering_recommender.autoencoder.sansa.SANSA
¶
Bases: ItemSimRecommender
Implementation of SANSA algorithm from "Scalable Approximate NonSymmetric Autoencoder forCollaborative Filtering" in RecSys 23.
This model implements a sparse approximate inversion of the Gram matrix.
It attempts to use scikit-sparse (CHOLMOD) for high-performance Cholesky
factorization. If not available, it falls back to scipy.sparse inversion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
The dictionary with the model params. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Argument for PyTorch nn.Module. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Keyword argument for PyTorch nn.Module. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
l2 |
float
|
The L2 regularization value. |
target_density |
float
|
The desired density of the weight matrix B. |
Source code in warprec/recommenders/collaborative_filtering_recommender/autoencoder/sansa.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction override to handle Sparse Matrix multiplication.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix. |
Source code in warprec/recommenders/collaborative_filtering_recommender/autoencoder/sansa.py
Graph-Based¶
warprec.recommenders.collaborative_filtering_recommender.graph_based.dgcf.DGCF
¶
Bases: IterativeRecommender, GraphRecommenderUtils
Implementation of DGCF algorithm from "Disentangled Graph Collaborative Filtering" (SIGIR 2020).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The embedding size of user and item. |
n_layers |
int
|
The number of graph convolution layers. |
n_factors |
int
|
The number of factors. |
n_iterations |
int
|
The number of routing steps. |
cor_weight |
float
|
The weight of correlation loss. |
reg_weight |
float
|
The L2 regularization weight. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If embedding size is not divisible by n_factors. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/dgcf.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
forward()
¶
Performs DGCF propagation using vectorized operations.
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/dgcf.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the learned embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/dgcf.py
warprec.recommenders.collaborative_filtering_recommender.graph_based.egcf.EGCF
¶
Bases: IterativeRecommender, GraphRecommenderUtils
Implementation of EGCF algorithm from "Simplify to the Limit! Embedding-Less Graph Collaborative Filtering for Recommender Systems" (TOIS 2024).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The embedding size of items. |
n_layers |
int
|
The number of propagation layers. |
ssl_lambda |
float
|
Weight for the Self-Supervised Learning (InfoNCE) loss. |
temperature |
float
|
Temperature parameter for InfoNCE loss. |
mode |
str
|
Propagation mode, either 'parallel' or 'alternating'. |
reg_weight |
float
|
Weight for the regularization loss. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the mode is not supported. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/egcf.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
forward()
¶
Forward pass of EGCF.
Generates user and item embeddings based on the selected mode.
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor]
|
Tuple[Tensor, Tensor]: The final user and item embeddings. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/egcf.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the learned embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/egcf.py
warprec.recommenders.collaborative_filtering_recommender.graph_based.esigcf.ESIGCF
¶
Bases: IterativeRecommender, GraphRecommenderUtils
Implementation of ESIGCF algorithm from Extremely Simplified but Intent-enhanced Graph Collaborative Filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The embedding size of items. |
n_layers |
int
|
The number of propagation layers. |
ssl_lambda |
float
|
Weight for SSL Intent Loss (User-Positive). |
can_lambda |
float
|
Weight for Candidate Loss (Positive-Generated). |
temperature |
float
|
Temperature for InfoNCE loss. |
reg_weight |
float
|
The L2 regularization weight. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/esigcf.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
forward()
¶
Forward pass of ESIGCF.
Steps performed
- Construct initial user embeddings from item embeddings using user_graph.
- Concatenate User and Item embeddings.
- Propagate through Full Graph with Tanh activation.
- Sum representations from all layers.
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/esigcf.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the learned embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/esigcf.py
warprec.recommenders.collaborative_filtering_recommender.graph_based.gcmc.GCMC
¶
Bases: IterativeRecommender, GraphRecommenderUtils
Implementation of GCMC algorithm from Graph Convolutional Matrix Completion (KDD 2018).
This model is a graph autoencoder for explicit feedback. It uses a graph convolutional encoder to learn user/item embeddings and a decoder to predict rating probabilities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The embedding size of user and item. |
reg_weight |
float
|
The L2 regularization weight. |
weight_decay |
float
|
The value of weight decay used in the optimizer. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of training epochs. |
learning_rate |
float
|
The learning rate value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the dataset does not have explicit rating. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/gcmc.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
forward(user, item)
¶
Forward pass for GCMC. Computes rating logits for given user-item pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
Tensor
|
The tensor containing the user indexes. |
required |
item
|
Tensor
|
The tensor containing the item indexes. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The raw logits for each rating class for each pair. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/gcmc.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the learned embeddings.
Returns the expected rating for each user-item pair, used for ranking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item} containing expected ratings. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/gcmc.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
propagate_embeddings()
¶
Performs the graph convolution to get final node embeddings.
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/gcmc.py
warprec.recommenders.collaborative_filtering_recommender.graph_based.lightccf.LightCCF
¶
Bases: IterativeRecommender, GraphRecommenderUtils
Implementation of LightCCF algorithm from "Unveiling Contrastive Learning’s Capability of Neighborhood Aggregation for Collaborative Filtering" (SIGIR 2025).
LightCCF introduces a Neighborhood Aggregation (NA) loss that brings users closer to all their interacted items while pushing them away from other positive pairs. It can operate with a simple Base Encoder (MF) or a GCN Encoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The embedding size of user and item. |
n_layers |
int
|
The number of graph convolution layers. If 0, uses Base Encoder (MF). |
alpha |
float
|
The weight for the Neighborhood Aggregation. |
temperature |
float
|
The temperature coefficient for InfoNCE. |
reg_weight |
float
|
The L2 regularization weight. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/lightccf.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
forward()
¶
Forward pass.
If n_layers > 0, performs LightGCN-style aggregation. If n_layers == 0, returns raw embeddings (MF encoder).
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor]
|
Tuple[Tensor, Tensor]: User and Item embeddings. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/lightccf.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the learned embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/lightccf.py
warprec.recommenders.collaborative_filtering_recommender.graph_based.lightgcl.LightGCL
¶
Bases: IterativeRecommender, GraphRecommenderUtils
Implementation of LightGCL algorithm from "LightGCL: Simple Yet Effective Graph Contrastive Learning for Recommendation" (ICLR 2023).
LightGCL utilizes Singular Value Decomposition (SVD) to construct a global contrastive view, which is contrasted with the local graph view (GCN) to enhance representation learning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The embedding size of user and item. |
n_layers |
int
|
The number of graph convolution layers. |
q |
int
|
The rank for SVD approximation. |
ssl_lambda |
float
|
Weight for contrastive loss. |
temperature |
float
|
Temperature for InfoNCE. |
dropout |
float
|
Dropout probability for the adjacency matrix. |
reg_weight |
float
|
The L2 regularization weight. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgcl.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | |
forward()
¶
Forward pass computing both GCN and SVD views.
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgcl.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the learned embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgcl.py
warprec.recommenders.collaborative_filtering_recommender.graph_based.lightgcn.LightGCN
¶
Bases: GraphRecommenderUtils, IterativeRecommender
Implementation of LightGCN algorithm from LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation (SIGIR 2020)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The embedding size of user and item. |
n_layers |
int
|
The number of graph convolution layers. |
reg_weight |
float
|
The L2 regularization weight. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgcn.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
forward()
¶
Forward pass of the LightGCN model for embedding propagation.
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor]
|
Tuple[Tensor, Tensor]: User and item embeddings after propagation. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgcn.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the learned embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgcn.py
warprec.recommenders.collaborative_filtering_recommender.graph_based.lightgcnpp.LightGCNpp
¶
Bases: IterativeRecommender, GraphRecommenderUtils
Implementation of LightGCN++ algorithm from Revisiting LightGCN: Unexpected Inflexibility, Inconsistency, and A Remedy Towards Improved Recommendation (RecSys 2024).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. Requires 'alpha', 'beta', 'gamma'. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The embedding size of user and item. |
n_layers |
int
|
The number of graph convolution layers. |
alpha |
float
|
The exponent for the target node degree in the normalization coefficient. |
beta |
float
|
The exponent for the source node degree in the normalization coefficient. |
gamma |
float
|
The coefficient balancing the initial embeddings (\(E^0\)) and the aggregated graph embeddings (\(E_{mean}\)). |
reg_weight |
float
|
The L2 regularization weight. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgcnpp.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
forward()
¶
Forward pass of LightGCN++ with custom pooling logic
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgcnpp.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the learned embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgcnpp.py
warprec.recommenders.collaborative_filtering_recommender.graph_based.lightgode.LightGODE
¶
Bases: IterativeRecommender, GraphRecommenderUtils
Implementation of LightGODE from "Do We Really Need Graph Convolution During Training? Light Post-Training Graph-ODE for Efficient Recommendation" (CIKM '24).
LightGODE skips graph convolution during training, optimizing embeddings directly via Alignment and Uniformity losses (like Matrix Factorization but with geometric losses). During inference, it applies a continuous Graph-ODE solver to inject high-order connectivity information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The embedding size of user and item. |
gamma |
float
|
The weight for the uniformity loss. |
t |
float
|
The time horizon for ODE integration. |
n_ode_steps |
int
|
The number of ODE integration steps during inference. |
reg_weight |
float
|
The L2 regularization weight. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgode.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
forward()
¶
Standard forward pass.
- If training: Returns raw ID embeddings (no convolution).
- If eval: Returns ODE-convolved embeddings (with caching).
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgode.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the learned embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgode.py
train(mode=True)
¶
Override train mode to clear cache when switching back to training.
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgode.py
warprec.recommenders.collaborative_filtering_recommender.graph_based.macrgcn.MACRGCN
¶
Bases: GraphRecommenderUtils, IterativeRecommender
Implementation of MACRGCN from Model-Agnostic Counterfactual Reasoning for Eliminating Popularity Bias in Recommender System (KDD 2021).
The model adds two auxiliary branches (user module, item module) to a standard LightGCN backbone and applies counterfactual inference at test time to remove the direct effect of item popularity on ranking scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
Dataset information (n_users, n_items, ...). |
required |
interactions
|
Interactions
|
Training interactions for adjacency matrix. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
Random seed. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
Uses pointwise loader with negatives for BCE training. |
|
embedding_size |
int
|
Embedding dimension. |
n_layers |
int
|
Number of LightGCN propagation layers. |
reg_weight |
float
|
L2 regularization weight. |
alpha |
float
|
Weight for item module loss L_I. |
beta |
float
|
Weight for user module loss L_U. |
c |
float
|
Counterfactual reference constant. |
user_mlp_hidden |
int
|
Hidden size for user module MLP. |
item_mlp_hidden |
int
|
Hidden size for item module MLP. |
neg_samples |
int
|
Negative samples per positive. |
batch_size |
int
|
Batch size. |
epochs |
int
|
Training epochs. |
learning_rate |
float
|
Learning rate. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/macrgcn.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
forward()
¶
LightGCN forward pass — propagate and average embeddings.
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor]
|
Tuple[Tensor, Tensor]: (user_embeddings, item_embeddings) after multi-layer graph convolution with mean pooling across layers. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/macrgcn.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Counterfactual inference — Eq. 9, Algorithm 1.
At test time the ranking score is
y_ui = y_k * sigma(y_i) * sigma(y_u) - c * sigma(y_i) * sigma(y_u) = (y_k - c) * sigma(y_i) * sigma(y_u)
This removes the Natural Direct Effect (NDE) of item popularity (Section 3.4, Eq. 10), ranking items by Total Indirect Effect (TIE).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
Batch of user indices. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
item_indices
|
Optional[Tensor]
|
Candidate item indices. If None, scores are computed for all items. |
None
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Debiased ranking scores [batch_size, n_items] or [batch_size, k] if item_indices provided. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/macrgcn.py
training_step(batch, batch_idx)
¶
Multi-task training with BCE losses on three branches.
Implements Eq. 7 (fusion) and Eq. 8 (multi-task loss): L = L_O + alpha * L_I + beta * L_U
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Any
|
Tuple of (user, item, rating) from pointwise loader. |
required |
batch_idx
|
int
|
Batch index. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Combined loss scalar. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/macrgcn.py
warprec.recommenders.collaborative_filtering_recommender.graph_based.mixrec.MixRec
¶
Bases: IterativeRecommender, GraphRecommenderUtils
Implementation of MixRec algorithm from "MixRec: Individual and Collective Mixing Empowers Data Augmentation for Recommender Systems" (WWW '25).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The embedding size of user and item. |
n_layers |
int
|
The number of LightGCN propagation layers. |
ssl_lambda |
float
|
Weight for Contrastive Loss. |
alpha |
float
|
Shape parameter for Beta distribution (for Individual Mixing). |
temperature |
float
|
Temperature for InfoNCE. |
reg_weight |
float
|
The L2 regularization weight. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/mixrec.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
forward()
¶
Standard LightGCN Forward pass to get encoded embeddings.
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/mixrec.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the learned embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/mixrec.py
warprec.recommenders.collaborative_filtering_recommender.graph_based.ngcf.NGCF
¶
Bases: IterativeRecommender, GraphRecommenderUtils
Implementation of NGCF algorithm from Neural Graph Collaborative Filtering (SIGIR 2019)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The embedding size of user and item. |
weight_size |
list[int]
|
List of hidden sizes for each layer. |
node_dropout |
float
|
Dropout rate for nodes in the adjacency matrix. |
message_dropout |
float
|
Dropout rate for messages/embeddings during propagation. |
reg_weight |
float
|
The L2 regularization weight. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/ngcf.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
forward()
¶
Forward pass of the NGCF model for embedding propagation.
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor]
|
Tuple[Tensor, Tensor]: User and item embeddings after propagation. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/ngcf.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the learned embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/ngcf.py
warprec.recommenders.collaborative_filtering_recommender.graph_based.paac.PAAC
¶
Bases: GraphRecommenderUtils, IterativeRecommender
Implementation of PAAC from "Popularity-Aware Alignment and Contrast for Mitigating Popularity Bias in Recommendation" (KDD 2024).
Popularity-Aware Alignment and Contrast (PAAC) for Mitigating Popularity Bias.
PAAC wraps a LightGCN encoder with the supervised alignment and re-weighted contrastive objectives defined in the paper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model hyperparameters (see PAACConfig). |
required |
info
|
dict
|
Dataset metadata (n_users, n_items, …). |
required |
interactions
|
Interactions
|
Training interactions used to build the graph and popularity counts. |
required |
*args
|
Any
|
Forwarded to parent constructors. |
()
|
seed
|
int
|
Random seed for reproducibility. |
42
|
**kwargs
|
Any
|
Forwarded to parent constructors. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
POS_NEG_LOADER — yields (user, pos_item, neg_item) triples. |
|
embedding_size |
int
|
Embedding dimensionality. |
n_layers |
int
|
LightGCN propagation depth. |
lambda1 |
float
|
Weight on the supervised alignment loss (λ₁). |
lambda2 |
float
|
Weight on the re-weighting contrastive loss (λ₂). |
temperature |
float
|
InfoNCE temperature τ. |
gamma |
float
|
Popular-vs-unpopular positive-sample weight γ (Eq. 7). |
beta |
float
|
Cross-group negative-sample weight β (Eq. 8/9). |
pop_ratio |
float
|
Fraction of batch items classified as popular per mini-batch. |
eps |
float
|
Noise scale for contrastive augmentation. |
reg_weight |
float
|
L2 regularization coefficient λ₃. |
batch_size |
int
|
Training batch size. |
epochs |
int
|
Maximum training epochs. |
learning_rate |
float
|
Adam learning rate. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/paac.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
forward(perturbed=False)
¶
LightGCN graph propagation with an optional perturbed view.
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/paac.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Score users against items using the learnt propagated embeddings.
Prediction score: s(u, i) = z_u^T h_i (dot product, Section 2.1)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
Batch of user indices [B]. |
required |
*args
|
Any
|
Ignored. |
()
|
item_indices
|
Optional[Tensor]
|
If None, scores all items [B, N]. Otherwise scores the provided candidates [B, K]. |
None
|
**kwargs
|
Any
|
Ignored. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Score matrix of shape [B, N] (full) or [B, K] (sampled). |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/paac.py
training_step(batch, batch_idx)
¶
Single training iteration following Algorithm 1 of the paper.
Computes the three-component loss (Eq. 11): L = L_rec + λ₁ * L_sa + λ₂ * L_cl + λ₃ * ||Θ||²
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Any
|
Tuple of (user, pos_item, neg_item) from POS_NEG_LOADER. |
required |
batch_idx
|
int
|
Batch index (unused). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Scalar total loss. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/paac.py
warprec.recommenders.collaborative_filtering_recommender.graph_based.popdcl.PopDCL
¶
Bases: GraphRecommenderUtils, IterativeRecommender
Implementation of PopDCL model from Popularity-aware Debiased Contrastive Loss for Collaborative Filtering (CIKM 2023).
Implements the full PopDCL model from Liu et al., CIKM 2023. The encoder is LightGCN (He et al., SIGIR 2020); the novelty is the loss function that simultaneously corrects: - Positive scores via M+(u,i): reduces the score of positive pairs that are likely false-positives due to popularity bias (Sections 3.3, Eq. 3–6). - Negative scores via M-(u,j): personalizes the debiased contrastive loss using a per-user false-negative probability omega+(u) (Section 3.4, Eq. 8–10).
Both corrections rely solely on item/user popularity (degree in the interaction graph), which is pre-computed from the training set and stored as a fixed buffer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters (see annotated attributes below). |
required |
info
|
dict
|
Dataset information dict containing 'n_users' and 'n_items'. |
required |
interactions
|
Interactions
|
Training interactions used to build the graph adjacency matrix and precompute popularity statistics. |
required |
*args
|
Any
|
Variable length argument list (forwarded to LightningModule). |
()
|
seed
|
int
|
Random seed for reproducibility. Default: 42. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
POS_NEG_LOADER – yields (user, pos_item, neg_item) triplets. The neg_item column is not used by the loss; in-batch negatives are derived from the pos_item column of each mini-batch (see Section 3.2). |
|
embedding_size |
int
|
Dimensionality of user/item embedding vectors. |
n_layers |
int
|
Number of LightGCN propagation layers. |
temperature |
float
|
Contrastive temperature parameter tau (Section 3.6). |
reg_weight |
float
|
L2 regularization coefficient lambda (Eq. 16). |
batch_size |
int
|
Training mini-batch size. |
epochs |
int
|
Number of training epochs. |
learning_rate |
float
|
Adam learning rate. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/popdcl.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | |
forward()
¶
LightGCN propagation: layer-wise mean pooling of embeddings.
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor]
|
Tuple[Tensor, Tensor]: (user_all_embeddings, item_all_embeddings). |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/popdcl.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Compute recommendation scores for the given users.
At inference time, scores are plain cosine similarities between the propagated user and item embeddings (no correction applied). ASSUMPTION: Corrections are applied only during training to debias the loss; the final embeddings are used directly for ranking (consistent with how BC_loss, DCL, HCL are evaluated — all use plain inner-product/cosine at test time).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
Batch of user IDs. |
required |
*args
|
Any
|
Unused positional arguments. |
()
|
item_indices
|
Optional[Tensor]
|
If None, scores against all items are returned. Otherwise, scores for the sampled item sub-set. |
None
|
**kwargs
|
Any
|
Unused keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Score matrix [batch_size, n_items] or [batch_size, n_samples]. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/popdcl.py
training_step(batch, batch_idx)
¶
One training iteration.
The standard WarpRec contrastive dataloader provides (user, pos_item, neg_item) triplets. neg_item is ignored here because PopDCL constructs negatives in-batch from the pos_item column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Any
|
Triplet (user [B], pos_item [B], neg_item [B]). |
required |
batch_idx
|
int
|
Current batch index. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Scalar training loss. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/popdcl.py
warprec.recommenders.collaborative_filtering_recommender.graph_based.recdcl.RecDCL
¶
Bases: GraphRecommenderUtils, IterativeRecommender
Implementation of RecDCL model from "RecDCL: Dual Contrastive Learning for Recommendation" (WWW 2024).
Implements the full RecDCL framework (Zhang et al., WWW 2024) which combines: - FCL objective (feature-wise CL): - UIBT: Barlow-Twins-style cross-correlation loss between user and item embeddings to eliminate inter-user/item redundancy (Eq. 5). - UUII: Polynomial-kernel uniformity loss applied within the user and item embedding matrices along the feature dimension (Eq. 6). - BCL objective (batch-wise CL): - Historical-embedding output augmentation inspired by SimSiam, using online and target networks with shared graph encoder (Eqs. 8–9).
The total training objective is (Eq. 10): L = L_UIBT + alpha * L_UUII + beta * L_BCL
The encoder is a 2-layer LightGCN (He et al., SIGIR 2020). Embeddings are L2-normalized before all loss computations (Algorithm 1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters (see annotated attributes below). |
required |
info
|
dict
|
Dataset information dict containing 'n_users' and 'n_items'. |
required |
interactions
|
Interactions
|
Training interactions used to build the graph adjacency matrix. |
required |
*args
|
Any
|
Variable length argument list (forwarded to LightningModule). |
()
|
seed
|
int
|
Random seed for reproducibility. Default: 42. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
POS_LOADER – yields (user, pos_item) pairs. RecDCL does not require negative sampling (Section 4.2 / Table 1). |
|
embedding_size |
int
|
Dimensionality of user/item embedding vectors (F). Best results at large F (2048); see Section D.7 / Figure 4. |
n_layers |
int
|
Number of LightGCN propagation layers. Default: 2. |
gamma |
float
|
Redundancy-reduction weight in UIBT (Eq. 5). Default: 0.01. |
alpha |
float
|
Coefficient for UUII loss in total objective (Eq. 10). Default: 0.2 (best for Beauty/Game; see Table 13 and Figure 5). |
beta |
float
|
Coefficient for BCL loss in total objective (Eq. 10). Default: 5 (best for Beauty/Yelp; see Table 13 and Figure 6). |
tau_momentum |
float
|
Momentum ratio for historical embedding blending in Eq. 8. Default: 0.1 (best for Beauty; Table 13 / Figure 8). |
poly_a |
float
|
Polynomial kernel coefficient a for UUII (Eq. 6). Default: 1. |
poly_c |
float
|
Polynomial kernel offset c for UUII (Eq. 6). Default: 1e-7. |
poly_e |
int
|
Polynomial kernel exponent e for UUII (Eq. 6). Default: 4. |
batch_size |
int
|
Training mini-batch size. Default 256 for Beauty, 1024 for Food/Game/Yelp (Appendix D.3). |
epochs |
int
|
Number of training epochs. |
learning_rate |
float
|
Adam learning rate. Default: 0.001 (Appendix D.3). |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/recdcl.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | |
forward()
¶
LightGCN propagation: layer-wise mean pooling of embeddings.
Implements the standard LightGCN forward pass used as the backbone encoder f_theta in RecDCL (Section 4.2).
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor]
|
Tuple[Tensor, Tensor]: (user_all_embeddings [n_users, F], item_all_embeddings [n_items+1, F]). |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/recdcl.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Compute recommendation scores for the given users.
At inference time, scores are computed as inner products between the propagated user and item embeddings. No contrastive corrections are applied — the FCL/BCL objectives are purely training-time regularizers.
Section 4.3: "we calculate the ranking score function by using the inner product between user and item representations."
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
Batch of user IDs [B]. |
required |
*args
|
Any
|
Unused positional arguments. |
()
|
item_indices
|
Optional[Tensor]
|
If None, scores against all items are returned [B, n_items]. Otherwise, scores for the sampled item sub-set [B, S]. |
None
|
**kwargs
|
Any
|
Unused keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Score matrix [B, n_items] or [B, S]. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/recdcl.py
training_step(batch, batch_idx)
¶
One training iteration executing all three RecDCL loss components.
Follows Algorithm 1 and Algorithm 2 from Appendix D.4: 1. Encode via LightGCN to obtain E_U and E_I. 2. L2-normalize embeddings (Algorithm 1 lines 4-5). 3. Compute L_UIBT (Eq. 5), L_UUII (Eq. 6), L_BCL (Eq. 9). 4. Combine with trade-off coefficients (Eq. 10). 5. Update historical embedding buffers for the next step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Any
|
Triplet (user [B], pos_item [B], neg_item [B]). neg_item is discarded — RecDCL is a negative-sampling-free method. |
required |
batch_idx
|
int
|
Current batch index. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Scalar training loss. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/recdcl.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | |
warprec.recommenders.collaborative_filtering_recommender.graph_based.rp3beta.RP3Beta
¶
Bases: ItemSimRecommender
Implementation of RP3Beta algorithm from Updatable, accurate, diverse, and scalable recommendations for interactive applications 2016.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
k |
int
|
Number of nearest neighbors. |
alpha |
float
|
The intensity of the normalization. |
beta |
float
|
The normalization value for the users connections. |
normalize |
bool
|
Wether or not to normalize the interactions. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/rp3beta.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
warprec.recommenders.collaborative_filtering_recommender.graph_based.sgcl.SGCL
¶
Bases: IterativeRecommender, GraphRecommenderUtils
Implementation of SGCL from "SGCL: Unifying Self-Supervised and Supervised Learning for Graph Recommendation" (RecSys '25).
SGCL unifies the recommendation and contrastive learning tasks into a single supervised contrastive loss function. It eliminates the need for data augmentation, negative sampling, and multi-task optimization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The embedding size of user and item. |
n_layers |
int
|
The number of graph convolution layers. |
temperature |
float
|
The temperature parameter for the contrastive loss. |
reg_weight |
float
|
The L2 regularization weight. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/sgcl.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
forward()
¶
Forward pass of SGCL (Standard LightGCN propagation).
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/sgcl.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the learned embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/sgcl.py
warprec.recommenders.collaborative_filtering_recommender.graph_based.simgcl.SimGCL
¶
Bases: IterativeRecommender, GraphRecommenderUtils
Implementation of SimGCL from "Are Graph Augmentations Necessary? Simple Graph Contrastive Learning for Recommendation" (SIGIR 2022).
SimGCL discards graph augmentations entirely and instead adds uniform random noise to node embeddings at each GCN layer to create contrastive views. Two independently perturbed views are generated per forward pass; an InfoNCE loss maximizes agreement between same-node representations across the two views while a BPR loss drives the recommendation task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The embedding size of user and item. |
n_layers |
int
|
The number of graph convolution layers. |
lambda_ |
float
|
Coefficient for the contrastive loss. |
eps |
float
|
L2 norm of the perturbation noise vectors. |
temperature |
float
|
Temperature for InfoNCE loss. |
reg_weight |
float
|
The L2 regularization weight. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/simgcl.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
forward(perturbed=False)
¶
Propagate embeddings through the LightGCN encoder.
When perturbed=True two independent noise-augmented views are
produced alongside the clean final embeddings.
SIMPLIFICATION: The paper states that E(0) (the raw ego embeddings)¶
is skipped in the final aggregation (Eq. 8). We follow this exactly:¶
E = (1/L) * sum_{l=1}^{L} E^(l).¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
perturbed
|
bool
|
If True, generates two noisy contrastive views. |
False
|
Returns:
| Type | Description |
|---|---|
Tuple[Tensor, Tensor, Optional[Tensor], Optional[Tensor]]
|
Tuple[Tensor, Tensor, Optional[Tensor], Optional[Tensor]]:
- user_final, item_final: clean aggregated embeddings
- user_cl, item_cl: None when perturbed=False; otherwise a tuple
of (view1_users, view1_items, view2_users, view2_items) packed
as two extra return values would break the interface, so we
return them via the instance attributes |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/simgcl.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the learned embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/simgcl.py
training_step(batch, batch_idx)
¶
Compute the joint BPR + CL + L2 loss.
Loss = L_rec + lambda * L_cl + reg_weight * L_reg (Eq. 1)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Any
|
Tuple of (user, pos_item, neg_item). |
required |
batch_idx
|
int
|
The current batch index. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The computed loss for the batch. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/simgcl.py
warprec.recommenders.collaborative_filtering_recommender.graph_based.simrec.SimRec
¶
Bases: IterativeRecommender
Implementation of SimRec from Graph-less Collaborative Filtering via Contrastive Knowledge Distillation (WWW 2023)
SimRec distills knowledge from a GCN teacher into a lightweight MLP student using prediction-level KD (L1), embedding-level contrastive KD (L2), and adaptive contrastive regularization (L3) to address over-smoothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model hyperparameters. |
required |
info
|
dict
|
Dataset metadata (n_users, n_items). |
required |
interactions
|
Interactions
|
Training user-item interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
Random seed. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
Uses POS_NEG_LOADER for BPR-style contrastive sampling of T2. |
|
embedding_size |
int
|
Dimensionality of embedding vectors. |
n_teacher_layers |
int
|
GCN propagation layers. |
n_student_layers |
int
|
MLP FC layers. |
teacher_reg_weight |
float
|
L2 weight for teacher pre-training. |
lambda1 |
float
|
Weight for prediction-level distillation loss L1. |
lambda2 |
float
|
Weight for embedding-level distillation loss L2. |
lambda3 |
float
|
Weight for adaptive contrastive regularization L3. |
lambda4 |
float
|
Weight for MLP weight-decay L4. |
tau1 |
float
|
Temperature for prediction-level distillation. |
tau2 |
float
|
Temperature for embedding-level distillation. |
tau3 |
float
|
Temperature for adaptive contrastive regularization. |
eps |
float
|
Epsilon for adaptive weight adjustment. |
batch_size_kd |
int
|
Number of KD samples |T1| per step. |
teacher_epochs |
int
|
Epochs to pre-train the GCN teacher. |
batch_size |
int
|
Mini-batch size |T2|. |
epochs |
int
|
Number of student training epochs. |
learning_rate |
float
|
Adam LR for student. |
teacher_learning_rate |
float
|
Adam LR for teacher. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/simrec.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 | |
forward(user_indices)
¶
Apply MLP student to user embeddings.
Eq 5 — h^(s)i = FC(h_bar^(s)_i)¶
This signature satisfies the Lightning/WarpRec abstract requirement. For item encoding use _encode_item; training_step calls both directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
User indices, shape [B]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Refined user embeddings, shape [B, d]. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/simrec.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Score users against items using the trained MLP student.
Eq 2 — y_{i,j} = h_i^T h_j, h_i = M-Embed(h_bar_i)¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
User indices, shape [batch_size]. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
item_indices
|
Optional[Tensor]
|
Optional item indices, shape [batch_size, k]. If None, scores all items. |
None
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Score tensor, shape [batch_size, n_items] or [batch_size, k]. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/simrec.py
training_step(batch, batch_idx)
¶
Combined teacher pre-training and student KD training.
Phase 1 (epochs 0..teacher_epochs-1): Only update the GCN teacher via BPR. Phase 2 (epochs teacher_epochs..total): Freeze teacher, update student with the full SimRec objective L^(s) = Lrec + lambda1L1 + lambda2L2 + lambda3L3 + lambda4L4.
Algorithm 1 — SimRec learning procedure¶
Eq 12 — L^(s) = Lrec + lambda1L1 + lambda2L2 + lambda3L3 + lambda4L4¶
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/simrec.py
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 | |
warprec.recommenders.collaborative_filtering_recommender.graph_based.sgl.SGL
¶
Bases: IterativeRecommender, GraphRecommenderUtils
Implementation of SGL algorithm from Self-supervised Graph Learning for Recommendation (SIGIR 2021)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The embedding size of user and item. |
n_layers |
int
|
The number of graph convolution layers. |
ssl_tau |
float
|
The temperature parameter for SSL loss. |
ssl_reg |
float
|
The weight for SSL loss. |
dropout |
float
|
The dropout rate for graph augmentation. |
aug_type |
str
|
The type of graph augmentation ('ED', 'ND', 'RW'). |
reg_weight |
float
|
The L2 regularization weight. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If aug_type is not one of the supported types. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/sgl.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
forward(adj, augment=False)
¶
Forward pass with optional augmentation logic.
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/sgl.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the learned embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/sgl.py
warprec.recommenders.collaborative_filtering_recommender.graph_based.ultragcn.UltraGCN
¶
Bases: IterativeRecommender, GraphRecommenderUtils
Implementation of UltraGCN algorithm from "UltraGCN: Ultra Simplification of Graph Convolutional Networks for Recommendation" (CIKM 2021).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The embedding size of user and item. |
w_lambda |
float
|
Weight for the User-Item Constraint Loss (L_C). |
w_gamma |
float
|
Weight for the Item-Item Constraint Loss (L_I). |
w_neg |
float
|
Weight for negative samples in the constraint loss. |
ii_k |
int
|
Number of neighbors (K) for the Item-Item graph construction. |
reg_weight |
float
|
The L2 regularization weight. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/ultragcn.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
forward()
¶
Forward pass just returns the embeddings.
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the learned embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/ultragcn.py
warprec.recommenders.collaborative_filtering_recommender.graph_based.xsimgcl.XSimGCL
¶
Bases: IterativeRecommender, GraphRecommenderUtils
Implementation of XSimGCL algorithm from XSimGCL: Towards Extremely Simple Graph Contrastive Learning for Recommendation (TKDE 2023).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The embedding size of user and item. |
n_layers |
int
|
The number of graph convolution layers. |
lambda_ |
float
|
Coefficient for contrastive loss. |
eps |
float
|
Perturbation noise scale |
temperature |
float
|
Temperature for InfoNCE loss. |
layer_cl |
int
|
Layer to pick for contrastive learning. |
reg_weight |
float
|
The L2 regularization weight. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/xsimgcl.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
forward(perturbed=False)
¶
Propagates embeddings through the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
perturbed
|
bool
|
If True, adds noise during propagation for CL. |
False
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Tuple[Tensor, Tensor, Optional[Tensor], Optional[Tensor]]: Tuple containing: |
Tensor
|
|
Optional[Tensor]
|
|
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/xsimgcl.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the learned embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/graph_based/xsimgcl.py
KNN¶
warprec.recommenders.collaborative_filtering_recommender.knn.itemknn.ItemKNN
¶
Bases: ItemSimRecommender
Implementation of ItemKNN algorithm from Amazon.com recommendations: item-to-item collaborative filtering 2003.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
k |
int
|
Number of nearest neighbors. |
similarity |
str
|
Similarity measure. |
Source code in warprec/recommenders/collaborative_filtering_recommender/knn/itemknn.py
warprec.recommenders.collaborative_filtering_recommender.knn.itemknntd.ItemKNNTD
¶
Bases: ItemKNN
Implementation of ItemKNN with Temporal Decay (ItemKNN-TD). from Time Weight Collaborative Filtering (CIKM 2005).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
k |
int
|
Number of nearest neighbors. |
similarity |
str
|
Similarity measure. |
beta |
float
|
The decay rate parameter. A higher beta means older interactions decay faster. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the timestamp column is not found in the dataset, as ItemKNNTD requires timestamps to compute temporal decay. |
Source code in warprec/recommenders/collaborative_filtering_recommender/knn/itemknntd.py
warprec.recommenders.collaborative_filtering_recommender.knn.userknn.UserKNN
¶
Bases: Recommender
Implementation of UserKNN algorithm from GroupLens: an open architecture for collaborative filtering of netnews 1994.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
k |
int
|
Number of nearest neighbors. |
similarity |
str
|
Similarity measure. |
Source code in warprec/recommenders/collaborative_filtering_recommender/knn/userknn.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction in the form of B@X where B is a {user x user} similarity matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/knn/userknn.py
warprec.recommenders.collaborative_filtering_recommender.knn.userknntd.UserKNNTD
¶
Bases: UserKNN
Implementation of UserKNN with Temporal Decay (UserKNN-TD). Adapted from Time Weight Collaborative Filtering (CIKM 2005).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
k |
int
|
Number of nearest neighbors. |
similarity |
str
|
Similarity measure. |
beta |
float
|
The decay rate parameter. A higher beta means older interactions decay faster. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the timestamp column is not found in the dataset, as UserKNNTD requires timestamps to compute temporal decay. |
Source code in warprec/recommenders/collaborative_filtering_recommender/knn/userknntd.py
Latent Factor¶
warprec.recommenders.collaborative_filtering_recommender.latent_factor.admmslim.ADMMSlim
¶
Bases: ItemSimRecommender
Implementation of ADMMSlim algorithm from ADMM SLIM: Sparse Recommendations for Many Users 2020.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
lambda_1 |
float
|
The first regularization parameter. |
lambda_2 |
float
|
The second regularization parameter. |
alpha |
float
|
The alpha parameter for the item means. |
rho |
float
|
The rho parameter for the ADMM algorithm. |
it |
int
|
The number of iterations for the ADMM algorithm. |
positive_only |
bool
|
Wether or not to keep the similarity matrix positive. |
center_columns |
bool
|
Wether or not to center the columns of the interactions. |
Source code in warprec/recommenders/collaborative_filtering_recommender/latent_factor/admmslim.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
warprec.recommenders.collaborative_filtering_recommender.latent_factor.bpr.BPR
¶
Bases: IterativeRecommender
Implementation of BPR algorithm from BPR: Bayesian Personalized Ranking from Implicit Feedback 2012
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The embedding size of user and item. |
reg_weight |
float
|
The L2 regularization weight. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
Source code in warprec/recommenders/collaborative_filtering_recommender/latent_factor/bpr.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
forward(user, item)
¶
Forward pass of the BPR model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
Tensor
|
The tensor containing the user indexes. |
required |
item
|
Tensor
|
The tensor containing the item indexes. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The predicted score for each pair of positive and negative items. |
Source code in warprec/recommenders/collaborative_filtering_recommender/latent_factor/bpr.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the learned embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/latent_factor/bpr.py
warprec.recommenders.collaborative_filtering_recommender.latent_factor.fism.FISM
¶
Bases: IterativeRecommender
Implementation of FISM model from FISM: Factored Item Similarity Models for Top-N Recommender Systems (KDD 2013).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The number of factors for item feature embeddings. |
alpha |
float
|
The alpha parameter, a value between 0 and 1, used in the similarity calculation. |
split_to |
int
|
Parameter for splitting items into chunks during prediction (for memory management). |
reg_weight |
float
|
The L2 regularization weight. |
batch_size |
int
|
The size of the batches used during training. |
epochs |
int
|
The number of training epochs. |
learning_rate |
float
|
The learning rate for the optimizer. |
Source code in warprec/recommenders/collaborative_filtering_recommender/latent_factor/fism.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
forward(user, item)
¶
Forward pass for calculating scores for specific user-item pairs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
Tensor
|
User indices. |
required |
item
|
Tensor
|
Item indices. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Predicted scores. |
Source code in warprec/recommenders/collaborative_filtering_recommender/latent_factor/fism.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the learned embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/latent_factor/fism.py
warprec.recommenders.collaborative_filtering_recommender.latent_factor.ials.iALS
¶
Bases: Recommender
Implementation of iALS model from "Revisiting the Performance of iALS on Item Recommendation Benchmarks" in RecSys 2022.
The paper revisits iALS for top-n recommendation using a binary
user-item matrix, an all-pairs unobserved loss weighted by alpha0,
and a frequency-scaled L2 regularizer controlled by nu.
The original implementation of iALS is described in "Collaborative Filtering for Implicit Feedback Datasets" in ICDM 2008, and optimizes a different confidence-weighted objective. The 2022 paper shows that the original iALS performs poorly on standard benchmarks, and that the modified iALS objective is competitive with state-of-the-art methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
The dictionary with the model params. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
factors |
int
|
Latent factor dimensionality. |
alpha0 |
float
|
Weight of the all-pairs unobserved loss term. |
reg |
float
|
L2 regularization weight (lambda). |
n_iterations |
int
|
Number of full ALS sweeps. |
nu |
float
|
Frequency scaling exponent for the regularizer. |
Source code in warprec/recommenders/collaborative_filtering_recommender/latent_factor/ials.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Compute predicted preference scores.
The paper uses the standard matrix-factorization score p_hat_ui = x_u^T y_i.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
Batch of user indices [batch_size]. |
required |
*args
|
Any
|
Additional positional arguments. |
()
|
item_indices
|
Optional[Tensor]
|
Optional item indices [batch_size, k] for sampled
evaluation. If |
None
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Score tensor [batch_size, n_items] or [batch_size, k]. |
Source code in warprec/recommenders/collaborative_filtering_recommender/latent_factor/ials.py
warprec.recommenders.collaborative_filtering_recommender.latent_factor.ials2008.iALS2008
¶
Bases: Recommender
Implementation of iALS model from "Collaborative Filtering for Implicit Feedback Datasets" in ICDM 2008.
Decomposes the user-item implicit feedback matrix into user-factor and item-factor matrices via confidence-weighted alternating least squares.
The model treats raw observations r_ui as indicators of preference (binary) and confidence (monotonic in r_ui), then minimizes a weighted squared-error objective with L2 regularization (Eq. 3).
Closed-form factor updates (Eq. 4 & 5) are computed in init, exploiting the sparsity trick Y^T C^u Y = Y^T Y + Y^T (C^u - I) Y to achieve O(f^2 N + f^3 m) per sweep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
The dictionary with the model params. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
factors |
int
|
Latent factor dimensionality. |
alpha |
float
|
Confidence scaling constant. |
reg |
float
|
L2 regularization weight (lambda). |
n_iterations |
int
|
Number of full ALS sweeps. |
confidence_type |
str
|
"linear" or "log". |
epsilon |
float
|
Epsilon for the log confidence variant. |
Source code in warprec/recommenders/collaborative_filtering_recommender/latent_factor/ials2008.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | |
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Compute predicted preference scores.
Sec. 5: p_hat_ui = x_u^T y_i
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
Batch of user indices [batch_size]. |
required |
*args
|
Any
|
Additional positional arguments. |
()
|
item_indices
|
Optional[Tensor]
|
Optional item indices [batch_size, k] for sampled
evaluation. If |
None
|
**kwargs
|
Any
|
Additional keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Score tensor [batch_size, n_items] or [batch_size, k]. |
Source code in warprec/recommenders/collaborative_filtering_recommender/latent_factor/ials2008.py
warprec.recommenders.collaborative_filtering_recommender.latent_factor.macrmf.MACRMF
¶
Bases: IterativeRecommender
Implementation of MACR model from Model-Agnostic Counterfactual Reasoning for Eliminating Popularity Bias in Recommender System (KDD 2021).
- Item module Y_i(I): captures the direct effect of item popularity on the ranking score via path I → Y.
- User module Y_u(U): captures user conformity (tendency to interact regardless of item-user match) via path U → Y.
During training the three branches are fused multiplicatively (Eq. 7) and supervised jointly with a multi-task BCE loss (Eq. 8).
During inference the counterfactual score (Eq. 9) subtracts the natural direct effect of item popularity, leaving only the total indirect effect through user-item matching (TIE = TE - NDE, Section 3.4).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
Dataset information dictionary (must contain n_users, n_items). |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
Random seed for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
Pointwise (user, item, rating) loader with negative sampling. |
|
embedding_size |
int
|
Dimension of user and item embeddings. |
alpha |
float
|
Weight for item-module auxiliary loss L_I (Eq. 8). |
beta |
float
|
Weight for user-module auxiliary loss L_U (Eq. 8). |
c |
float
|
Reference matching score for counterfactual inference (Eq. 9). |
reg_weight |
float
|
L2 regularization coefficient. |
batch_size |
int
|
Training batch size. |
neg_samples |
int
|
Number of negative samples per positive interaction. |
epochs |
int
|
Number of training epochs. |
learning_rate |
float
|
Adam learning rate. |
Source code in warprec/recommenders/collaborative_filtering_recommender/latent_factor/macrmf.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
forward(user, item)
¶
Compute per-branch scores and the fused training prediction.
Implements the three-branch fusion
ŷ_ui = ŷ_k * σ(ŷ_i) * σ(ŷ_u) — Eq. 7, Section 3.3
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
Tensor
|
User index tensor [batch_size]. |
required |
item
|
Tensor
|
Item index tensor [batch_size]. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Tensor, Tensor, Tensor]
|
tuple[Tensor, Tensor, Tensor]: y_hat_k: Raw MF dot-product matching score [batch_size]. y_hat_i: Raw item-module score [batch_size]. y_hat_u: Raw user-module score [batch_size]. |
Source code in warprec/recommenders/collaborative_filtering_recommender/latent_factor/macrmf.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Counterfactual debiased prediction (TIE-based ranking).
Implements Eq. 9 from Section 3.3: ŷ_cf = ŷ_k * σ(ŷ_i) * σ(ŷ_u) − c * σ(ŷ_i) * σ(ŷ_u)
This is the Total Indirect Effect (TIE = TE − NDE) which removes the Natural Direct Effect of item popularity from the ranking score, leaving only the user–item matching contribution (Section 3.4).
The hyperparameter c represents the reference status of ŷ_k when
user–item matching is blocked (i.e. K = K_{u,i}), typically the
mean matching score at reference embeddings (Section 3.4, Eq. 10).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
Batch of user indices [batch_size]. |
required |
*args
|
Any
|
Unused positional arguments. |
()
|
item_indices
|
Optional[Tensor]
|
Item indices for sampled evaluation [batch_size, pad_seq]. If None, full ranking over all items. |
None
|
**kwargs
|
Any
|
Unused keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Debiased ranking scores [batch_size, n_items] or [batch_size, pad_seq]. |
Source code in warprec/recommenders/collaborative_filtering_recommender/latent_factor/macrmf.py
training_step(batch, batch_idx)
¶
Single gradient step computing the MACR multi-task loss.
Loss function (Eq. 8, Section 3.3): L = L_O + α * L_I + β * L_U
where L_O, L_I, L_U are all binary cross-entropy losses.
L_O supervises the fused prediction ŷ_ui = ŷ_k * σ(ŷ_i) * σ(ŷ_u). L_I supervises the item-module output σ(ŷ_i) alone. L_U supervises the user-module output σ(ŷ_u) alone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
Any
|
Tuple of (user, item, rating) tensors. |
required |
batch_idx
|
int
|
Batch index (unused). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The total scalar loss. |
Source code in warprec/recommenders/collaborative_filtering_recommender/latent_factor/macrmf.py
warprec.recommenders.collaborative_filtering_recommender.latent_factor.slim.Slim
¶
Bases: ItemSimRecommender
Implementation of Slim model from Sparse Linear Methods for Top-N Recommender Systems 2011.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
The dictionary with the model params. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
interactions
|
Interactions
|
The training interactions. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
l1 |
float
|
The normalization value. |
alpha |
float
|
The alpha multiplication constant value. |
Source code in warprec/recommenders/collaborative_filtering_recommender/latent_factor/slim.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
Neural¶
warprec.recommenders.collaborative_filtering_recommender.neural.convncf.ConvNCF
¶
Bases: IterativeRecommender
Implementation of ConvNCF algorithm from Outer Product-based Neural Collaborative Filtering 2018.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
embedding_size |
int
|
The embedding size for users and items. |
cnn_channels |
List[int]
|
The list of output channels for each CNN layer. |
cnn_kernels |
List[int]
|
The list of kernel sizes for each CNN layer. |
cnn_strides |
List[int]
|
The list of stride sizes for each CNN layer. |
dropout_prob |
float
|
The dropout probability for the prediction layer. |
reg_weight |
float
|
The L2 regularization weight. |
weight_decay |
float
|
The value of weight decay used in the optimizer. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
Source code in warprec/recommenders/collaborative_filtering_recommender/neural/convncf.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
forward(user, item)
¶
Forward pass of the ConvNCF model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
Tensor
|
The tensor containing the user indexes. |
required |
item
|
Tensor
|
The tensor containing the item indexes. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The predicted score for each pair (user, item). |
Source code in warprec/recommenders/collaborative_filtering_recommender/neural/convncf.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the learned embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |
Source code in warprec/recommenders/collaborative_filtering_recommender/neural/convncf.py
warprec.recommenders.collaborative_filtering_recommender.neural.neumf.NeuMF
¶
Bases: IterativeRecommender
Implementation of NeuMF algorithm from Neural Collaborative Filtering 2017.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
*args
|
Any
|
Variable length argument list. |
()
|
seed
|
int
|
The seed to use for reproducibility. |
42
|
**kwargs
|
Any
|
Arbitrary keyword arguments. |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
DATALOADER_TYPE |
The type of dataloader used. |
|
mf_embedding_size |
int
|
The MF embedding size. |
mlp_embedding_size |
int
|
The MLP embedding size. |
mlp_hidden_size |
List[int]
|
The MLP hidden layer size list. |
mf_train |
bool
|
Wether or not to train MF embedding. |
mlp_train |
bool
|
Wether or not to train MLP embedding. |
dropout |
float
|
The dropout probability. |
reg_weight |
float
|
The L2 regularization weight. |
weight_decay |
float
|
The value of weight decay used in the optimizer. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of epochs. |
learning_rate |
float
|
The learning rate value. |
neg_samples |
int
|
The number of negative samples per positive interaction. |
Source code in warprec/recommenders/collaborative_filtering_recommender/neural/neumf.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
forward(user, item)
¶
Forward pass of the NeuMF model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
Tensor
|
The tensor containing the user indexes. |
required |
item
|
Tensor
|
The tensor containing the item indexes. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The predicted score for each pair (user, item). |
Source code in warprec/recommenders/collaborative_filtering_recommender/neural/neumf.py
predict(user_indices, *args, item_indices=None, **kwargs)
¶
Prediction using the learned embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
*args
|
Any
|
List of arguments. |
()
|
item_indices
|
Optional[Tensor]
|
The batch of item indices. If None, full prediction will be produced. |
None
|
**kwargs
|
Any
|
The dictionary of keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The score matrix {user x item}. |