warprec 2.1.2__tar.gz → 2.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. {warprec-2.1.2 → warprec-2.1.3}/PKG-INFO +1 -1
  2. {warprec-2.1.2 → warprec-2.1.3}/pyproject.toml +1 -1
  3. {warprec-2.1.2 → warprec-2.1.3}/warprec/common/__init__.py +2 -0
  4. {warprec-2.1.2 → warprec-2.1.3}/warprec/common/run_state.py +39 -1
  5. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/dataset.py +2 -0
  6. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/eval_loaders.py +145 -83
  7. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/writer/base_writer.py +3 -1
  8. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/evaluator.py +8 -0
  9. {warprec-2.1.2 → warprec-2.1.3}/warprec/pipelines/common.py +64 -1
  10. {warprec-2.1.2 → warprec-2.1.3}/warprec/pipelines/estimate.py +41 -2
  11. {warprec-2.1.2 → warprec-2.1.3}/warprec/pipelines/eval.py +143 -25
  12. {warprec-2.1.2 → warprec-2.1.3}/warprec/pipelines/remotes/ml.py +2 -1
  13. {warprec-2.1.2 → warprec-2.1.3}/warprec/pipelines/swarm.py +31 -18
  14. {warprec-2.1.2 → warprec-2.1.3}/warprec/pipelines/train.py +20 -59
  15. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/base_recommender.py +124 -61
  16. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/callbacks.py +64 -30
  17. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/sequential_recommender/bsarec.py +4 -0
  18. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/sequential_recommender/caser.py +4 -0
  19. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/sequential_recommender/core.py +4 -1
  20. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/sequential_recommender/fossil.py +5 -1
  21. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/sequential_recommender/lightsans.py +4 -0
  22. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/sequential_recommender/sasrec.py +4 -2
  23. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/trainer/dashboard_callbacks.py +29 -0
  24. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/trainer/objectives.py +4 -1
  25. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/trainer/trainer.py +65 -15
  26. {warprec-2.1.2 → warprec-2.1.3}/warprec/serving/app.py +5 -1
  27. {warprec-2.1.2 → warprec-2.1.3}/warprec/serving/servable.py +8 -2
  28. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/model_configuration.py +19 -0
  29. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/helpers.py +7 -2
  30. {warprec-2.1.2 → warprec-2.1.3}/LICENSE +0 -0
  31. {warprec-2.1.2 → warprec-2.1.3}/README.md +0 -0
  32. {warprec-2.1.2 → warprec-2.1.3}/warprec/__init__.py +0 -0
  33. {warprec-2.1.2 → warprec-2.1.3}/warprec/common/initialize.py +0 -0
  34. {warprec-2.1.2 → warprec-2.1.3}/warprec/common/std_logs.py +0 -0
  35. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/__init__.py +0 -0
  36. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/entities/__init__.py +0 -0
  37. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/entities/common.py +0 -0
  38. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/entities/context.py +0 -0
  39. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/entities/interactions.py +0 -0
  40. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/entities/knowledge.py +0 -0
  41. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/entities/multimodal.py +0 -0
  42. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/entities/sessions.py +0 -0
  43. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/entities/train_structures/__init__.py +0 -0
  44. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/entities/train_structures/custom_collate_fn.py +0 -0
  45. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/entities/train_structures/interaction_structures.py +0 -0
  46. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/entities/train_structures/session_structures.py +0 -0
  47. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/entities/transactions.py +0 -0
  48. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/filtering.py +0 -0
  49. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/ranking.py +0 -0
  50. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/reader/__init__.py +0 -0
  51. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/reader/azureblob_reader.py +0 -0
  52. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/reader/base_reader.py +0 -0
  53. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/reader/local_reader.py +0 -0
  54. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/schema.py +0 -0
  55. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/splitting/__init__.py +0 -0
  56. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/splitting/splitter.py +0 -0
  57. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/splitting/strategies.py +0 -0
  58. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/writer/__init__.py +0 -0
  59. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/writer/azureblob_writer.py +0 -0
  60. {warprec-2.1.2 → warprec-2.1.3}/warprec/data/writer/local_writer.py +0 -0
  61. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/__init__.py +0 -0
  62. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/factory.py +0 -0
  63. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/__init__.py +0 -0
  64. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/accuracy/__init__.py +0 -0
  65. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/accuracy/auc.py +0 -0
  66. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/accuracy/f1.py +0 -0
  67. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/accuracy/gauc.py +0 -0
  68. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/accuracy/hit_rate.py +0 -0
  69. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/accuracy/lauc.py +0 -0
  70. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/accuracy/logloss.py +0 -0
  71. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/accuracy/map.py +0 -0
  72. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/accuracy/mar.py +0 -0
  73. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/accuracy/mrr.py +0 -0
  74. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/accuracy/ndcg.py +0 -0
  75. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/accuracy/precision.py +0 -0
  76. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/accuracy/recall.py +0 -0
  77. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/base_metric.py +0 -0
  78. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/bias/__init__.py +0 -0
  79. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/bias/aclt.py +0 -0
  80. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/bias/aplt.py +0 -0
  81. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/bias/arp.py +0 -0
  82. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/bias/long_tail.py +0 -0
  83. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/bias/pop_reo.py +0 -0
  84. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/bias/pop_rsp.py +0 -0
  85. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/coverage/__init__.py +0 -0
  86. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/coverage/item_coverage.py +0 -0
  87. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/coverage/numretrieved.py +0 -0
  88. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/coverage/user_coverage.py +0 -0
  89. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/coverage/user_coverage_at_n.py +0 -0
  90. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/debiased/__init__.py +0 -0
  91. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/debiased/base.py +0 -0
  92. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/debiased/dcg.py +0 -0
  93. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/debiased/recall.py +0 -0
  94. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/diversity/__init__.py +0 -0
  95. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/diversity/gini_index.py +0 -0
  96. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/diversity/shannon_entropy.py +0 -0
  97. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/diversity/srecall.py +0 -0
  98. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/fairness/__init__.py +0 -0
  99. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/fairness/biasdisparitybd.py +0 -0
  100. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/fairness/biasdisparitybr.py +0 -0
  101. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/fairness/biasdisparitybs.py +0 -0
  102. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/fairness/itemmadranking.py +0 -0
  103. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/fairness/itemmadrating.py +0 -0
  104. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/fairness/reo.py +0 -0
  105. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/fairness/rsp.py +0 -0
  106. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/fairness/usermadranking.py +0 -0
  107. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/fairness/usermadrating.py +0 -0
  108. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/multiobjective/__init__.py +0 -0
  109. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/multiobjective/euclideandistance.py +0 -0
  110. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/multiobjective/hypervolume.py +0 -0
  111. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/novelty/__init__.py +0 -0
  112. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/novelty/efd.py +0 -0
  113. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/novelty/epc.py +0 -0
  114. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/novelty/novelty_profile.py +0 -0
  115. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/rating/__init__.py +0 -0
  116. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/rating/mae.py +0 -0
  117. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/rating/mse.py +0 -0
  118. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/metrics/rating/rmse.py +0 -0
  119. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/propensity.py +0 -0
  120. {warprec-2.1.2 → warprec-2.1.3}/warprec/evaluation/statistical_significance.py +0 -0
  121. {warprec-2.1.2 → warprec-2.1.3}/warprec/pipelines/__init__.py +0 -0
  122. {warprec-2.1.2 → warprec-2.1.3}/warprec/pipelines/design.py +0 -0
  123. {warprec-2.1.2 → warprec-2.1.3}/warprec/pipelines/remotes/__init__.py +0 -0
  124. {warprec-2.1.2 → warprec-2.1.3}/warprec/pipelines/remotes/data.py +0 -0
  125. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/__init__.py +0 -0
  126. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/__init__.py +0 -0
  127. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/__init__.py +0 -0
  128. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/cdae.py +0 -0
  129. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/diffrec.py +0 -0
  130. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/ease.py +0 -0
  131. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/elsa.py +0 -0
  132. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/macridvae.py +0 -0
  133. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/multidae.py +0 -0
  134. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/multivae.py +0 -0
  135. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/sansa.py +0 -0
  136. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/__init__.py +0 -0
  137. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/dgcf.py +0 -0
  138. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/egcf.py +0 -0
  139. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/esigcf.py +0 -0
  140. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/gcmc.py +0 -0
  141. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/graph_utils.py +0 -0
  142. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/lightccf.py +0 -0
  143. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgcl.py +0 -0
  144. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgcn.py +0 -0
  145. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgcnpp.py +0 -0
  146. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgode.py +0 -0
  147. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/macrgcn.py +0 -0
  148. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/mixrec.py +0 -0
  149. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/ngcf.py +0 -0
  150. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/paac.py +0 -0
  151. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/popdcl.py +0 -0
  152. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/recdcl.py +0 -0
  153. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/rp3beta.py +0 -0
  154. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/sgcl.py +0 -0
  155. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/sgl.py +0 -0
  156. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/simgcl.py +0 -0
  157. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/simrec.py +0 -0
  158. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/ultragcn.py +0 -0
  159. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/graph_based/xsimgcl.py +0 -0
  160. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/knn/__init__.py +0 -0
  161. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/knn/itemknn.py +0 -0
  162. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/knn/itemknntd.py +0 -0
  163. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/knn/userknn.py +0 -0
  164. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/knn/userknntd.py +0 -0
  165. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/__init__.py +0 -0
  166. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/admmslim.py +0 -0
  167. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/bpr.py +0 -0
  168. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/fism.py +0 -0
  169. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/ials.py +0 -0
  170. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/ials2008.py +0 -0
  171. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/macrmf.py +0 -0
  172. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/slim.py +0 -0
  173. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/neural/__init__.py +0 -0
  174. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/neural/convncf.py +0 -0
  175. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/neural/neumf.py +0 -0
  176. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/collaborative_filtering_recommender/neural/twotower.py +0 -0
  177. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/content_based_recommender/__init__.py +0 -0
  178. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/content_based_recommender/vsm.py +0 -0
  179. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/context_aware_recommender/__init__.py +0 -0
  180. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/context_aware_recommender/afm.py +0 -0
  181. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/context_aware_recommender/dcn.py +0 -0
  182. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/context_aware_recommender/dcnv2.py +0 -0
  183. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/context_aware_recommender/deepfm.py +0 -0
  184. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/context_aware_recommender/fm.py +0 -0
  185. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/context_aware_recommender/nfm.py +0 -0
  186. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/context_aware_recommender/wideanddeep.py +0 -0
  187. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/context_aware_recommender/xdeepfm.py +0 -0
  188. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/hybrid_recommender/__init__.py +0 -0
  189. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/hybrid_recommender/addease.py +0 -0
  190. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/hybrid_recommender/attributeitemknn.py +0 -0
  191. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/hybrid_recommender/attributeuserknn.py +0 -0
  192. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/hybrid_recommender/cease.py +0 -0
  193. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/knowledge_aware_recommender/__init__.py +0 -0
  194. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/knowledge_aware_recommender/cke.py +0 -0
  195. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/knowledge_aware_recommender/kahfm.py +0 -0
  196. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/knowledge_aware_recommender/kgat.py +0 -0
  197. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/knowledge_aware_recommender/kgcn.py +0 -0
  198. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/knowledge_aware_recommender/kgflex.py +0 -0
  199. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/knowledge_aware_recommender/kgin.py +0 -0
  200. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/knowledge_aware_recommender/knowledge_utils.py +0 -0
  201. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/knowledge_aware_recommender/ripplenet.py +0 -0
  202. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/layers.py +0 -0
  203. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/losses.py +0 -0
  204. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/lr_scheduler_wrapper.py +0 -0
  205. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/multimodal_recommender/__init__.py +0 -0
  206. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/multimodal_recommender/bm3.py +0 -0
  207. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/multimodal_recommender/freedom.py +0 -0
  208. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/multimodal_recommender/lattice.py +0 -0
  209. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/multimodal_recommender/mgcn.py +0 -0
  210. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/multimodal_recommender/mmgcn.py +0 -0
  211. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/multimodal_recommender/multimodal_utils.py +0 -0
  212. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/multimodal_recommender/vbpr.py +0 -0
  213. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/optimizer_wrapper.py +0 -0
  214. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/proxy.py +0 -0
  215. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/reranking/__init__.py +0 -0
  216. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/reranking/base.py +0 -0
  217. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/reranking/calibration.py +0 -0
  218. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/reranking/factory.py +0 -0
  219. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/reranking/mmr.py +0 -0
  220. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/sequential_recommender/__init__.py +0 -0
  221. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/sequential_recommender/bert4rec.py +0 -0
  222. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/sequential_recommender/cl4srec.py +0 -0
  223. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/sequential_recommender/duorec.py +0 -0
  224. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/sequential_recommender/esasrec.py +0 -0
  225. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/sequential_recommender/gru4rec.py +0 -0
  226. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/sequential_recommender/gsasrec.py +0 -0
  227. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/sequential_recommender/linrec.py +0 -0
  228. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/sequential_recommender/narm.py +0 -0
  229. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/sequential_recommender/stan.py +0 -0
  230. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/similarities.py +0 -0
  231. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/trainer/__init__.py +0 -0
  232. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/trainer/logger_callbacks.py +0 -0
  233. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/trainer/runtime.py +0 -0
  234. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/trainer/scheduler_wrapper.py +0 -0
  235. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/trainer/search_algorithm_wrapper.py +0 -0
  236. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/unpersonalized_recommender/__init__.py +0 -0
  237. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/unpersonalized_recommender/pop.py +0 -0
  238. {warprec-2.1.2 → warprec-2.1.3}/warprec/recommenders/unpersonalized_recommender/random.py +0 -0
  239. {warprec-2.1.2 → warprec-2.1.3}/warprec/run.py +0 -0
  240. {warprec-2.1.2 → warprec-2.1.3}/warprec/serve.py +0 -0
  241. {warprec-2.1.2 → warprec-2.1.3}/warprec/serving/__init__.py +0 -0
  242. {warprec-2.1.2 → warprec-2.1.3}/warprec/serving/api.py +0 -0
  243. {warprec-2.1.2 → warprec-2.1.3}/warprec/serving/catalogue.py +0 -0
  244. {warprec-2.1.2 → warprec-2.1.3}/warprec/serving/context.py +0 -0
  245. {warprec-2.1.2 → warprec-2.1.3}/warprec/serving/deployments.py +0 -0
  246. {warprec-2.1.2 → warprec-2.1.3}/warprec/serving/errors.py +0 -0
  247. {warprec-2.1.2 → warprec-2.1.3}/warprec/serving/mcp.py +0 -0
  248. {warprec-2.1.2 → warprec-2.1.3}/warprec/serving/payload.py +0 -0
  249. {warprec-2.1.2 → warprec-2.1.3}/warprec/serving/schemas.py +0 -0
  250. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/__init__.py +0 -0
  251. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/callback.py +0 -0
  252. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/__init__.py +0 -0
  253. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/common.py +0 -0
  254. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/config.py +0 -0
  255. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/dashboard_configuration.py +0 -0
  256. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/estimate_configuration.py +0 -0
  257. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/evaluation_configuration.py +0 -0
  258. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/general_configuration.py +0 -0
  259. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/reader_configuration.py +0 -0
  260. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/recommender_model_config/__init__.py +0 -0
  261. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/recommender_model_config/collaborative_filtering_config/__init__.py +0 -0
  262. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/recommender_model_config/collaborative_filtering_config/autoencoder_config.py +0 -0
  263. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/recommender_model_config/collaborative_filtering_config/graph_based_config.py +0 -0
  264. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/recommender_model_config/collaborative_filtering_config/knn_config.py +0 -0
  265. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/recommender_model_config/collaborative_filtering_config/latent_factor_config.py +0 -0
  266. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/recommender_model_config/collaborative_filtering_config/neural_config.py +0 -0
  267. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/recommender_model_config/content_based_config.py +0 -0
  268. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/recommender_model_config/context_aware_config.py +0 -0
  269. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/recommender_model_config/hybrid_config.py +0 -0
  270. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/recommender_model_config/knowledge_aware_config.py +0 -0
  271. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/recommender_model_config/multimodal_config.py +0 -0
  272. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/recommender_model_config/sequential_model_config.py +0 -0
  273. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/recommender_model_config/unpersonalized_config.py +0 -0
  274. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/rerank_configuration.py +0 -0
  275. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/run_configuration.py +0 -0
  276. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/search_space_wrapper.py +0 -0
  277. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/serving_configuration.py +0 -0
  278. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/splitter_configuration.py +0 -0
  279. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/training_configuration.py +0 -0
  280. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/config/writer_configuration.py +0 -0
  281. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/enums.py +0 -0
  282. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/logger/__init__.py +0 -0
  283. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/logger/logger.py +0 -0
  284. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/pause.py +0 -0
  285. {warprec-2.1.2 → warprec-2.1.3}/warprec/utils/registry.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: warprec
