Sequential - API Reference¶
Auto-generated documentation for sequential recommender model classes.
warprec.recommenders.sequential_recommender.caser.Caser
¶
Bases: IterativeRecommender, SequentialRecommenderUtils
Implementation of Caser algorithm from "Personalized Top-N Sequential Recommendation via Convolutional Sequence Embedding" in WSDM 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 dimension of the item and user embeddings. |
n_h |
int
|
The number of horizontal filters. |
n_v |
int
|
The number of vertical filters. |
dropout_prob |
float
|
The probability of dropout for the fully connected 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 during training. |
epochs |
int
|
The number of training epochs. |
learning_rate |
float
|
The learning rate value. |
neg_samples |
int
|
The number of negative samples. |
max_seq_len |
int
|
The maximum length of sequences. |
Source code in warprec/recommenders/sequential_recommender/caser.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 | |
forward(user, item_seq)
¶
Forward pass of the Caser model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user
|
Tensor
|
The user ID for each sequence [batch_size,]. |
required |
item_seq
|
Tensor
|
Padded sequences of item IDs [batch_size, max_seq_len]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The final sequence output embedding [batch_size, embedding_size]. |
Source code in warprec/recommenders/sequential_recommender/caser.py
predict(user_indices, user_seq, *args, item_indices=None, **kwargs)
¶
Prediction using the learned session embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
user_seq
|
Tensor
|
Padded sequences of item IDs for users to predict for. |
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/sequential_recommender/caser.py
warprec.recommenders.sequential_recommender.fossil.FOSSIL
¶
Bases: IterativeRecommender, SequentialRecommenderUtils
Implementation of FOSSIL algorithm from "Fusing Similarity Models with Markov Chains for Sparse Sequential Recommendation." in ICDM 2016.
FOSSIL uses similarity of the items as main purpose and uses high MC as a way of sequential preference improve of ability of sequential recommendation.
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 dimension of the item embeddings. |
order_len |
int
|
The number of last items to consider for high-order Markov chains. |
alpha |
float
|
The parameter for calculating similarity. |
reg_weight |
float
|
The L2 regularization weight. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of training epochs. |
learning_rate |
float
|
The learning rate value. |
neg_samples |
int
|
The number of negative samples. |
max_seq_len |
int
|
The maximum length of sequences. |
Source code in warprec/recommenders/sequential_recommender/fossil.py
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 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 | |
forward(user_id, item_seq, item_seq_len)
¶
Forward pass of the FOSSIL model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
Tensor
|
User IDs for each sequence [batch_size,]. |
required |
item_seq
|
Tensor
|
Padded sequences of item IDs [batch_size, max_seq_len]. |
required |
item_seq_len
|
Tensor
|
Actual lengths of sequences [batch_size,]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The combined embedding for prediction [batch_size, embedding_size]. |
Source code in warprec/recommenders/sequential_recommender/fossil.py
predict(user_indices, user_seq, seq_len, *args, item_indices=None, **kwargs)
¶
Prediction using the learned session embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
The batch of user indices. |
required |
user_seq
|
Tensor
|
Padded sequences of item IDs for users to predict for. |
required |
seq_len
|
Tensor
|
Actual lengths of these sequences, before padding. |
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/sequential_recommender/fossil.py
warprec.recommenders.sequential_recommender.gru4rec.GRU4Rec
¶
Bases: IterativeRecommender, SequentialRecommenderUtils
Implementation of GRU4Rec algorithm from "Improved Recurrent Neural Networks for Session-based Recommendations." in DLRS 2016.
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 dimension of the item embeddings. |
hidden_size |
int
|
The number of features in the hidden state of the GRU. |
num_layers |
int
|
The number of recurrent layers. |
dropout_prob |
float
|
The probability of dropout for the embeddings. |
reg_weight |
float
|
The L2 regularization weight. |
weight_decay |
float
|
The value of weight decay used in optimizer. |
batch_size |
int
|
The batch size used for training. |
epochs |
int
|
The number of training epochs. |
learning_rate |
float
|
The learning rate value. |
neg_samples |
int
|
The number of negative samples. |
max_seq_len |
int
|
The maximum length of sequences. |
Source code in warprec/recommenders/sequential_recommender/gru4rec.py
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 | |
forward(item_seq, item_seq_len)
¶
Forward pass of the GRU4Rec model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_seq
|
Tensor
|
Padded sequences of item IDs [batch_size, max_seq_len]. |
required |
item_seq_len
|
Tensor
|
Actual lengths of sequences [batch_size,]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The embedding of the predicted item (last session state) [batch_size, embedding_size]. |
Source code in warprec/recommenders/sequential_recommender/gru4rec.py
predict(user_seq, seq_len, *args, item_indices=None, **kwargs)
¶
Prediction using the learned session embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_seq
|
Tensor
|
Padded sequences of item IDs for users to predict for. |
required |
seq_len
|
Tensor
|
Actual lengths of these sequences, before padding. |
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/sequential_recommender/gru4rec.py
warprec.recommenders.sequential_recommender.narm.NARM
¶
Bases: IterativeRecommender, SequentialRecommenderUtils
Implementation of NARM algorithm from "Neural Attentive Session-based Recommendation." in CIKM 2017.
NARM explores a hybrid encoder with an attention mechanism to model the user’s sequential behavior (Global Encoder) and capture the user’s main purpose in the current session (Local Encoder).
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 dimension of the item embeddings. |
hidden_size |
int
|
The number of features in the hidden state of the GRU. |
n_layers |
int
|
The number of recurrent layers in the GRU. |
hidden_dropout_prob |
float
|
Dropout probability for the item embeddings. |
attn_dropout_prob |
float
|
Dropout probability for the hybrid session representation. |
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. |
neg_samples |
int
|
The number of negative samples. |
max_seq_len |
int
|
The maximum length of sequences. |
Source code in warprec/recommenders/sequential_recommender/narm.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 | |
forward(item_seq, item_seq_len)
¶
Forward pass of the NARM model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_seq
|
Tensor
|
Padded sequences of item IDs [batch_size, max_seq_len]. |
required |
item_seq_len
|
Tensor
|
Actual lengths of sequences. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The hybrid session representation [batch_size, embedding_size]. |
Source code in warprec/recommenders/sequential_recommender/narm.py
predict(user_seq, seq_len, *args, item_indices=None, **kwargs)
¶
Prediction using the learned session embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_seq
|
Tensor
|
Padded sequences of item IDs for users to predict for. |
required |
seq_len
|
Tensor
|
Actual lengths of these sequences, before padding. |
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/sequential_recommender/narm.py
warprec.recommenders.sequential_recommender.bert4rec.BERT4Rec
¶
Bases: IterativeRecommender, SequentialRecommenderUtils
Implementation of BERT4Rec algorithm from "BERT4Rec: Sequential Recommendation with Bidirectional Encoder Representations from Transformer." in CIKM 2019.
This model uses a bidirectional Transformer to learn item representations based on a masked item prediction task (cloze task). For next-item prediction, a special [MASK] token is appended to the sequence.
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 dimension of the item embeddings (hidden_size). |
n_layers |
int
|
The number of transformer encoder layers. |
n_heads |
int
|
The number of attention heads in the transformer. |
inner_size |
int
|
The dimensionality of the feed-forward layer in the transformer. |
dropout_prob |
float
|
The probability of dropout for embeddings and other layers. |
attn_dropout_prob |
float
|
The probability of dropout for the attention weights. |
mask_prob |
float
|
The probability of an item being masked during training. |
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. |
neg_samples |
int
|
The number of negative samples for BPR loss. |
max_seq_len |
int
|
The maximum length of sequences. |
Source code in warprec/recommenders/sequential_recommender/bert4rec.py
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 | |
forward(item_seq)
¶
Forward pass of BERT4Rec. Uses bidirectional attention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_seq
|
Tensor
|
Sequence of items, potentially with [MASK] tokens. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Output of the Transformer for each token [batch_size, seq_len, embedding_size]. |
Source code in warprec/recommenders/sequential_recommender/bert4rec.py
predict(user_seq, seq_len, *args, item_indices=None, **kwargs)
¶
Prediction using the learned bidirectional embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_seq
|
Tensor
|
Padded sequences of item IDs for users to predict for. |
required |
seq_len
|
Tensor
|
Actual lengths of these sequences, before padding. |
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/sequential_recommender/bert4rec.py
warprec.recommenders.sequential_recommender.bsarec.BSARec
¶
Bases: IterativeRecommender, SequentialRecommenderUtils
Implementation of BASRec model from "BSARec: Bandlimited Self-Attention for Sequential Recommendation." in AAAi 2024.
This model combines frequency-based filtering with self-attention to capture both periodic patterns and sequential dependencies in user behavior.
Architecture: 1. Domain-Specific Patterns (DSP): FFT-based low/high-pass filtering 2. Graph-Space Patterns (GSP): Multi-head self-attention 3. Adaptive Combination: Learnable weighted sum (alpha parameter)
The frequency filtering helps capture cyclical patterns (e.g., weekly habits), while attention captures complex sequential dependencies.
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 dimension of the item embeddings (hidden_size). |
n_layers |
int
|
The number of transformer encoder layers. |
n_heads |
int
|
The number of attention heads in the transformer. |
inner_size |
int
|
The dimensionality of the feed-forward layer. |
dropout_prob |
float
|
The probability of dropout for embeddings. |
attn_dropout_prob |
float
|
The probability of dropout for attention weights. |
alpha |
float
|
Balance parameter between DSP and GSP (0.0-1.0). |
c |
int
|
Cutoff frequency for low-pass filtering. |
reg_weight |
float
|
The L2 regularization weight. |
weight_decay |
float
|
The value of weight decay used in optimizer. |
batch_size |
int
|
The batch size used during training. |
epochs |
int
|
The number of training epochs. |
learning_rate |
float
|
The learning rate value. |
neg_samples |
int
|
The number of negative samples. |
max_seq_len |
int
|
The maximum length of sequences. |
Source code in warprec/recommenders/sequential_recommender/bsarec.py
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 | |
forward(item_seq, item_seq_len)
¶
Forward pass of the BSARec model.
Combines frequency-based patterns (DSP) with attention patterns (GSP) through an adaptive weighted combination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_seq
|
Tensor
|
Padded sequences of item IDs [batch_size, max_seq_len]. |
required |
item_seq_len
|
Tensor
|
Actual lengths of sequences [batch_size,]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The embedding of the predicted item (last session state) [batch_size, embedding_size]. |
Source code in warprec/recommenders/sequential_recommender/bsarec.py
predict(user_indices, *args, item_indices=None, user_seq=None, seq_len=None, **kwargs)
¶
Prediction using the learned session 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
|
user_seq
|
Optional[Tensor]
|
Padded sequences of item IDs for users to predict for. |
None
|
seq_len
|
Optional[Tensor]
|
Actual lengths of these sequences, before padding. |
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/sequential_recommender/bsarec.py
warprec.recommenders.sequential_recommender.cl4srec.CL4SRec
¶
Bases: IterativeRecommender, SequentialRecommenderUtils
Implementation of CL4SRec model from "Contrastive learning for sequential recommendation" in SIGIR 2021.
This implementation follows the original paper: 1. A SASRec-style unidirectional Transformer encoder. 2. Two random augmentations sampled from crop/mask/reorder. 3. A multi-task objective with sampled-softmax next-item prediction and InfoNCE contrastive learning.
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 dimension of the item embeddings (hidden_size). |
n_layers |
int
|
The number of transformer encoder layers. |
n_heads |
int
|
The number of attention heads in the transformer. |
inner_size |
int
|
The dimensionality of the feed-forward layer. |
dropout_prob |
float
|
The probability of dropout for embeddings. |
attn_dropout_prob |
float
|
The probability of dropout for attention weights. |
ssl_lambda |
float
|
The weight for the unsupervised CL loss. |
tau |
float
|
The temperature parameter for contrastive loss. |
sim_type |
str
|
The similarity metric for contrastive loss ("dot" or "cos"). |
crop_eta |
float
|
The probability of cropping items in the augmentation. |
mask_gamma |
float
|
The probability of masking items in the augmentation. |
reorder_beta |
float
|
The probability of reordering items in the augmentation. |
reg_weight |
float
|
The L2 regularization weight. |
weight_decay |
float
|
The value of weight decay used in optimizer. |
batch_size |
int
|
The batch size used during training. |
epochs |
int
|
The number of training epochs. |
learning_rate |
float
|
The learning rate value. |
neg_samples |
int
|
The number of negative samples. |
max_seq_len |
int
|
The maximum length of sequences. |
Source code in warprec/recommenders/sequential_recommender/cl4srec.py
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 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 | |
augment(item_seq, item_seq_len)
¶
Generate two random augmented views for each sequence.
Source code in warprec/recommenders/sequential_recommender/cl4srec.py
forward(item_seq, item_seq_len)
¶
Forward pass of the SASRec-style encoder used by CL4SRec.
Source code in warprec/recommenders/sequential_recommender/cl4srec.py
predict(user_indices, *args, item_indices=None, user_seq=None, seq_len=None, **kwargs)
¶
Prediction using the learned sequence embeddings.
Source code in warprec/recommenders/sequential_recommender/cl4srec.py
warprec.recommenders.sequential_recommender.core.CORE
¶
Bases: IterativeRecommender, SequentialRecommenderUtils
Implementation of CORE algorithm from "CORE: Simple and Effective Session-based Recommendation within Consistent Representation Space." in SIGIR 2022.
CORE unifies the representation space for both encoding and decoding processes, using a Representation-Consistent Encoder (RCE) and Robust Distance Measuring (RDM).
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 dimension of the item embeddings. |
dnn_type |
str
|
Type of encoder ('trm' for Transformer or 'ave' for Average). |
n_layers |
int
|
Number of transformer layers. |
n_heads |
int
|
Number of attention heads. |
inner_size |
int
|
Inner size of the transformer feed-forward layer. |
hidden_dropout_prob |
float
|
Dropout probability for hidden layers. |
attn_dropout_prob |
float
|
Dropout probability for attention weights. |
layer_norm_eps |
float
|
Epsilon for layer normalization. |
session_dropout |
float
|
Dropout for the session embeddings. |
item_dropout |
float
|
Dropout for item embeddings during training. |
temperature |
float
|
Temperature scaling factor for RDM. |
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. |
neg_samples |
int
|
The number of negative samples. |
max_seq_len |
int
|
Maximum sequence length. |
Source code in warprec/recommenders/sequential_recommender/core.py
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 | |
ave_net(item_seq, item_emb)
¶
Simple average pooling encoder.
Source code in warprec/recommenders/sequential_recommender/core.py
forward(item_seq)
¶
Forward pass of the CORE model. Args: item_seq (Tensor): Padded sequences of item IDs [batch_size, max_seq_len]. Returns: Tensor: The session representation [batch_size, embedding_size].
Source code in warprec/recommenders/sequential_recommender/core.py
predict(user_seq, *args, item_indices=None, **kwargs)
¶
Prediction using the learned session embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_seq
|
Tensor
|
Padded sequences of item IDs for users to predict for. |
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/sequential_recommender/core.py
warprec.recommenders.sequential_recommender.duorec.DuoRec
¶
Bases: IterativeRecommender, SequentialRecommenderUtils
Implementation of DuoRec model "Contrastive Learning for Representation Degeneration Problem in Sequential Recommendation" in WSDM 2022.
DuoRec extends a SASRec-style backbone with two contrastive regularizers: 1. Unsupervised CL from two stochastic forward passes of the same sequence. 2. Supervised CL from another sequence sharing the same next-item target.
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
|
Dimension of item and position embeddings. |
n_layers |
int
|
Number of transformer encoder layers. |
n_heads |
int
|
Number of attention heads in the transformer. |
inner_size |
int
|
Dimension of the feedforward network in the transformer. |
dropout_prob |
float
|
Dropout probability for embeddings. |
attn_dropout_prob |
float
|
Dropout probability for attention weights. |
ssl_type |
str
|
Type of self-supervised learning ("us", "su", "un", "us_x"). |
ssl_lambda |
float
|
Weight for the unsupervised CL loss. |
ssl_lambda_sem |
float
|
Weight for the supervised CL loss. |
tau |
float
|
Temperature parameter for contrastive loss. |
sim_type |
str
|
Similarity metric for contrastive loss ("dot" or "cos"). |
reg_weight |
float
|
Weight for the embedding regularization loss. |
weight_decay |
float
|
L2 regularization weight for optimizer. |
batch_size |
int
|
Training batch size. |
epochs |
int
|
Number of training epochs. |
learning_rate |
float
|
Learning rate for optimizer. |
neg_samples |
int
|
Number of negative samples for training. |
max_seq_len |
int
|
Maximum length of input sequences. |
Source code in warprec/recommenders/sequential_recommender/duorec.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 | |
forward(item_seq, item_seq_len)
¶
Encode the sequence and return the final valid hidden state.
Source code in warprec/recommenders/sequential_recommender/duorec.py
predict(user_indices, *args, item_indices=None, user_seq=None, seq_len=None, **kwargs)
¶
Prediction using the learned sequence embeddings.
Source code in warprec/recommenders/sequential_recommender/duorec.py
warprec.recommenders.sequential_recommender.esasrec.eSASRec
¶
Bases: IterativeRecommender, SequentialRecommenderUtils
Implementation of eSASRec from "eSASRec: Enhancing Transformer-based Recommendations in a Modular Fashion."
The model is built around the winning combination described in the paper: shifted-sequence objective, LiGR Transformer blocks, and sampled softmax, with optional mixed negative sampling.
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
|
Dimension of item and position embeddings. |
n_layers |
int
|
Number of transformer encoder layers. |
n_heads |
int
|
Number of attention heads in the transformer. |
inner_size |
int
|
Dimension of the feedforward network in the transformer. |
dropout_prob |
float
|
Dropout probability for embeddings. |
attn_dropout_prob |
float
|
Dropout probability for attention weights. |
use_relative_pos |
bool
|
Whether to use relative positional embeddings. |
use_sampled_softmax |
bool
|
Whether to use sampled softmax loss. |
use_ligr |
bool
|
Whether to use LiGR blocks instead of standard transformer layers. |
mn_ratio |
float
|
Ratio of in-batch negatives to uniform negatives when using mixed negative sampling. |
reg_weight |
float
|
Weight for the embedding regularization loss. |
weight_decay |
float
|
L2 regularization weight for optimizer. |
batch_size |
int
|
Training batch size. |
epochs |
int
|
Number of training epochs. |
learning_rate |
float
|
Learning rate for optimizer. |
neg_samples |
int
|
Number of negative samples for training. |
max_seq_len |
int
|
Maximum length of input sequences. |
Source code in warprec/recommenders/sequential_recommender/esasrec.py
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 | |
forward(item_seq, item_seq_len)
¶
Forward pass with shifted-sequence causal masking.
Source code in warprec/recommenders/sequential_recommender/esasrec.py
predict(user_indices, *args, item_indices=None, user_seq=None, seq_len=None, **kwargs)
¶
Prediction using the learned session embeddings.
Source code in warprec/recommenders/sequential_recommender/esasrec.py
warprec.recommenders.sequential_recommender.gsasrec.gSASRec
¶
Bases: IterativeRecommender, SequentialRecommenderUtils
Implementation of gSASRec algorithm from "gSASRec: Reducing Overconfidence in Sequential Recommendation Trained with Negative Sampling." in RecSys 2023.
This model adapts the SASRec architecture to predict the next item at every step of the sequence, using a Group-wise Binary Cross-Entropy (GBCE) loss function.
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 dimension of the item embeddings (hidden_size). |
n_layers |
int
|
The number of transformer encoder layers. |
n_heads |
int
|
The number of attention heads in the transformer. |
inner_size |
int
|
The dimensionality of the feed-forward layer in the transformer. |
dropout_prob |
float
|
The probability of dropout for embeddings and other layers. |
attn_dropout_prob |
float
|
The probability of dropout for the attention weights. |
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. |
gbce_t |
float
|
The temperature parameter for the Group-wise Binary Cross-Entropy loss. |
neg_samples |
int
|
The number of negative samples. |
max_seq_len |
int
|
The maximum length of sequences. |
reuse_item_embeddings |
bool
|
Whether to reuse item embeddings for output or not. |
Source code in warprec/recommenders/sequential_recommender/gsasrec.py
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 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
forward(item_seq)
¶
Forward pass of gSASRec. Returns the output of the Transformer for each token in the input sequence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_seq
|
Tensor
|
Sequence of items [batch_size, seq_len]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Output of the Transformer encoder [batch_size, seq_len, embedding_size]. |
Source code in warprec/recommenders/sequential_recommender/gsasrec.py
predict(user_seq, seq_len, *args, item_indices=None, **kwargs)
¶
Prediction using the learned session embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_seq
|
Tensor
|
Padded sequences of item IDs for users to predict for. |
required |
seq_len
|
Tensor
|
Actual lengths of these sequences, before padding. |
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/sequential_recommender/gsasrec.py
warprec.recommenders.sequential_recommender.lightsans.LightSANs
¶
Bases: IterativeRecommender, SequentialRecommenderUtils
Implementation of LightSANs algorithm from "Lighter and Better: Low-Rank Decomposed Self-Attention Networks for Next-Item Recommendation" (SIGIR 2021).
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 dimension of the item embeddings. |
n_layers |
int
|
The number of attention layers. |
n_heads |
int
|
The number of attention heads. |
k_interests |
int
|
The number of latent interests (k). |
inner_size |
int
|
The dimensionality of the feed-forward layer. |
dropout_prob |
float
|
The probability of dropout. |
attn_dropout_prob |
float
|
The probability of dropout for attention. |
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. |
neg_samples |
int
|
The number of negative samples. |
max_seq_len |
int
|
The maximum length of sequences. |
Source code in warprec/recommenders/sequential_recommender/lightsans.py
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 | |
forward(item_seq, item_seq_len)
¶
Forward pass of the LightSANs model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_seq
|
Tensor
|
Padded sequences of item IDs [batch_size, max_seq_len]. |
required |
item_seq_len
|
Tensor
|
Actual lengths of sequences [batch_size,]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The embedding of the predicted item (last session state). |
Source code in warprec/recommenders/sequential_recommender/lightsans.py
predict(user_seq, seq_len, *args, item_indices=None, **kwargs)
¶
Prediction using the learned session embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_seq
|
Tensor
|
Padded sequences of item IDs for users to predict for. |
required |
seq_len
|
Tensor
|
Actual lengths of these sequences, before padding. |
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/sequential_recommender/lightsans.py
warprec.recommenders.sequential_recommender.linrec.LinRec
¶
Bases: IterativeRecommender, SequentialRecommenderUtils
Implementation of LinRec algorithm from "LinRec: Linear Attention Mechanism for Long-term Sequential Recommender Systems" in SIGIR 2023.
LinRec replaces the quadratic Dot-Product Attention with an O(N) Linear Attention mechanism based on L2 Normalization and ELU activation.
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
|
Item embedding dimensions. |
n_layers |
int
|
The number of transformer encoder layers. |
n_heads |
int
|
The number of attention heads in the transformer. |
inner_size |
int
|
The dimensionality of the feed-forward layer in the transformer. |
dropout_prob |
float
|
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 during training. |
epochs |
int
|
The number of training epochs. |
learning_rate |
float
|
The learning rate value. |
neg_samples |
int
|
The number of negative samples. |
max_seq_len |
int
|
The maximum length of sequences. |
Source code in warprec/recommenders/sequential_recommender/linrec.py
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 | |
predict(user_seq, seq_len, *args, item_indices=None, **kwargs)
¶
Prediction using the learned session embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_seq
|
Tensor
|
Padded sequences of item IDs for users to predict for. |
required |
seq_len
|
Tensor
|
Actual lengths of these sequences, before padding. |
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/sequential_recommender/linrec.py
warprec.recommenders.sequential_recommender.sasrec.SASRec
¶
Bases: IterativeRecommender, SequentialRecommenderUtils
Implementation of SASRec algorithm from "Self-Attentive Sequential Recommendation." in ICDM 2018.
This implementation is adapted to the WarpRec framework, using PyTorch's native nn.TransformerEncoder for the self-attention mechanism.
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 dimension of the item embeddings (hidden_size). |
n_layers |
int
|
The number of transformer encoder layers. |
n_heads |
int
|
The number of attention heads in the transformer. |
inner_size |
int
|
The dimensionality of the feed-forward layer in the transformer. |
dropout_prob |
float
|
The probability of dropout for embeddings and other layers. |
attn_dropout_prob |
float
|
The probability of dropout for the attention weights. |
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. |
neg_samples |
int
|
The number of negative samples. |
max_seq_len |
int
|
The maximum length of sequences. |
Source code in warprec/recommenders/sequential_recommender/sasrec.py
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 | |
forward(item_seq, item_seq_len)
¶
Forward pass of the SASRec model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_seq
|
Tensor
|
Padded sequences of item IDs [batch_size, max_seq_len]. |
required |
item_seq_len
|
Tensor
|
Actual lengths of sequences [batch_size,]. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
The embedding of the predicted item (last session state) [batch_size, embedding_size]. |
Source code in warprec/recommenders/sequential_recommender/sasrec.py
predict(user_seq, seq_len, *args, item_indices=None, **kwargs)
¶
Prediction using the learned session embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_seq
|
Tensor
|
Padded sequences of item IDs for users to predict for. |
required |
seq_len
|
Tensor
|
Actual lengths of these sequences, before padding. |
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/sequential_recommender/sasrec.py
warprec.recommenders.sequential_recommender.stan.STAN
¶
Bases: Recommender, SequentialRecommenderUtils
Implementation of STAN model from Sequence and Time Aware Neighborhood for Session-basedRecommendations (SIGIR'19).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Model parameters. |
required |
info
|
dict
|
The dictionary containing dataset information. |
required |
sessions
|
Sessions
|
Training sessions — the primary data source; we pull (flat_items, flat_users, user_offsets, timestamps) from it. |
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
|
Neighborhood size N (Section 4). |
lambda_1 |
float
|
Eq. 3 decay. |
lambda_2 |
float
|
Eq. 5 decay (seconds). |
lambda_3 |
float
|
Eq. 7 decay. |
max_seq_len |
int
|
Upper bound on current-session length (controls how much history the evaluator feeds to predict). |
Source code in warprec/recommenders/sequential_recommender/stan.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 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 | |
predict(user_indices, *args, user_seq=None, seq_len=None, item_indices=None, **kwargs)
¶
Compute STAN scores for a batch of current sessions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_indices
|
Tensor
|
User indices for which to produce scores. |
required |
*args
|
Any
|
List of arguments. |
()
|
user_seq
|
Optional[Tensor]
|
Padded sequences of item IDs for users to predict for. |
None
|
seq_len
|
Optional[Tensor]
|
Actual lengths of these sequences, before padding. |
None
|
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
|
Score matrix [batch_size, n_items] or [batch_size, n_samples]. |