warprec 2.1.8__tar.gz → 2.2.0__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.
- {warprec-2.1.8 → warprec-2.2.0}/PKG-INFO +1 -1
- {warprec-2.1.8 → warprec-2.2.0}/pyproject.toml +1 -1
- {warprec-2.1.8 → warprec-2.2.0}/warprec/__init__.py +2 -1
- {warprec-2.1.8 → warprec-2.2.0}/warprec/common/initialize.py +17 -12
- {warprec-2.1.8 → warprec-2.2.0}/warprec/common/run_state.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/dataset.py +12 -9
- warprec-2.2.0/warprec/data/entities/common.py +355 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/entities/interactions.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/entities/knowledge.py +8 -3
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/entities/multimodal.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/entities/sessions.py +7 -6
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/eval_loaders.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/filtering.py +24 -23
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/ranking.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/reader/azureblob_reader.py +5 -4
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/reader/base_reader.py +9 -8
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/reader/local_reader.py +5 -4
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/schema.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/splitting/splitter.py +5 -4
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/splitting/strategies.py +7 -5
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/stash.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/writer/base_writer.py +7 -6
- warprec-2.2.0/warprec/errors.py +271 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/evaluator.py +5 -4
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/accuracy/logloss.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/base_metric.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/debiased/base.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/fairness/biasdisparitybs.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/multiobjective/euclideandistance.py +5 -4
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/multiobjective/hypervolume.py +5 -4
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/propensity.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/pipelines/common.py +8 -7
- {warprec-2.1.8 → warprec-2.2.0}/warprec/pipelines/estimate.py +107 -18
- {warprec-2.1.8 → warprec-2.2.0}/warprec/pipelines/eval.py +10 -7
- {warprec-2.1.8 → warprec-2.2.0}/warprec/pipelines/remotes/ml.py +4 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/pipelines/swarm.py +168 -3
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/base_recommender.py +13 -10
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/callbacks.py +190 -1
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/cdae.py +6 -3
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/diffrec.py +6 -4
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/dgcf.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/egcf.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/gcmc.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/graph_utils.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/sgl.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/knn/itemknntd.py +4 -3
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/knn/userknntd.py +4 -3
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/neural/twotower.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/content_based_recommender/vsm.py +2 -1
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/context_aware_recommender/dcnv2.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/hybrid_recommender/addease.py +2 -1
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/hybrid_recommender/attributeitemknn.py +2 -1
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/hybrid_recommender/attributeuserknn.py +2 -1
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/hybrid_recommender/cease.py +2 -1
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/knowledge_aware_recommender/kahfm.py +5 -4
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/knowledge_aware_recommender/kgat.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/knowledge_aware_recommender/kgflex.py +5 -4
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/knowledge_aware_recommender/kgin.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/knowledge_aware_recommender/knowledge_utils.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/knowledge_aware_recommender/ripplenet.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/layers.py +5 -4
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/losses.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/multimodal_recommender/bm3.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/multimodal_recommender/lattice.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/multimodal_recommender/mgcn.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/multimodal_recommender/mmgcn.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/multimodal_recommender/multimodal_utils.py +6 -5
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/proxy.py +9 -7
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/reranking/base.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/reranking/calibration.py +9 -5
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/reranking/factory.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/reranking/mmr.py +5 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/sequential_recommender/cl4srec.py +2 -1
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/sequential_recommender/duorec.py +2 -1
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/sequential_recommender/stan.py +2 -1
- warprec-2.2.0/warprec/recommenders/trainer/dashboard_callbacks.py +209 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/trainer/objectives.py +28 -11
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/trainer/trainer.py +36 -9
- warprec-2.2.0/warprec/run.py +103 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/serve.py +41 -8
- warprec-2.2.0/warprec/serving/errors.py +3 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/serving/servable.py +25 -17
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/common.py +69 -26
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/config.py +74 -43
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/estimate_configuration.py +5 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/evaluation_configuration.py +23 -17
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/general_configuration.py +30 -14
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/model_configuration.py +70 -53
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/reader_configuration.py +11 -10
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/recommender_model_config/collaborative_filtering_config/graph_based_config.py +5 -4
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/recommender_model_config/collaborative_filtering_config/neural_config.py +10 -9
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/recommender_model_config/knowledge_aware_config.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/recommender_model_config/sequential_model_config.py +37 -36
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/rerank_configuration.py +10 -4
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/run_configuration.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/serving_configuration.py +31 -23
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/splitter_configuration.py +9 -8
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/training_configuration.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/writer_configuration.py +3 -2
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/helpers.py +36 -11
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/registry.py +94 -17
- warprec-2.1.8/warprec/data/entities/common.py +0 -131
- warprec-2.1.8/warprec/recommenders/trainer/dashboard_callbacks.py +0 -103
- warprec-2.1.8/warprec/run.py +0 -69
- warprec-2.1.8/warprec/serving/errors.py +0 -27
- {warprec-2.1.8 → warprec-2.2.0}/LICENSE +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/README.md +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/common/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/common/std_logs.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/entities/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/entities/context.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/entities/train_structures/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/entities/train_structures/custom_collate_fn.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/entities/train_structures/interaction_structures.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/entities/train_structures/session_structures.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/entities/transactions.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/reader/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/splitting/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/writer/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/writer/azureblob_writer.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/data/writer/local_writer.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/factory.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/accuracy/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/accuracy/auc.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/accuracy/f1.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/accuracy/gauc.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/accuracy/hit_rate.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/accuracy/lauc.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/accuracy/map.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/accuracy/mar.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/accuracy/mrr.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/accuracy/ndcg.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/accuracy/precision.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/accuracy/recall.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/bias/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/bias/aclt.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/bias/aplt.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/bias/arp.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/bias/long_tail.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/bias/pop_reo.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/bias/pop_rsp.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/coverage/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/coverage/item_coverage.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/coverage/numretrieved.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/coverage/user_coverage.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/coverage/user_coverage_at_n.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/debiased/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/debiased/dcg.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/debiased/recall.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/diversity/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/diversity/gini_index.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/diversity/shannon_entropy.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/diversity/srecall.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/fairness/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/fairness/biasdisparitybd.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/fairness/biasdisparitybr.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/fairness/itemmadranking.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/fairness/itemmadrating.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/fairness/reo.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/fairness/rsp.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/fairness/usermadranking.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/fairness/usermadrating.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/multiobjective/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/novelty/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/novelty/efd.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/novelty/epc.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/novelty/novelty_profile.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/rating/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/rating/mae.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/rating/mse.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/metrics/rating/rmse.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/evaluation/statistical_significance.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/pipelines/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/pipelines/design.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/pipelines/remotes/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/pipelines/remotes/data.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/pipelines/train.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/ease.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/elsa.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/macridvae.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/multidae.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/multivae.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/autoencoder/sansa.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/esigcf.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/lightccf.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgcl.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgcn.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgcnpp.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/lightgode.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/macrgcn.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/mixrec.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/ngcf.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/paac.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/popdcl.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/recdcl.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/rp3beta.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/sgcl.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/simgcl.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/simrec.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/ultragcn.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/graph_based/xsimgcl.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/knn/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/knn/itemknn.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/knn/userknn.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/admmslim.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/bpr.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/fism.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/ials.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/ials2008.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/macrmf.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/latent_factor/slim.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/neural/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/neural/convncf.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/collaborative_filtering_recommender/neural/neumf.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/content_based_recommender/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/context_aware_recommender/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/context_aware_recommender/afm.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/context_aware_recommender/dcn.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/context_aware_recommender/deepfm.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/context_aware_recommender/fm.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/context_aware_recommender/nfm.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/context_aware_recommender/wideanddeep.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/context_aware_recommender/xdeepfm.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/hybrid_recommender/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/knowledge_aware_recommender/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/knowledge_aware_recommender/cke.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/knowledge_aware_recommender/kgcn.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/lr_scheduler_wrapper.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/multimodal_recommender/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/multimodal_recommender/freedom.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/multimodal_recommender/vbpr.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/optimizer_wrapper.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/reranking/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/sequential_recommender/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/sequential_recommender/bert4rec.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/sequential_recommender/bsarec.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/sequential_recommender/caser.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/sequential_recommender/core.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/sequential_recommender/esasrec.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/sequential_recommender/fossil.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/sequential_recommender/gru4rec.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/sequential_recommender/gsasrec.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/sequential_recommender/lightsans.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/sequential_recommender/linrec.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/sequential_recommender/narm.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/sequential_recommender/sasrec.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/similarities.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/trainer/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/trainer/logger_callbacks.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/trainer/runtime.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/trainer/scheduler_wrapper.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/trainer/search_algorithm_wrapper.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/unpersonalized_recommender/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/unpersonalized_recommender/pop.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/recommenders/unpersonalized_recommender/random.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/serving/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/serving/api.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/serving/app.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/serving/catalogue.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/serving/context.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/serving/deployments.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/serving/mcp.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/serving/payload.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/serving/schemas.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/callback.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/dashboard_configuration.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/recommender_model_config/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/recommender_model_config/collaborative_filtering_config/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/recommender_model_config/collaborative_filtering_config/autoencoder_config.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/recommender_model_config/collaborative_filtering_config/knn_config.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/recommender_model_config/collaborative_filtering_config/latent_factor_config.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/recommender_model_config/content_based_config.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/recommender_model_config/context_aware_config.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/recommender_model_config/hybrid_config.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/recommender_model_config/multimodal_config.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/recommender_model_config/unpersonalized_config.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/config/search_space_wrapper.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/enums.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/logger/__init__.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/logger/logger.py +0 -0
- {warprec-2.1.8 → warprec-2.2.0}/warprec/utils/pause.py +0 -0
|
@@ -3,6 +3,7 @@ from typing import Tuple, List, Optional, Dict, Union, Any
|
|
|
3
3
|
|
|
4
4
|
from narwhals.dataframe import DataFrame
|
|
5
5
|
|
|
6
|
+
from warprec.errors import ConfigurationError, DataError
|
|
6
7
|
from warprec.data import Dataset
|
|
7
8
|
from warprec.data.reader import Reader
|
|
8
9
|
from warprec.data.schema import ColumnLabels, SplitSpec
|
|
@@ -66,7 +67,7 @@ def _read_modality(
|
|
|
66
67
|
normalisation to apply.
|
|
67
68
|
|
|
68
69
|
Raises:
|
|
69
|
-
|
|
70
|
+
ConfigurationError: If the file format is not one features can be read from.
|
|
70
71
|
"""
|
|
71
72
|
item_label = modality.item_column_name
|
|
72
73
|
# The item column has to be read as the interactions read it, or the rows
|
|
@@ -105,7 +106,7 @@ def _read_modality(
|
|
|
105
106
|
items = frame.select(columns[0]).to_numpy().flatten().tolist()
|
|
106
107
|
features = frame.select(columns[1:]).to_numpy().astype("float32")
|
|
107
108
|
case _:
|
|
108
|
-
raise
|
|
109
|
+
raise ConfigurationError(
|
|
109
110
|
f"The modality '{name}' is configured as "
|
|
110
111
|
f"'{modality.file_format}', which features cannot be read from."
|
|
111
112
|
)
|
|
@@ -138,7 +139,7 @@ def initialize_datasets(
|
|
|
138
139
|
dataset, an optional validation dataset, and a list of datasets for cross-validation folds.
|
|
139
140
|
|
|
140
141
|
Raises:
|
|
141
|
-
|
|
142
|
+
ConfigurationError: If the data type specified in the configuration is not supported.
|
|
142
143
|
"""
|
|
143
144
|
# Dataset loading
|
|
144
145
|
main_dataset: Dataset = None
|
|
@@ -174,7 +175,7 @@ def initialize_datasets(
|
|
|
174
175
|
case "parquet":
|
|
175
176
|
data = reader.read_parquet(location)
|
|
176
177
|
case _:
|
|
177
|
-
raise
|
|
178
|
+
raise ConfigurationError(f"File format '{file_format}'not supported.")
|
|
178
179
|
data = callback.on_data_reading(data)
|
|
179
180
|
|
|
180
181
|
# Check for optional filtering
|
|
@@ -207,7 +208,7 @@ def initialize_datasets(
|
|
|
207
208
|
)
|
|
208
209
|
|
|
209
210
|
else:
|
|
210
|
-
raise
|
|
211
|
+
raise ConfigurationError("Data type not yet supported.")
|
|
211
212
|
|
|
212
213
|
elif config.reader.loading_strategy == "split":
|
|
213
214
|
if config.reader.data_type == "transaction":
|
|
@@ -232,7 +233,9 @@ def initialize_datasets(
|
|
|
232
233
|
ext=split.ext,
|
|
233
234
|
)
|
|
234
235
|
case _:
|
|
235
|
-
raise
|
|
236
|
+
raise ConfigurationError(
|
|
237
|
+
f"File format '{file_format}'not supported."
|
|
238
|
+
)
|
|
236
239
|
|
|
237
240
|
# Filter out train and validation data if not aligned with the training set
|
|
238
241
|
def _align_set_on_train(
|
|
@@ -254,7 +257,7 @@ def initialize_datasets(
|
|
|
254
257
|
),
|
|
255
258
|
)
|
|
256
259
|
if len(eval_set) == 0:
|
|
257
|
-
raise
|
|
260
|
+
raise DataError(
|
|
258
261
|
"After aligning the split with the training set, it resulted in "
|
|
259
262
|
"an empty set. Please check the consistency of your splits and "
|
|
260
263
|
"the filtering process."
|
|
@@ -276,7 +279,7 @@ def initialize_datasets(
|
|
|
276
279
|
else:
|
|
277
280
|
val_data = _align_set_on_train(train_data, val_data, "Validation")
|
|
278
281
|
else:
|
|
279
|
-
raise
|
|
282
|
+
raise ConfigurationError("Data type not yet supported.")
|
|
280
283
|
|
|
281
284
|
# Side information reading
|
|
282
285
|
if config.reader.side:
|
|
@@ -304,14 +307,14 @@ def initialize_datasets(
|
|
|
304
307
|
location, column_names=side.column_names
|
|
305
308
|
)
|
|
306
309
|
case _:
|
|
307
|
-
raise
|
|
310
|
+
raise ConfigurationError(f"File format '{side_format}' not supported.")
|
|
308
311
|
|
|
309
312
|
# Knowledge graph reading
|
|
310
313
|
if config.reader.knowledge:
|
|
311
314
|
knowledge = config.reader.knowledge
|
|
312
315
|
|
|
313
316
|
if knowledge.file_format != "tabular":
|
|
314
|
-
raise
|
|
317
|
+
raise ConfigurationError(
|
|
315
318
|
f"Knowledge graphs are read as tabular files, got "
|
|
316
319
|
f"'{knowledge.file_format}'."
|
|
317
320
|
)
|
|
@@ -361,7 +364,7 @@ def initialize_datasets(
|
|
|
361
364
|
DataFrame[Any]: A DataFrame containing the cluster data.
|
|
362
365
|
|
|
363
366
|
Raises:
|
|
364
|
-
|
|
367
|
+
ConfigurationError: If the file format is not supported.
|
|
365
368
|
"""
|
|
366
369
|
|
|
367
370
|
# Define column names
|
|
@@ -397,7 +400,9 @@ def initialize_datasets(
|
|
|
397
400
|
)
|
|
398
401
|
|
|
399
402
|
case _:
|
|
400
|
-
raise
|
|
403
|
+
raise ConfigurationError(
|
|
404
|
+
f"File format '{file_format}'not supported."
|
|
405
|
+
)
|
|
401
406
|
|
|
402
407
|
return cluster_data
|
|
403
408
|
|
|
@@ -10,6 +10,7 @@ from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING
|
|
|
10
10
|
import numpy as np
|
|
11
11
|
import torch
|
|
12
12
|
|
|
13
|
+
from warprec.errors import RunStateError
|
|
13
14
|
from warprec.utils.logger import logger
|
|
14
15
|
|
|
15
16
|
if TYPE_CHECKING:
|
|
@@ -203,11 +204,11 @@ class RunState:
|
|
|
203
204
|
RunState: The reconstructed run state.
|
|
204
205
|
|
|
205
206
|
Raises:
|
|
206
|
-
|
|
207
|
+
RunStateError: If the manifest was written by a newer WarpRec version.
|
|
207
208
|
"""
|
|
208
209
|
stored_version = data.get("schema_version", 0)
|
|
209
210
|
if stored_version > SCHEMA_VERSION:
|
|
210
|
-
raise
|
|
211
|
+
raise RunStateError(
|
|
211
212
|
f"Run state schema version {stored_version} is newer than the "
|
|
212
213
|
"version supported by this WarpRec installation "
|
|
213
214
|
f"({SCHEMA_VERSION}). Upgrade WarpRec to resume this run."
|
|
@@ -13,6 +13,7 @@ import narwhals as nw
|
|
|
13
13
|
from narwhals.typing import FrameT
|
|
14
14
|
from narwhals.dataframe import DataFrame
|
|
15
15
|
|
|
16
|
+
from warprec.errors import ConfigurationError, DataError
|
|
16
17
|
from warprec.data.entities import (
|
|
17
18
|
Interactions,
|
|
18
19
|
KnowledgeGraph,
|
|
@@ -96,7 +97,7 @@ class Dataset:
|
|
|
96
97
|
built only when at least one modality is configured.
|
|
97
98
|
|
|
98
99
|
Raises:
|
|
99
|
-
|
|
100
|
+
ConfigurationError: If the evaluation_set is not supported.
|
|
100
101
|
"""
|
|
101
102
|
|
|
102
103
|
train_set: Interactions = None
|
|
@@ -145,7 +146,9 @@ class Dataset:
|
|
|
145
146
|
# per structure it derives from them.
|
|
146
147
|
# Check evaluation set
|
|
147
148
|
if evaluation_set not in ["Test", "Validation"]:
|
|
148
|
-
raise
|
|
149
|
+
raise ConfigurationError(
|
|
150
|
+
"Evaluation set must be either 'Test' or 'Validation'."
|
|
151
|
+
)
|
|
149
152
|
|
|
150
153
|
# Materialize the data and ensure
|
|
151
154
|
mat_train_data = self._materialize(train_data)
|
|
@@ -714,11 +717,11 @@ class Dataset:
|
|
|
714
717
|
Optional[DataFrame[Any]]: The processed DataFrame with integer indices.
|
|
715
718
|
|
|
716
719
|
Raises:
|
|
717
|
-
|
|
720
|
+
DataError: If the item ID label is not found in side_data.
|
|
718
721
|
"""
|
|
719
722
|
# Check for item ID label
|
|
720
723
|
if item_id_label not in side_data.columns:
|
|
721
|
-
raise
|
|
724
|
+
raise DataError("Item ID label not found inside side information data.")
|
|
722
725
|
|
|
723
726
|
df_processed = side_data.clone()
|
|
724
727
|
|
|
@@ -789,7 +792,7 @@ class Dataset:
|
|
|
789
792
|
DataFrame[Any]: The frame with the column replaced by its indices.
|
|
790
793
|
|
|
791
794
|
Raises:
|
|
792
|
-
|
|
795
|
+
DataError: If the column was not fitted on the training data first.
|
|
793
796
|
"""
|
|
794
797
|
cells = [
|
|
795
798
|
"" if value is None else str(value)
|
|
@@ -813,7 +816,7 @@ class Dataset:
|
|
|
813
816
|
|
|
814
817
|
mapping = self._context_maps.get(col)
|
|
815
818
|
if mapping is None:
|
|
816
|
-
raise
|
|
819
|
+
raise DataError(
|
|
817
820
|
f"Mapping for context '{col}' not found. Fit on train first."
|
|
818
821
|
)
|
|
819
822
|
|
|
@@ -864,14 +867,14 @@ class Dataset:
|
|
|
864
867
|
DataFrame[Any]: The processed data.
|
|
865
868
|
|
|
866
869
|
Raises:
|
|
867
|
-
|
|
870
|
+
DataError: If the contextual column names are not
|
|
868
871
|
present the the DataFrame.
|
|
869
872
|
"""
|
|
870
873
|
df_processed = df.clone()
|
|
871
874
|
|
|
872
875
|
for col in context_labels:
|
|
873
876
|
if col not in df_processed.columns:
|
|
874
|
-
raise
|
|
877
|
+
raise DataError(f"Context label '{col}' not found in DataFrame.")
|
|
875
878
|
|
|
876
879
|
separator = self._context_separators.get(col)
|
|
877
880
|
if separator or self._context_types.get(col) == "seq":
|
|
@@ -916,7 +919,7 @@ class Dataset:
|
|
|
916
919
|
# Use existing mapping
|
|
917
920
|
mapping = self._context_maps.get(col)
|
|
918
921
|
if mapping is None:
|
|
919
|
-
raise
|
|
922
|
+
raise DataError(
|
|
920
923
|
f"Mapping for context '{col}' not found. Fit on train first."
|
|
921
924
|
)
|
|
922
925
|
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import pickle # nosec B403 - only WarpRec's own worker and checkpoint state
|
|
2
|
+
from typing import Any, Callable, Dict, List, Optional
|
|
3
|
+
|
|
4
|
+
import narwhals as nw
|
|
5
|
+
import numpy as np
|
|
6
|
+
import torch
|
|
7
|
+
from narwhals.dataframe import DataFrame
|
|
8
|
+
from torch.utils.data import DataLoader, Dataset, default_collate
|
|
9
|
+
|
|
10
|
+
USER_INDEX = "__uidx__"
|
|
11
|
+
ITEM_INDEX = "__iidx__"
|
|
12
|
+
ROW_INDEX = "__row__"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _rng_holders(dataset: Any) -> List[Any]:
|
|
16
|
+
"""The objects a training dataset draws its random samples from.
|
|
17
|
+
|
|
18
|
+
A dataset samples either through an 'rng' of its own or through the 'rng'
|
|
19
|
+
of its negative sampler. Seeding a worker and saving a loader's state for a
|
|
20
|
+
resume both have to reach the same generators, so they find them here.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
dataset (Any): The dataset of a DataLoader.
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
List[Any]: The dataset and its sampler, those of them holding an 'rng'.
|
|
27
|
+
"""
|
|
28
|
+
return [
|
|
29
|
+
holder
|
|
30
|
+
for holder in (dataset, getattr(dataset, "sampler", None))
|
|
31
|
+
if hasattr(holder, "rng")
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def get_generator_state(generator: Any) -> Any:
|
|
36
|
+
"""Read the state of a random generator, whatever library it comes from.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
generator (Any): A numpy Generator or RandomState, a torch Generator or
|
|
40
|
+
a Python random.Random.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
Any: A picklable copy of its state.
|
|
44
|
+
"""
|
|
45
|
+
if isinstance(generator, np.random.Generator):
|
|
46
|
+
return generator.bit_generator.state
|
|
47
|
+
if isinstance(generator, (torch.Generator, np.random.RandomState)):
|
|
48
|
+
return generator.get_state()
|
|
49
|
+
return generator.getstate()
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def set_generator_state(generator: Any, state: Any) -> None:
|
|
53
|
+
"""Put a random generator back in a state read by 'get_generator_state'.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
generator (Any): The generator to restore, of the same kind as the one
|
|
57
|
+
the state was read from.
|
|
58
|
+
state (Any): The state.
|
|
59
|
+
"""
|
|
60
|
+
if isinstance(generator, np.random.Generator):
|
|
61
|
+
generator.bit_generator.state = state
|
|
62
|
+
elif isinstance(generator, (torch.Generator, np.random.RandomState)):
|
|
63
|
+
generator.set_state(state)
|
|
64
|
+
else:
|
|
65
|
+
generator.setstate(state)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def seed_worker(worker_id: int) -> None:
|
|
69
|
+
"""Seed a DataLoader worker so that sampling is reproducible.
|
|
70
|
+
|
|
71
|
+
Each worker receives its own copy of the dataset, so without this they would
|
|
72
|
+
all inherit the same generator state and draw the same negatives. Torch
|
|
73
|
+
already gives every worker a distinct, seed-derived initial seed, so that is
|
|
74
|
+
what the copies are reseeded from: the run stays reproducible while the
|
|
75
|
+
workers stay independent of one another.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
worker_id (int): The index of the worker being seeded.
|
|
79
|
+
"""
|
|
80
|
+
worker_seed = torch.initial_seed() % 2**32
|
|
81
|
+
np.random.seed(worker_seed)
|
|
82
|
+
|
|
83
|
+
info = torch.utils.data.get_worker_info()
|
|
84
|
+
for holder in _rng_holders(getattr(info, "dataset", None)):
|
|
85
|
+
holder.rng = np.random.default_rng(worker_seed)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class WorkerRandomState:
|
|
89
|
+
"""Collate function that keeps track of what persistent workers have drawn.
|
|
90
|
+
|
|
91
|
+
A persistent worker keeps its copy of the dataset, and so its sampling
|
|
92
|
+
generators, from one epoch to the next. That state lives in the worker
|
|
93
|
+
process, out of reach of the checkpoint a resumed trial restarts from, so
|
|
94
|
+
a resumed trial used to draw different negatives than the uninterrupted
|
|
95
|
+
run from the first epoch it repeated onwards.
|
|
96
|
+
|
|
97
|
+
The wrapper runs in the worker after every batch it builds. It writes the
|
|
98
|
+
state of the worker's generators to a slot of shared memory, which the
|
|
99
|
+
checkpoint reads at the end of an epoch, when every batch of the epoch has
|
|
100
|
+
been delivered and the workers are idle.
|
|
101
|
+
|
|
102
|
+
Restoring works the other way round. The state is handed to the workers
|
|
103
|
+
when they start, but it must take effect only once they reach the first
|
|
104
|
+
batch of the resumed epoch: the loader iterator Lightning creates before
|
|
105
|
+
the first epoch has already given every worker its first 'prefetch_factor'
|
|
106
|
+
batches, which a resumed trial discards. Each worker therefore counts the
|
|
107
|
+
batches it builds and adopts the saved state after the last discarded one.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
collate_fn (Optional[Callable[[Any], Any]]): The collate function to
|
|
111
|
+
wrap. None stands for PyTorch's default collation.
|
|
112
|
+
num_workers (int): The number of workers of the loader.
|
|
113
|
+
|
|
114
|
+
Attributes:
|
|
115
|
+
SLOT_BYTES (int): The shared memory given to the state of one worker.
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
SLOT_BYTES: int = 16384
|
|
119
|
+
|
|
120
|
+
def __init__(self, collate_fn: Optional[Callable[[Any], Any]], num_workers: int):
|
|
121
|
+
self.collate_fn = collate_fn or default_collate
|
|
122
|
+
self.slots = torch.zeros((num_workers, self.SLOT_BYTES), dtype=torch.uint8)
|
|
123
|
+
self.slots.share_memory_()
|
|
124
|
+
self.pending: Optional[List[Optional[bytes]]] = None
|
|
125
|
+
self.skip: List[int] = []
|
|
126
|
+
self._built = 0
|
|
127
|
+
|
|
128
|
+
def __call__(self, batch: Any) -> Any:
|
|
129
|
+
"""Collate a batch, then record the state of this worker's generators.
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
batch (Any): The samples of the batch.
|
|
133
|
+
|
|
134
|
+
Returns:
|
|
135
|
+
Any: The collated batch.
|
|
136
|
+
"""
|
|
137
|
+
collated = self.collate_fn(batch)
|
|
138
|
+
info = torch.utils.data.get_worker_info()
|
|
139
|
+
if info is None:
|
|
140
|
+
return collated
|
|
141
|
+
|
|
142
|
+
holders = _rng_holders(info.dataset)
|
|
143
|
+
self._built += 1
|
|
144
|
+
if self.pending is not None and self._built == self.skip[info.id]:
|
|
145
|
+
saved = self.pending[info.id]
|
|
146
|
+
if saved is not None:
|
|
147
|
+
states = pickle.loads(saved) # nosec B301 - written by this loader
|
|
148
|
+
for holder, state in zip(holders, states):
|
|
149
|
+
set_generator_state(holder.rng, state)
|
|
150
|
+
self.pending = None
|
|
151
|
+
|
|
152
|
+
record = pickle.dumps([get_generator_state(h.rng) for h in holders])
|
|
153
|
+
slot = self.slots[info.id]
|
|
154
|
+
if len(record) + 4 > self.SLOT_BYTES:
|
|
155
|
+
slot[:4] = torch.tensor([255, 255, 255, 255], dtype=torch.uint8)
|
|
156
|
+
else:
|
|
157
|
+
header = len(record).to_bytes(4, "little")
|
|
158
|
+
slot[: 4 + len(record)] = torch.frombuffer(
|
|
159
|
+
bytearray(header + record), dtype=torch.uint8
|
|
160
|
+
)
|
|
161
|
+
return collated
|
|
162
|
+
|
|
163
|
+
def snapshot(self) -> Optional[List[Optional[bytes]]]:
|
|
164
|
+
"""The last state each worker recorded.
|
|
165
|
+
|
|
166
|
+
Returns:
|
|
167
|
+
Optional[List[Optional[bytes]]]: One entry per worker, None for a
|
|
168
|
+
worker that has built no batch yet. None when a state did not
|
|
169
|
+
fit its slot and cannot be saved.
|
|
170
|
+
"""
|
|
171
|
+
states: List[Optional[bytes]] = []
|
|
172
|
+
for slot in self.slots:
|
|
173
|
+
raw = bytes(slot.numpy())
|
|
174
|
+
size = int.from_bytes(raw[:4], "little")
|
|
175
|
+
if size == 0xFFFFFFFF:
|
|
176
|
+
return None
|
|
177
|
+
states.append(raw[4 : 4 + size] if size else None)
|
|
178
|
+
return states
|
|
179
|
+
|
|
180
|
+
def prime(self, states: List[Optional[bytes]], loader: DataLoader) -> None:
|
|
181
|
+
"""Hand saved states to the workers the loader is about to start.
|
|
182
|
+
|
|
183
|
+
Args:
|
|
184
|
+
states (List[Optional[bytes]]): The states 'snapshot' returned.
|
|
185
|
+
loader (DataLoader): The loader, whose length and prefetch factor
|
|
186
|
+
tell how many batches each worker builds before the epoch the
|
|
187
|
+
trial resumes from.
|
|
188
|
+
"""
|
|
189
|
+
workers = loader.num_workers
|
|
190
|
+
first_requests = min(workers * (loader.prefetch_factor or 2), len(loader))
|
|
191
|
+
self.skip = [len(range(w, first_requests, workers)) for w in range(workers)]
|
|
192
|
+
self.pending = list(states)
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def loader_random_state(loader: DataLoader) -> Dict[str, Any]:
|
|
196
|
+
"""Everything that decides the batches a training loader yields next.
|
|
197
|
+
|
|
198
|
+
Args:
|
|
199
|
+
loader (DataLoader): A loader built by 'seeded_dataloader'.
|
|
200
|
+
|
|
201
|
+
Returns:
|
|
202
|
+
Dict[str, Any]: The state of the shuffling generator, of the dataset's
|
|
203
|
+
sampling generators in this process and, for persistent workers,
|
|
204
|
+
of the copies the workers hold.
|
|
205
|
+
"""
|
|
206
|
+
collate = loader.collate_fn
|
|
207
|
+
return {
|
|
208
|
+
"generator": (
|
|
209
|
+
loader.generator.get_state() if loader.generator is not None else None
|
|
210
|
+
),
|
|
211
|
+
"holders": [get_generator_state(h.rng) for h in _rng_holders(loader.dataset)],
|
|
212
|
+
"workers": (
|
|
213
|
+
collate.snapshot() if isinstance(collate, WorkerRandomState) else None
|
|
214
|
+
),
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def prime_loader_workers(loader: DataLoader, state: Dict[str, Any]) -> bool:
|
|
219
|
+
"""Give a loader's persistent workers the state saved by 'loader_random_state'.
|
|
220
|
+
|
|
221
|
+
Must run before the workers start, that is before the loader is first
|
|
222
|
+
iterated.
|
|
223
|
+
|
|
224
|
+
Args:
|
|
225
|
+
loader (DataLoader): The loader of the resumed trial.
|
|
226
|
+
state (Dict[str, Any]): The saved state.
|
|
227
|
+
|
|
228
|
+
Returns:
|
|
229
|
+
bool: False when the workers' state was needed but could not be saved
|
|
230
|
+
or restored, so that the resumed epochs will draw other samples.
|
|
231
|
+
"""
|
|
232
|
+
collate = loader.collate_fn
|
|
233
|
+
if not isinstance(collate, WorkerRandomState):
|
|
234
|
+
return True
|
|
235
|
+
if state.get("workers") is None or len(state["workers"]) != loader.num_workers:
|
|
236
|
+
return False
|
|
237
|
+
collate.prime(state["workers"], loader)
|
|
238
|
+
return True
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def restore_loader_random_state(loader: DataLoader, state: Dict[str, Any]) -> None:
|
|
242
|
+
"""Restore the shuffling and sampling state saved by 'loader_random_state'.
|
|
243
|
+
|
|
244
|
+
Args:
|
|
245
|
+
loader (DataLoader): The loader of the resumed trial.
|
|
246
|
+
state (Dict[str, Any]): The saved state.
|
|
247
|
+
"""
|
|
248
|
+
if loader.generator is not None and state.get("generator") is not None:
|
|
249
|
+
loader.generator.set_state(state["generator"])
|
|
250
|
+
for holder, saved in zip(_rng_holders(loader.dataset), state.get("holders", [])):
|
|
251
|
+
set_generator_state(holder.rng, saved)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def seeded_dataloader(
|
|
255
|
+
dataset: Dataset,
|
|
256
|
+
batch_size: int,
|
|
257
|
+
shuffle: bool,
|
|
258
|
+
seed: int,
|
|
259
|
+
**kwargs: Any,
|
|
260
|
+
) -> DataLoader:
|
|
261
|
+
"""Wrap a dataset in a DataLoader whose shuffling and sampling are reproducible.
|
|
262
|
+
|
|
263
|
+
Every entity builds its loaders the same way, so the generator and the worker
|
|
264
|
+
seeding live here rather than being repeated at each call site, where one copy
|
|
265
|
+
could silently drift from the rest.
|
|
266
|
+
|
|
267
|
+
Args:
|
|
268
|
+
dataset (Dataset): The dataset to iterate.
|
|
269
|
+
batch_size (int): The batch size.
|
|
270
|
+
shuffle (bool): Whether to shuffle the data.
|
|
271
|
+
seed (int): The seed that makes an epoch reproducible.
|
|
272
|
+
**kwargs (Any): Additional keyword arguments for the DataLoader.
|
|
273
|
+
|
|
274
|
+
Returns:
|
|
275
|
+
DataLoader: The seeded loader.
|
|
276
|
+
"""
|
|
277
|
+
generator = torch.Generator()
|
|
278
|
+
generator.manual_seed(seed)
|
|
279
|
+
|
|
280
|
+
# Persistent workers carry their sampling state across epochs, so it is
|
|
281
|
+
# tracked for a trial that is paused and resumed.
|
|
282
|
+
num_workers = kwargs.get("num_workers", 0)
|
|
283
|
+
if num_workers > 0 and kwargs.get("persistent_workers", False):
|
|
284
|
+
kwargs["collate_fn"] = WorkerRandomState(kwargs.get("collate_fn"), num_workers)
|
|
285
|
+
|
|
286
|
+
return DataLoader(
|
|
287
|
+
dataset,
|
|
288
|
+
batch_size=batch_size,
|
|
289
|
+
shuffle=shuffle,
|
|
290
|
+
worker_init_fn=seed_worker,
|
|
291
|
+
generator=generator,
|
|
292
|
+
**kwargs,
|
|
293
|
+
)
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def map_to_index_space(
|
|
297
|
+
data: DataFrame[Any],
|
|
298
|
+
user_label: str,
|
|
299
|
+
item_label: str,
|
|
300
|
+
user_mapping: dict,
|
|
301
|
+
item_mapping: dict,
|
|
302
|
+
keep: Optional[list] = None,
|
|
303
|
+
) -> DataFrame[Any]:
|
|
304
|
+
"""Attach the user and item indices to a frame of raw interactions.
|
|
305
|
+
|
|
306
|
+
The two joins are inner ones on purpose: a row naming a user or an item the
|
|
307
|
+
mappings do not know is outside the catalogue the experiment was built on and
|
|
308
|
+
is dropped. That rule is the reason this lives in one place - the row-oriented
|
|
309
|
+
entities each used to carry their own copy of it, and a copy is a chance for
|
|
310
|
+
the two to disagree about which rows exist.
|
|
311
|
+
|
|
312
|
+
A join does not promise to keep the rows in their input order (polars does
|
|
313
|
+
not), so each row also carries its position in the input, ``ROW_INDEX``.
|
|
314
|
+
Sorting on it after the indices keeps repeated (user, item) rows in file
|
|
315
|
+
order, which is what the 'first' and 'last' duplicate policies mean.
|
|
316
|
+
|
|
317
|
+
Args:
|
|
318
|
+
data (DataFrame[Any]): The raw interactions.
|
|
319
|
+
user_label (str): The name of the user column.
|
|
320
|
+
item_label (str): The name of the item column.
|
|
321
|
+
user_mapping (dict): Mapping of user ID -> user index.
|
|
322
|
+
item_mapping (dict): Mapping of item ID -> item index.
|
|
323
|
+
keep (Optional[list]): Columns to carry through in addition to the
|
|
324
|
+
indices. Left out, every column of the input is kept.
|
|
325
|
+
|
|
326
|
+
Returns:
|
|
327
|
+
DataFrame[Any]: The frame with the index and row position columns attached.
|
|
328
|
+
"""
|
|
329
|
+
namespace = nw.get_native_namespace(data)
|
|
330
|
+
umap_df = nw.from_dict(
|
|
331
|
+
{
|
|
332
|
+
user_label: list(user_mapping.keys()),
|
|
333
|
+
USER_INDEX: list(user_mapping.values()),
|
|
334
|
+
},
|
|
335
|
+
native_namespace=namespace,
|
|
336
|
+
)
|
|
337
|
+
imap_df = nw.from_dict(
|
|
338
|
+
{
|
|
339
|
+
item_label: list(item_mapping.keys()),
|
|
340
|
+
ITEM_INDEX: list(item_mapping.values()),
|
|
341
|
+
},
|
|
342
|
+
native_namespace=namespace,
|
|
343
|
+
)
|
|
344
|
+
|
|
345
|
+
mapped = (
|
|
346
|
+
data.with_row_index(ROW_INDEX)
|
|
347
|
+
.join(umap_df, on=user_label, how="inner")
|
|
348
|
+
.join(imap_df, on=item_label, how="inner")
|
|
349
|
+
)
|
|
350
|
+
|
|
351
|
+
if keep is None:
|
|
352
|
+
return mapped
|
|
353
|
+
return mapped.select(
|
|
354
|
+
[nw.col(c) for c in (*keep, USER_INDEX, ITEM_INDEX, ROW_INDEX)]
|
|
355
|
+
)
|
|
@@ -8,6 +8,7 @@ from torch.utils.data import DataLoader
|
|
|
8
8
|
from narwhals.dataframe import DataFrame
|
|
9
9
|
from scipy.sparse import csr_matrix, coo_matrix
|
|
10
10
|
|
|
11
|
+
from warprec.errors import ConfigurationError
|
|
11
12
|
from warprec.data.entities.train_structures import (
|
|
12
13
|
InteractionDataset,
|
|
13
14
|
PointWiseDataset,
|
|
@@ -298,11 +299,11 @@ class Interactions:
|
|
|
298
299
|
coo_matrix: A sparse matrix of shape [num_users, num_items] for the given rating.
|
|
299
300
|
|
|
300
301
|
Raises:
|
|
301
|
-
|
|
302
|
+
ConfigurationError: If interactions are not explicit or if
|
|
302
303
|
rating label is None.
|
|
303
304
|
"""
|
|
304
305
|
if self.rating_type != RatingType.EXPLICIT or self.rating_label is None:
|
|
305
|
-
raise
|
|
306
|
+
raise ConfigurationError(
|
|
306
307
|
"Filtering by rating is only supported for explicit feedback data."
|
|
307
308
|
)
|
|
308
309
|
|
|
@@ -5,6 +5,7 @@ import torch
|
|
|
5
5
|
from narwhals.dataframe import DataFrame
|
|
6
6
|
from torch import Tensor
|
|
7
7
|
|
|
8
|
+
from warprec.errors import ConfigurationError
|
|
8
9
|
from warprec.utils.logger import logger
|
|
9
10
|
|
|
10
11
|
|
|
@@ -324,12 +325,16 @@ class KnowledgeGraph:
|
|
|
324
325
|
the identifiers the graph was read with.
|
|
325
326
|
|
|
326
327
|
Raises:
|
|
327
|
-
|
|
328
|
+
ConfigurationError: If the order is not 1 or 2, or min_items is below 1.
|
|
328
329
|
"""
|
|
329
330
|
if order not in (1, 2):
|
|
330
|
-
raise
|
|
331
|
+
raise ConfigurationError(
|
|
332
|
+
f"An item feature is one or two facts long, not {order}."
|
|
333
|
+
)
|
|
331
334
|
if min_items < 1:
|
|
332
|
-
raise
|
|
335
|
+
raise ConfigurationError(
|
|
336
|
+
f"min_items must be at least 1, received {min_items}."
|
|
337
|
+
)
|
|
333
338
|
|
|
334
339
|
key = (order, min_items)
|
|
335
340
|
if key not in self._item_features:
|
|
@@ -4,6 +4,7 @@ import numpy as np
|
|
|
4
4
|
import torch
|
|
5
5
|
from torch import Tensor
|
|
6
6
|
|
|
7
|
+
from warprec.errors import DataError
|
|
7
8
|
from warprec.utils.logger import logger
|
|
8
9
|
|
|
9
10
|
|
|
@@ -87,11 +88,11 @@ class MultiModalFeatures:
|
|
|
87
88
|
many items of the catalogue it actually covers.
|
|
88
89
|
|
|
89
90
|
Raises:
|
|
90
|
-
|
|
91
|
+
DataError: If the matrix and its row order disagree on how many
|
|
91
92
|
rows there are.
|
|
92
93
|
"""
|
|
93
94
|
if len(row_items) != matrix.shape[0]:
|
|
94
|
-
raise
|
|
95
|
+
raise DataError(
|
|
95
96
|
f"The features hold {matrix.shape[0]} rows but their row order "
|
|
96
97
|
f"names {len(row_items)} items. The two files do not describe "
|
|
97
98
|
"the same modality."
|