3
- Version: 2.1.2
3
+ Version: 2.1.3
4
4
  Summary: Unifying Academic Rigor and Industrial Scale for Responsible, Reproducible, and Efficient Recommendation
5
5
  Author: MarcoWV
6
6
  Author-email: marco.avolio@wideverse.com
@@ -61,7 +61,7 @@ warprec = "warprec.run:main"
61
61
  "warprec.serve" = "warprec.serve:main"
62
62
 
63
63
  [tool.poetry]
64
- version = "2.1.2"
64
+ version = "2.1.3"
65
65
 
66
66
  [tool.poetry.dependencies]
67
67
  python = "^3.12"
@@ -5,6 +5,7 @@ from .run_state import (
5
5
  RunState,
6
6
  RunStateStore,
7
7
  model_fingerprint,
8
+ reconcile_model_state,
8
9
  resolve_run_name,
9
10
  run_fingerprint,
10
11
  warprec_version,
@@ -20,6 +21,7 @@ __all__ = [
20
21
  "RunState",
21
22
  "RunStateStore",
22
23
  "model_fingerprint",
24
+ "reconcile_model_state",
23
25
  "resolve_run_name",
24
26
  "run_fingerprint",
25
27
  "warprec_version",
@@ -5,7 +5,7 @@ from datetime import datetime
5
5
  from enum import Enum
6
6
  from importlib.metadata import PackageNotFoundError, version
7
7
  from io import BytesIO
8
- from typing import Any, Dict, Optional, TYPE_CHECKING
8
+ from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING
9
9
 
10
10
  import numpy as np
11
11
  import torch
@@ -300,6 +300,44 @@ def model_fingerprint(model_name: str, model_params: Dict[str, Any]) -> str:
300
300
  return _digest({"model": model_name, "params": _strip_excluded(model_params)})
301
301
 
302
302
 
303
+ def reconcile_model_state(
304
+ state: RunState, model_name: str, model_params: Dict[str, Any]
305
+ ) -> Tuple[ModelState, bool]:
306
+ """Checks a model's recorded progress against its current configuration.
307
+
308
+ This runs before any decision based on the recorded status, so that a model
309
+ whose configuration changed is optimised again even when the manifest says
310
+ it completed or failed. Its recorded state is replaced by a pending one and
311
+ the current fingerprint is recorded.
312
+
313
+ Args:
314
+ state (RunState): The state of the run.
315
+ model_name (str): The name of the model.
316
+ model_params (Dict[str, Any]): The model's current parameter block.
317
+
318
+ Returns:
319
+ Tuple[ModelState, bool]: The model's state, and whether the progress
320
+ Ray Tune saved for it may be restored. Only progress recorded by
321
+ this run, under the same model configuration, may be restored;
322
+ anything else on disk belongs to a run whose state was discarded.
323
+ """
324
+ model_state = state.model_state(model_name)
325
+ current = model_fingerprint(model_name, model_params)
326
+
327
+ if model_state.fingerprint and model_state.fingerprint != current:
328
+ logger.attention(
329
+ f"The configuration of {model_name} changed since the last run. "
330
+ "Its saved state will be discarded and the model will be "
331
+ "optimized from scratch."
332
+ )
333
+ model_state = ModelState()
334
+ state.models[model_name] = model_state
335
+
336
+ resumable = model_state.fingerprint == current
337
+ model_state.fingerprint = current
338
+ return model_state, resumable
339
+
340
+
303
341
  def run_fingerprint(config: "TrainConfiguration") -> str:
304
342
  """Fingerprints the run-level configuration.
305
343
 
@@ -1083,6 +1083,7 @@ class Dataset:
1083
1083
  user_id_label=user_label,
1084
1084
  item_id_label=item_label,
1085
1085
  context_labels=context_labels,
1086
+ context=self._context_spec,
1086
1087
  )
1087
1088
  self._precomputed_dataloader[key] = DataLoader(
1088
1089
  dataset, batch_size=self.batch_size, shuffle=False, **kwargs
@@ -1166,6 +1167,7 @@ class Dataset:
1166
1167
  seed=seed,
1167
1168
  negative_sampling=negative_sampling,
1168
1169
  neg_alpha=neg_alpha,
1170
+ context=self._context_spec,
1169
1171
  )
1170
1172
  self._precomputed_dataloader[key] = DataLoader(
1171
1173
  dataset,
@@ -10,9 +10,11 @@ from torch.utils.data import Dataset as TorchDataset
10
10
  from torch.nn.utils.rnn import pad_sequence
11
11
  from scipy.sparse import csr_matrix
12
12
 
13
+ from warprec.data.entities.context import build_context_array
13
14
  from warprec.data.entities.train_structures.interaction_structures import (
14
15
  popularity_cumulative,
15
16
  )
17
+ from warprec.data.schema import ContextSpec
16
18
 
17
19
 
18
20
  def draw_candidates(
@@ -40,6 +42,118 @@ def draw_candidates(
40
42
  return np.minimum(drawn, num_items - 1)
41
43
 
42
44
 
45
+ def drawable_items(cumulative: Optional[np.ndarray]) -> Optional[np.ndarray]:
46
+ """Which items a popularity draw can return at all.
47
+
48
+ Args:
49
+ cumulative (Optional[np.ndarray]): The cumulative popularity weights, or
50
+ None for a uniform draw.
51
+
52
+ Returns:
53
+ Optional[np.ndarray]: A mask of the items with a weight, or None when
54
+ every item can be drawn.
55
+ """
56
+ if cumulative is None:
57
+ return None
58
+ return np.diff(cumulative, prepend=0.0) > 0
59
+
60
+
61
+ def draw_negatives(
62
+ rng: np.random.RandomState,
63
+ cumulative: Optional[np.ndarray],
64
+ drawable: Optional[np.ndarray],
65
+ num_items: int,
66
+ seen: np.ndarray,
67
+ num_negatives: int,
68
+ user: int,
69
+ ) -> np.ndarray:
70
+ """Draw distinct items a user has not seen, in the configured distribution.
71
+
72
+ Candidates are drawn one after another and a repeat or a seen item is
73
+ rejected, so the result is a draw without replacement from the user's unseen
74
+ items: uniform over them, or in proportion to their popularity. The order of
75
+ the draws is kept. Sorting the candidates and keeping the first ones, as
76
+ the loaders used to, favoured the items with the lowest indices.
77
+
78
+ Args:
79
+ rng (np.random.RandomState): The stream the draws come from.
80
+ cumulative (Optional[np.ndarray]): The cumulative popularity weights, or
81
+ None to draw every item with equal probability.
82
+ drawable (Optional[np.ndarray]): The items the popularity draw can
83
+ return, from drawable_items; None for a uniform draw.
84
+ num_items (int): The size of the catalogue.
85
+ seen (np.ndarray): The items the user may not be offered.
86
+ num_negatives (int): How many items to draw.
87
+ user (int): The user drawn for, named in the error.
88
+
89
+ Returns:
90
+ np.ndarray: Exactly num_negatives distinct unseen items, in draw order.
91
+
92
+ Raises:
93
+ ValueError: If the user has fewer items left to draw than num_negatives.
94
+ """
95
+ seen = np.unique(np.asarray(seen, dtype=np.int64))
96
+ if drawable is None:
97
+ available = num_items - len(seen)
98
+ reason = ""
99
+ else:
100
+ # An item no one interacted with has no weight and is never drawn.
101
+ available = int(drawable.sum() - drawable[seen].sum())
102
+ reason = " that popularity sampling can draw"
103
+ # Every user must yield the same number of candidates, or the evaluator
104
+ # cannot line the batch up, and drawing for a user who cannot supply them
105
+ # would never return.
106
+ if available < num_negatives:
107
+ raise ValueError(
108
+ f"Sampled evaluation asks for {num_negatives} negatives per user, but "
109
+ f"user {user} has only {available} of the {num_items} items left "
110
+ f"unseen{reason}. Lower 'evaluation.num_negatives' or evaluate on the "
111
+ "full catalogue."
112
+ )
113
+
114
+ chosen = np.empty(0, dtype=np.int64)
115
+ while len(chosen) < num_negatives:
116
+ # Twice as many as needed, so that one round is usually enough.
117
+ candidates = draw_candidates(rng, cumulative, num_items, 2 * num_negatives)
118
+ candidates = candidates[np.isin(candidates, seen, invert=True)]
119
+ merged = np.concatenate([chosen, candidates.astype(np.int64)])
120
+ # Each item where it was first drawn, in the order of the draws.
121
+ _, first = np.unique(merged, return_index=True)
122
+ chosen = merged[np.sort(first)]
123
+ return chosen[:num_negatives]
124
+
125
+
126
+ def read_contexts(
127
+ eval_data: DataFrame[Any],
128
+ context_labels: List[str],
129
+ context: Optional[ContextSpec] = None,
130
+ ) -> Tensor:
131
+ """Read the encoded context columns the way training reads them.
132
+
133
+ A categorical field stores an index and a numeric field a value, and a
134
+ multi-valued field stores its indices as one string, such as '5 14'. The
135
+ array is built by the same function the training records use, so that an
136
+ evaluation context has the shape and the padding of a training one.
137
+
138
+ Args:
139
+ eval_data (DataFrame[Any]): The evaluation rows, contexts encoded.
140
+ context_labels (List[str]): The context columns, in order.
141
+ context (Optional[ContextSpec]): How each field is encoded and the widest
142
+ multi-valued field; None when every field holds a single number.
143
+
144
+ Returns:
145
+ Tensor: The contexts, [rows, fields], or [rows, fields, values] with a
146
+ multi-valued field.
147
+ """
148
+ context = context or ContextSpec()
149
+ types = [context.field_types.get(label, "token") for label in context_labels]
150
+ return torch.from_numpy(
151
+ build_context_array(
152
+ eval_data.select(context_labels).to_numpy(), types, context.max_len
153
+ )
154
+ )
155
+
156
+
43
157
  class EvaluationDataset(TorchDataset):
44
158
  """
45
159
  Yields: (user_idx, item_indices, values)
@@ -88,6 +202,7 @@ class ContextualEvaluationDataset(TorchDataset):
88
202
  user_id_label: str,
89
203
  item_id_label: str,
90
204
  context_labels: List[str],
205
+ context: Optional[ContextSpec] = None,
91
206
  ):
92
207
  # Pre-convert DataFrames to torch tensor to reduce overhead
93
208
  self.user_indices = torch.from_numpy(
@@ -96,11 +211,7 @@ class ContextualEvaluationDataset(TorchDataset):
96
211
  self.item_indices = torch.from_numpy(
97
212
  eval_data.select(item_id_label).to_numpy().flatten().astype(np.int64)
98
213
  )
99
- # Categorical fields store an index and numeric fields a value, so the
100
- # evaluation contexts are read the same way the training ones are.
101
- self.context_features = torch.from_numpy(
102
- eval_data.select(context_labels).to_numpy().astype(np.float32)
103
- )
214
+ self.context_features = read_contexts(eval_data, context_labels, context)
104
215
 
105
216
  def __len__(self) -> int:
106
217
  return len(self.user_indices)
@@ -161,6 +272,7 @@ class SampledEvaluationDataset(TorchDataset):
161
272
  if negative_sampling == "popularity"
162
273
  else None
163
274
  )
275
+ drawable = drawable_items(cumulative)
164
276
 
165
277
  for u in self.users_with_eval:
166
278
  # Store positives
@@ -178,43 +290,18 @@ class SampledEvaluationDataset(TorchDataset):
178
290
  self.negative_items_list.append(torch.tensor([], dtype=torch.long))
179
291
  continue
180
292
 
181
- # Sample one time 2x the number of negatives
182
- # NOTE: In most cases this will skip the while loop
183
- num_to_generate = num_negatives * 2
184
- candidates = draw_candidates(
185
- rng, cumulative, self.num_items, num_to_generate
186
- )
187
-
188
- # Fast filtering using numpy boolean masking
189
- mask = np.isin(candidates, seen_items, invert=True)
190
- valid_negatives = candidates[mask]
191
-
192
- # Remove duplicates in candidates if necessary
193
- valid_negatives = np.unique(valid_negatives)
194
-
195
- # Every user must yield the same number of candidates, or the
196
- # evaluator cannot line the batch up. A user with fewer unseen items
197
- # than were asked for cannot, and the loop below would otherwise
198
- # draw for them forever.
199
- if self.num_items - n_seen < num_negatives:
200
- raise ValueError(
201
- f"Sampled evaluation asks for {num_negatives} negatives per "
202
- f"user, but user {u} has only {self.num_items - n_seen} of "
203
- f"the {self.num_items} items left unseen. Lower "
204
- "'evaluation.num_negatives' or evaluate on the full catalogue."
205
- )
206
-
207
- if len(valid_negatives) < num_negatives:
208
- final_negs = list(valid_negatives)
209
- while len(final_negs) < num_negatives:
210
- cand = int(draw_candidates(rng, cumulative, self.num_items, 1)[0])
211
- if cand not in seen_items and cand not in final_negs:
212
- final_negs.append(cand)
213
- valid_negatives = np.array(final_negs)
214
-
215
- # Take exactly num_negatives
216
293
  self.negative_items_list.append(
217
- torch.tensor(valid_negatives[:num_negatives], dtype=torch.long)
294
+ torch.from_numpy(
295
+ draw_negatives(
296
+ rng,
297
+ cumulative,
298
+ drawable,
299
+ self.num_items,
300
+ seen_items,
301
+ num_negatives,
302
+ u,
303
+ )
304
+ )
218
305
  )
219
306
 
220
307
  def __len__(self) -> int:
@@ -272,8 +359,11 @@ class SampledContextualEvaluationDataset(TorchDataset):
272
359
  seed: int = 42,
273
360
  negative_sampling: str = "uniform",
274
361
  neg_alpha: float = 0.75,
362
+ context: Optional[ContextSpec] = None,
275
363
  ):
