Centroid Vector
VBPR(item_field, gamma_dim, theta_dim, batch_size, epochs, threshold=0, learning_rate=0.005, lambda_w=0.01, lambda_b_pos=0.01, lambda_b_neg=0.001, lambda_e=0, train_loss=fun.logsigmoid, optimizer_class=torch.optim.Adam, device=None, embedding_combiner=Centroid(), normalize=True, seed=None, additional_opt_parameters=None, additional_dl_parameters=None)
Bases: ContentBasedAlgorithm
Class that implements recommendation through the VBPR algorithm. It's a ranking algorithm, so it can't do score prediction.
The VBPR algorithm expects features extracted from images and works on implicit feedback, but in theory you could
use any embedding representation, and you can use explicit feedback which will be converted into implicit one
thanks to the threshold
parameter:
- All scores \(>= threshold\) are considered positive scores
For more details on VBPR algorithm, please check the relative paper here
PARAMETER | DESCRIPTION |
---|---|
item_field |
dict where the key is the name of the field that contains the content to use, value is the representation(s) id(s) that will be used for the said item. The value of a field can be a string or a list, use a list if you want to use multiple representations for a particular field.
TYPE:
|
gamma_dim |
dimension of latent factors for non-visual parameters
TYPE:
|
theta_dim |
dimension of latent factors for visual parameters
TYPE:
|
batch_size |
dimension of each batch of the torch dataloader for the images features
TYPE:
|
epochs |
number of training epochs
TYPE:
|
threshold |
float value which is used to distinguish positive from negative items. If None, it will vary for each user, and it will be set to the average rating given by it |
learning_rate |
learning rate for the torch optimizer
TYPE:
|
lambda_w |
weight assigned to the regularization of the loss on \(\gamma_u\), \(\gamma_i\), \(\theta_u\)
TYPE:
|
lambda_b_pos |
weight assigned to the regularization of the loss on \(\beta_i\) for the positive items
TYPE:
|
lambda_b_neg |
weight assigned to the regularization of the loss on \(\beta_i\) for the negative items
TYPE:
|
lambda_e |
weight assigned to the regularization of the loss on \(\beta'\), \(E\)
TYPE:
|
train_loss |
loss function for the training phase. Default is logsigmoid
TYPE:
|
optimizer_class |
optimizer torch class for the training phase. It will be instantiated using
TYPE:
|
device |
device on which the training will be run. If None and a GPU is available, then the GPU is automatically selected as device to use. Otherwise, the cpu is used
TYPE:
|
embedding_combiner |
TYPE:
|
normalize |
Whether to normalize input features or not. If True, the input feature matrix is subtracted to its \(min\) and divided by its \(max + 1e-10\)
TYPE:
|
seed |
random state which will be used for weight initialization and sampling of the negative example
TYPE:
|
additional_opt_parameters |
kwargs for the optimizer. If you specify learning rate in this parameter, it will
be overwritten by the local |
additional_dl_parameters |
kwargs for the dataloader. If you specify batch size in this parameter, it will
be overwritten by the local |
Source code in clayrs/recsys/visual_based_algorithm/vbpr/vbpr_algorithm.py
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 |
|
fit(train_set, items_directory, num_cpus=-1)
Method which will fit the VBPR algorithm via neural training with torch
PARAMETER | DESCRIPTION |
---|---|
train_set |
TYPE:
|
items_directory |
Path where complexly represented items are serialized by the Content Analyzer
TYPE:
|
num_cpus |
number of processors that must be reserved for the method. If set to
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
VBPRNetwork
|
A fit VBPRNetwork object (torch module which implements the VBPR neural network) |
Source code in clayrs/recsys/visual_based_algorithm/vbpr/vbpr_algorithm.py
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 |
|
fit_predict(train_set, test_set, items_directory, user_idx_list, methodology, num_cpus, save_fit)
VBPR is not a score prediction algorithm, calling this method will raise the NotPredictionAlg
exception!
RAISES | DESCRIPTION |
---|---|
NotPredictionAlg
|
exception raised since the VBPR algorithm is not a score prediction algorithm |
Source code in clayrs/recsys/visual_based_algorithm/vbpr/vbpr_algorithm.py
482 483 484 485 486 487 488 489 490 491 492 |
|
fit_rank(train_set, test_set, items_directory, user_idx_list, n_recs, methodology, num_cpus, save_fit)
Method used to both fit and calculate ranking for all users in user_idx_list
parameter.
The algorithm will first be fit considering all users in the user_idx_list
which should contain user id
mapped to their integer!
With the save_fit
parameter you can specify if you need the function to return the algorithm fit (in case
you want to perform multiple calls to the predict()
or rank()
function). If set to True, the first value
returned by this function will be the fit algorithm and the second will be the list of uir matrices with
predictions for each user.
Otherwise, if save_fit
is False, the first value returned by this function will be None
PARAMETER | DESCRIPTION |
---|---|
train_set |
TYPE:
|
test_set |
Ratings object which represents the ground truth of the split considered
TYPE:
|
items_directory |
Path where complexly represented items are serialized by the Content Analyzer
TYPE:
|
user_idx_list |
Set of user idx (int representation) for which a recommendation list must be generated. Users should be represented with their mapped integer! |
n_recs |
Number of the top items that will be present in the ranking of each user.
If |
methodology |
TYPE:
|
save_fit |
Boolean value which let you choose if the fit algorithm should be saved and returned by this function. If True, the first value returned by this function is the fit algorithm. Otherwise, the first value will be None. The second value is always the list of predicted uir matrices
TYPE:
|
num_cpus |
number of processors that must be reserved for the method. If set to
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Optional[VBPRNetwork]
|
The first value is the fit VBPR algorithm (could be None if |
List[np.ndarray]
|
The second value is a list of predicted uir matrices all sorted in a decreasing order w.r.t. the ranking scores |
Source code in clayrs/recsys/visual_based_algorithm/vbpr/vbpr_algorithm.py
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 |
|
predict(fit_alg, train_set, test_set, items_directory, user_idx_list, methodology, num_cpus)
VBPR is not a score prediction algorithm, calling this method will raise the NotPredictionAlg
exception!
RAISES | DESCRIPTION |
---|---|
NotPredictionAlg
|
exception raised since the VBPR algorithm is not a score prediction algorithm |
Source code in clayrs/recsys/visual_based_algorithm/vbpr/vbpr_algorithm.py
426 427 428 429 430 431 432 433 434 435 436 |
|
rank(fit_alg, train_set, test_set, items_directory, user_idx_list, n_recs, methodology, num_cpus)
Method used to calculate ranking for all users in user_idx_list
parameter.
You must first call the fit()
method before you can compute the ranking.
The user_idx_list
parameter should contain users with mapped to their integer!
The representation of the fit VBPR algorithm is a VBPRNetwork
object (torch module which implements the
VBPR neural network)
If the n_recs
is specified, then the rank will contain the top-n items for the users.
Otherwise, the rank will contain all unrated items of the particular users.
Via the methodology
parameter you can perform different candidate item selection. By default, the
TestRatingsMethodology()
is used: so, for each user, items in its test set only will be ranked
PARAMETER | DESCRIPTION |
---|---|
fit_alg |
a fit
TYPE:
|
train_set |
TYPE:
|
test_set |
Ratings object which represents the ground truth of the split considered
TYPE:
|
items_directory |
Path where complexly represented items are serialized by the Content Analyzer
TYPE:
|
user_idx_list |
Set of user idx (int representation) for which a recommendation list must be generated. Users should be represented with their mapped integer! |
n_recs |
Number of the top items that will be present in the ranking of each user.
If |
methodology |
TYPE:
|
num_cpus |
number of processors that must be reserved for the method. If set to
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[np.ndarray]
|
List of uir matrices for each user, where each uir contains predicted interactions between users and unseen items sorted in a descending way w.r.t. the third dimension which is the ranked score |
Source code in clayrs/recsys/visual_based_algorithm/vbpr/vbpr_algorithm.py
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 |
|