276
- # pylint: disable = too-many-nested-blocks
364
+ # pylint: disable = too-many-arguments, too-many-positional-arguments
365
+ # The evaluation rows, the sampling protocol and the context encoding
366
+ # are decided in different places and only meet here.
277
367
  self.num_negatives = num_negatives
278
368
  self.num_items = num_items
279
369
 
@@ -284,11 +374,7 @@ class SampledContextualEvaluationDataset(TorchDataset):
284
374
  self.pos_item_indices = torch.from_numpy(
285
375
  eval_data.select(item_id_label).to_numpy().flatten().astype(np.int64)
286
376
  )
287
- # Categorical fields store an index and numeric fields a value, so the
288
- # evaluation contexts are read the same way the training ones are.
289
- self.context_features = torch.from_numpy(
290
- eval_data.select(context_labels).to_numpy().astype(np.float32)
291
- )
377
+ self.context_features = read_contexts(eval_data, context_labels, context)
292
378
 
293
379
  n_train_users = train_interactions.shape[0]
294
380
 
@@ -299,6 +385,7 @@ class SampledContextualEvaluationDataset(TorchDataset):
299
385
  if negative_sampling == "popularity"
300
386
  else None
301
387
  )
388
+ drawable = drawable_items(cumulative)
302
389
 
303
390
  for idx, user_idx_tensor in enumerate(self.user_indices):
304
391
  u = int(user_idx_tensor.item())
@@ -315,43 +402,18 @@ class SampledContextualEvaluationDataset(TorchDataset):
315
402
  # Compute seen items
316
403
  seen_items = np.append(train_items, target_item)
317
404
 
318
- # Generate 2x candidates to avoid loops in most cases
319
- num_to_generate = self.num_negatives * 2
320
- candidates = draw_candidates(
321
- rng, cumulative, self.num_items, num_to_generate
322
- )
323
-
324
- # Filter out seen items using optimized numpy boolean masking
325
- mask = np.isin(candidates, seen_items, invert=True)
326
- valid_negatives = candidates[mask]
327
-
328
- # Remove duplicates
329
- valid_negatives = np.unique(valid_negatives)
330
-
331
- # As above: a user without enough unseen items cannot supply the
332
- # candidates, and drawing until they can would never return.
333
- if self.num_items - len(np.unique(seen_items)) < self.num_negatives:
334
- raise ValueError(
335
- f"Sampled evaluation asks for {self.num_negatives} negatives "
336
- f"per user, but user {u} has only "
337
- f"{self.num_items - len(np.unique(seen_items))} of the "
338
- f"{self.num_items} items left unseen. Lower "
339
- "'evaluation.num_negatives' or evaluate on the full catalogue."
340
- )
341
-
342
- if len(valid_negatives) < self.num_negatives:
343
- final_negs = list(valid_negatives)
344
- while len(final_negs) < self.num_negatives:
345
- cand = int(draw_candidates(rng, cumulative, self.num_items, 1)[0])
346
- if cand not in final_negs:
347
- if cand != target_item:
348
- if cand not in train_items:
349
- final_negs.append(cand) # type: ignore[arg-type]
350
- valid_negatives = np.array(final_negs)
351
-
352
- # Take exactly num_negatives
353
405
  self.negatives_list.append(
354
- torch.tensor(valid_negatives[: self.num_negatives], dtype=torch.long)
406
+ torch.from_numpy(
407
+ draw_negatives(
408
+ rng,
409
+ cumulative,
410
+ drawable,
411
+ self.num_items,
412
+ seen_items,
413
+ self.num_negatives,
414
+ u,
415
+ )
416
+ )
355
417
  )
356
418
 
357
419
  def __len__(self) -> int:
@@ -557,7 +557,9 @@ class Writer(ABC):
557
557
  new_df = pd.DataFrame(time_report)
558
558
  new_df["Inference Time (ms)"] = (new_df.pop("Inference Time") * 1000).round(6)
559
559
  for col in new_df.select_dtypes(include=["float"]).columns:
560
- if "Usage (MB)" in col:
560
+ # A column whose name gives its unit holds a number in that unit;
561
+ # only the unlabelled durations are written as h:mm:ss.
562
+ if col.endswith(("(MB)", "(ms)", "(s)")):
561
563
  new_df[col] = new_df[col].round(6)
562
564
  else:
563
565
  new_df[col] = new_df[col].apply(
@@ -85,6 +85,7 @@ class Evaluator:
85
85
  self.required_blocks: Dict[int, Set[MetricBlock]] = {}
86
86
 
87
87
  # Set the seed for random permutation in sampled evaluation
88
+ self.seed = seed
88
89
  self.g = torch.Generator().manual_seed(seed)
89
90
 
90
91
  # Ties are broken from a stream of their own, so that turning the tie
@@ -210,6 +211,13 @@ class Evaluator:
210
211
  self.metrics_to(device)
211
212
  model.eval()
212
213
 
214
+ # Both random streams start again from the seed, so that a result
215
+ # depends on the model alone: the pipelines evaluate every model and
216
+ # every epoch with one evaluator, and a stream carried over from the
217
+ # previous call would rank tied scores differently each time.
218
+ self.g.manual_seed(self.seed)
219
+ self.tie_g.manual_seed(self.seed)
220
+
213
221
  # Retrieve train interactions for masking (needed in full strategy)
214
222
  train_sparse = dataset.train_set.get_sparse()
215
223
  padding_idx = train_sparse.shape[1]
@@ -1,6 +1,6 @@
1
1
  import time
2
2
  from dataclasses import dataclass
3
- from typing import Any, List, Optional, Tuple
3
+ from typing import Any, Dict, List, Optional, Tuple
4
4
 
5
5
  import ray
6
6
 
@@ -18,8 +18,10 @@ from warprec.data.reader import ReaderFactory
18
18
  from warprec.data.reader.base_reader import Reader
19
19
  from warprec.data.writer import WriterFactory
20
20
  from warprec.data.writer.base_writer import Writer
21
+ from warprec.recommenders.base_recommender import Recommender
21
22
  from warprec.utils.callback import WarpRecCallback
22
23
  from warprec.utils.config import (
24
+ RecomModel,
23
25
  TrainConfiguration,
24
26
  load_callback,
25
27
  load_train_configuration,
@@ -261,6 +263,67 @@ def prepare_datasets(
261
263
  return main_dataset, val_dataset, fold_dataset
262
264
 
263
265
 
266
+ def write_model_outputs(
267
+ context: PipelineContext,
268
+ model_name: str,
269
+ params: RecomModel,
270
+ model: Recommender,
271
+ results: Dict[Any, Any],
272
+ best_iter: int,
273
+ dataset: Dataset,
274
+ ) -> None:
275
+ """Write what a run keeps of one evaluated model.
276
+
277
+ The train and swarm pipelines both call this once a model is evaluated, so
278
+ that either of them leaves the same files behind: the overall and, when
279
+ asked for, per-user results, the best parameters and, when 'meta.save_model'
280
+ is set, the model itself with what serving needs from the data.
281
+
282
+ Args:
283
+ context (PipelineContext): The context produced by the bootstrap.
284
+ model_name (str): The name of the model.
285
+ params (RecomModel): The parameters of the model.
286
+ model (Recommender): The best model found.
287
+ results (Dict[Any, Any]): The evaluation results of the model.
288
+ best_iter (int): The best training iteration.
289
+ dataset (Dataset): The main dataset the model was evaluated on.
290
+ """
291
+ config = context.config
292
+ writer = context.writer
293
+
294
+ writer.write_results(results, model_name, **config.writer.results.model_dump())
295
+
296
+ if config.evaluation.save_per_user:
297
+ i_umap, _ = dataset.get_inverse_mappings()
298
+ writer.write_results_per_user(
299
+ results, model_name, i_umap, **config.writer.results.model_dump()
300
+ )
301
+
302
+ writer.write_params(
303
+ {
304
+ model_name: {
305
+ "Best Params": model.get_params(),
306
+ "Best Training Iteration": best_iter,
307
+ }
308
+ }
309
+ )
310
+
311
+ # Model serialization, with what serving needs from the data
312
+ if params.meta.save_model:
313
+ evaluation: Dict[str, Any] = {"strategy": config.evaluation.strategy}
314
+ if config.evaluation.strategy == "sampled":
315
+ evaluation["num_negatives"] = config.evaluation.num_negatives
316
+ writer.write_model(
317
+ model,
318
+ dataset=dataset,
319
+ training={
320
+ "dataset": config.writer.dataset_name,
321
+ "evaluation": evaluation,
322
+ "metrics": results,
323
+ },
324
+ )
325
+
326
+
264
327
  def report_statistical_significance(
265
328
  context: PipelineContext, model_results: dict, models: list
266
329
  ) -> None:
@@ -11,6 +11,12 @@ import torch
11
11
 
12
12
  from warprec.common import initialize_datasets
13
13
  from warprec.data import Dataset
14
+ from warprec.data.ranking import (
15
+ mask_seen_in_context,
16
+ mask_seen_pairs,
17
+ resolve_mask_policy,
18
+ restrict_to_candidates,
19
+ )
14
20
  from warprec.evaluation import build_evaluator
15
21
  from warprec.recommenders.reranking import build_reranker
16
22
  from warprec.data.reader import ReaderFactory
@@ -309,7 +315,7 @@ def _estimate_eval_loop(
309
315
  measured_batches: int,
310
316
  tracker: EstimateStageTracker,
311
317
  ) -> Dict[str, Any]:
312
- # pylint: disable=too-many-statements
318
+ # pylint: disable=too-many-statements, too-many-branches
313
319
  evaluator.reset_metrics()
314
320
  evaluator.metrics_to(device)
315
321
  model.eval()
@@ -320,6 +326,15 @@ def _estimate_eval_loop(
320
326
  padding_idx = train_sparse.shape[1]
321
327
  max_batches = warmup_batches + measured_batches
322
328
 
329
+ # The batches are run here rather than through Evaluator.evaluate so that
330
+ # each one can be timed, so the same masking policy has to be resolved.
331
+ transactions = dataset.train_transactions
332
+ policy = resolve_mask_policy(evaluator.mask_seen, transactions)
333
+ context_index: Optional[dict] = None
334
+ context_ids: Optional[dict] = None
335
+ if policy == "context" and transactions is not None:
336
+ context_index, context_ids = transactions.get_context_index()
337
+
323
338
  for batch_idx, batch in enumerate(dataloader):
324
339
  if batch_idx >= max_batches:
325
340
  break
@@ -375,10 +390,34 @@ def _estimate_eval_loop(
375
390
  (len(user_indices), evaluator.num_items), device=device
376
391
  )
377
392
  eval_batch.scatter_(1, target_item.unsqueeze(1), 1.0)
393
+ elif "gt_rows" in batch_data:
394
+ # The full loader yields the ground truth sparse, as
395
+ # (users, rows, cols, values): densify it on the device.
396
+ eval_batch = torch.zeros(
397
+ (len(user_indices), evaluator.num_items), device=device
398
+ )
399
+ eval_batch[batch_data["gt_rows"], batch_data["gt_cols"]] = (
400
+ batch_data["gt_vals"]
401
+ )
378
402
  else:
379
403
  eval_batch = batch_data["ground_truth"]
380
404
 
381
- predictions[train_batch.nonzero()] = -torch.inf
405
+ if evaluator.candidate_mask is not None:
406
+ restrict_to_candidates(predictions, evaluator.candidate_mask)
407
+
408
+ if policy == "none":
409
+ pass
410
+ elif context_index is not None and context is not None:
411
+ mask_seen_in_context(
412
+ predictions,
413
+ user_indices,
414
+ context.cpu().numpy(),
415
+ context_index,
416
+ context_ids,
417
+ batch_data.get("target_item"),
418
+ )
419
+ else:
420
+ mask_seen_pairs(predictions, train_batch)
382
421
  else:
383
422
  predictions[candidates == padding_idx] = -torch.inf
384
423