dslighting 1.7.1__py3-none-any.whl → 1.7.8__py3-none-any.whl
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.
- dslighting/__init__.py +1 -1
- dslighting/core/agent.py +78 -62
- {dslighting-1.7.1.dist-info → dslighting-1.7.8.dist-info}/METADATA +3 -1
- {dslighting-1.7.1.dist-info → dslighting-1.7.8.dist-info}/RECORD +352 -7
- {dslighting-1.7.1.dist-info → dslighting-1.7.8.dist-info}/top_level.txt +1 -0
- mlebench/README.md +39 -0
- mlebench/__init__.py +0 -0
- mlebench/cli.py +221 -0
- mlebench/competitions/3d-object-detection-for-autonomous-vehicles/grade.py +161 -0
- mlebench/competitions/3d-object-detection-for-autonomous-vehicles/mAP_evaluation.py +425 -0
- mlebench/competitions/3d-object-detection-for-autonomous-vehicles/prepare.py +483 -0
- mlebench/competitions/3d-object-detection-for-autonomous-vehicles/prepare_val.py +719 -0
- mlebench/competitions/AI4Code/grade.py +70 -0
- mlebench/competitions/AI4Code/prepare.py +84 -0
- mlebench/competitions/AI4Code/prepare_val.py +159 -0
- mlebench/competitions/__init__.py +0 -0
- mlebench/competitions/aerial-cactus-identification/grade.py +11 -0
- mlebench/competitions/aerial-cactus-identification/prepare.py +71 -0
- mlebench/competitions/aerial-cactus-identification/prepare_val.py +133 -0
- mlebench/competitions/alaska2-image-steganalysis/grade.py +136 -0
- mlebench/competitions/alaska2-image-steganalysis/prepare.py +88 -0
- mlebench/competitions/alaska2-image-steganalysis/prepare_val.py +148 -0
- mlebench/competitions/aptos2019-blindness-detection/grade.py +35 -0
- mlebench/competitions/aptos2019-blindness-detection/prepare.py +75 -0
- mlebench/competitions/aptos2019-blindness-detection/prepare_val.py +123 -0
- mlebench/competitions/bike-sharing-demand/__init__.py +0 -0
- mlebench/competitions/bike-sharing-demand/grade.py +55 -0
- mlebench/competitions/bike-sharing-demand/prepare.py +37 -0
- mlebench/competitions/billion-word-imputation/grade.py +37 -0
- mlebench/competitions/billion-word-imputation/prepare.py +107 -0
- mlebench/competitions/billion-word-imputation/prepare_val.py +179 -0
- mlebench/competitions/bms-molecular-translation/grade.py +40 -0
- mlebench/competitions/bms-molecular-translation/prepare.py +68 -0
- mlebench/competitions/bms-molecular-translation/prepare_val.py +131 -0
- mlebench/competitions/cassava-leaf-disease-classification/grade.py +12 -0
- mlebench/competitions/cassava-leaf-disease-classification/prepare.py +113 -0
- mlebench/competitions/cassava-leaf-disease-classification/prepare_val.py +186 -0
- mlebench/competitions/cdiscount-image-classification-challenge/grade.py +11 -0
- mlebench/competitions/cdiscount-image-classification-challenge/prepare.py +144 -0
- mlebench/competitions/cdiscount-image-classification-challenge/prepare_val.py +205 -0
- mlebench/competitions/chaii-hindi-and-tamil-question-answering/grade.py +67 -0
- mlebench/competitions/chaii-hindi-and-tamil-question-answering/prepare.py +31 -0
- mlebench/competitions/chaii-hindi-and-tamil-question-answering/prepare_val.py +94 -0
- mlebench/competitions/champs-scalar-coupling/grade.py +60 -0
- mlebench/competitions/champs-scalar-coupling/prepare.py +116 -0
- mlebench/competitions/champs-scalar-coupling/prepare_val.py +155 -0
- mlebench/competitions/conways-reverse-game-of-life-2020/__init__.py +0 -0
- mlebench/competitions/conways-reverse-game-of-life-2020/grade.py +40 -0
- mlebench/competitions/conways-reverse-game-of-life-2020/prepare.py +41 -0
- mlebench/competitions/demand-forecasting-kernels-only/__init__.py +0 -0
- mlebench/competitions/demand-forecasting-kernels-only/grade.py +66 -0
- mlebench/competitions/demand-forecasting-kernels-only/prepare.py +27 -0
- mlebench/competitions/demand_forecasting_kernels_only/__init__.py +0 -0
- mlebench/competitions/demand_forecasting_kernels_only/grade.py +66 -0
- mlebench/competitions/demand_forecasting_kernels_only/prepare.py +27 -0
- mlebench/competitions/denoising-dirty-documents/grade.py +44 -0
- mlebench/competitions/denoising-dirty-documents/prepare.py +134 -0
- mlebench/competitions/denoising-dirty-documents/prepare_val.py +178 -0
- mlebench/competitions/detecting-insults-in-social-commentary/grade.py +11 -0
- mlebench/competitions/detecting-insults-in-social-commentary/prepare.py +72 -0
- mlebench/competitions/detecting-insults-in-social-commentary/prepare_val.py +128 -0
- mlebench/competitions/dog-breed-identification/dogs.py +124 -0
- mlebench/competitions/dog-breed-identification/grade.py +42 -0
- mlebench/competitions/dog-breed-identification/prepare.py +55 -0
- mlebench/competitions/dog-breed-identification/prepare_val.py +104 -0
- mlebench/competitions/dogs-vs-cats-redux-kernels-edition/grade.py +43 -0
- mlebench/competitions/dogs-vs-cats-redux-kernels-edition/prepare.py +70 -0
- mlebench/competitions/dogs-vs-cats-redux-kernels-edition/prepare_val.py +143 -0
- mlebench/competitions/ethanol-concentration/grade.py +23 -0
- mlebench/competitions/ethanol-concentration/prepare.py +90 -0
- mlebench/competitions/facebook-recruiting-iii-keyword-extraction/grade.py +60 -0
- mlebench/competitions/facebook-recruiting-iii-keyword-extraction/prepare.py +41 -0
- mlebench/competitions/facebook-recruiting-iii-keyword-extraction/prepare_val.py +92 -0
- mlebench/competitions/feedback-prize-english-language-learning/__init__.py +0 -0
- mlebench/competitions/feedback-prize-english-language-learning/grade.py +60 -0
- mlebench/competitions/feedback-prize-english-language-learning/prepare.py +39 -0
- mlebench/competitions/freesound-audio-tagging-2019/grade.py +64 -0
- mlebench/competitions/freesound-audio-tagging-2019/prepare.py +94 -0
- mlebench/competitions/freesound-audio-tagging-2019/prepare_val.py +175 -0
- mlebench/competitions/freesound-audio-tagging-2019/vocabulary.py +83 -0
- mlebench/competitions/google-quest-challenge/classes.py +32 -0
- mlebench/competitions/google-quest-challenge/grade.py +45 -0
- mlebench/competitions/google-quest-challenge/prepare.py +58 -0
- mlebench/competitions/google-quest-challenge/prepare_val.py +120 -0
- mlebench/competitions/google-research-identify-contrails-reduce-global-warming/grade.py +77 -0
- mlebench/competitions/google-research-identify-contrails-reduce-global-warming/prepare.py +155 -0
- mlebench/competitions/google-research-identify-contrails-reduce-global-warming/prepare_val.py +211 -0
- mlebench/competitions/h-and-m-personalized-fashion-recommendations/grade.py +42 -0
- mlebench/competitions/h-and-m-personalized-fashion-recommendations/prepare.py +102 -0
- mlebench/competitions/h-and-m-personalized-fashion-recommendations/prepare_val.py +132 -0
- mlebench/competitions/handwriting/grade.py +23 -0
- mlebench/competitions/handwriting/prepare.py +179 -0
- mlebench/competitions/herbarium-2020-fgvc7/grade.py +34 -0
- mlebench/competitions/herbarium-2020-fgvc7/prepare.py +251 -0
- mlebench/competitions/herbarium-2020-fgvc7/prepare_val.py +242 -0
- mlebench/competitions/herbarium-2021-fgvc8/grade.py +34 -0
- mlebench/competitions/herbarium-2021-fgvc8/prepare.py +251 -0
- mlebench/competitions/herbarium-2021-fgvc8/prepare_val.py +222 -0
- mlebench/competitions/herbarium-2022-fgvc9/grade.py +31 -0
- mlebench/competitions/herbarium-2022-fgvc9/prepare.py +233 -0
- mlebench/competitions/herbarium-2022-fgvc9/prepare_val.py +213 -0
- mlebench/competitions/histopathologic-cancer-detection/grade.py +12 -0
- mlebench/competitions/histopathologic-cancer-detection/prepare.py +59 -0
- mlebench/competitions/histopathologic-cancer-detection/prepare_val.py +131 -0
- mlebench/competitions/hms-harmful-brain-activity-classification/constants.py +9 -0
- mlebench/competitions/hms-harmful-brain-activity-classification/grade.py +43 -0
- mlebench/competitions/hms-harmful-brain-activity-classification/kaggle_metric_utilities.py +96 -0
- mlebench/competitions/hms-harmful-brain-activity-classification/kullback_leibler_divergence.py +118 -0
- mlebench/competitions/hms-harmful-brain-activity-classification/prepare.py +121 -0
- mlebench/competitions/hms-harmful-brain-activity-classification/prepare_val.py +190 -0
- mlebench/competitions/hotel-id-2021-fgvc8/grade.py +41 -0
- mlebench/competitions/hotel-id-2021-fgvc8/prepare.py +63 -0
- mlebench/competitions/hotel-id-2021-fgvc8/prepare_val.py +132 -0
- mlebench/competitions/hubmap-kidney-segmentation/grade.py +62 -0
- mlebench/competitions/hubmap-kidney-segmentation/prepare.py +108 -0
- mlebench/competitions/hubmap-kidney-segmentation/prepare_val.py +153 -0
- mlebench/competitions/icecube-neutrinos-in-deep-ice/grade.py +111 -0
- mlebench/competitions/icecube-neutrinos-in-deep-ice/prepare.py +127 -0
- mlebench/competitions/icecube-neutrinos-in-deep-ice/prepare_val.py +183 -0
- mlebench/competitions/ili/grade.py +60 -0
- mlebench/competitions/ili/prepare.py +99 -0
- mlebench/competitions/imet-2020-fgvc7/grade.py +54 -0
- mlebench/competitions/imet-2020-fgvc7/prepare.py +77 -0
- mlebench/competitions/imet-2020-fgvc7/prepare_val.py +157 -0
- mlebench/competitions/inaturalist-2019-fgvc6/grade.py +35 -0
- mlebench/competitions/inaturalist-2019-fgvc6/prepare.py +259 -0
- mlebench/competitions/inaturalist-2019-fgvc6/prepare_val.py +304 -0
- mlebench/competitions/instant-gratification/__init__.py +0 -0
- mlebench/competitions/instant-gratification/grade.py +55 -0
- mlebench/competitions/instant-gratification/prepare.py +25 -0
- mlebench/competitions/instant_gratification/__init__.py +0 -0
- mlebench/competitions/instant_gratification/grade.py +55 -0
- mlebench/competitions/instant_gratification/prepare.py +25 -0
- mlebench/competitions/invasive-species-monitoring/grade.py +11 -0
- mlebench/competitions/invasive-species-monitoring/prepare.py +97 -0
- mlebench/competitions/invasive-species-monitoring/prepare_val.py +164 -0
- mlebench/competitions/iwildcam-2019-fgvc6/grade.py +44 -0
- mlebench/competitions/iwildcam-2019-fgvc6/prepare.py +118 -0
- mlebench/competitions/iwildcam-2019-fgvc6/prepare_val.py +194 -0
- mlebench/competitions/iwildcam-2020-fgvc7/grade.py +11 -0
- mlebench/competitions/iwildcam-2020-fgvc7/prepare.py +164 -0
- mlebench/competitions/iwildcam-2020-fgvc7/prepare_val.py +245 -0
- mlebench/competitions/jigsaw-toxic-comment-classification-challenge/classes.py +1 -0
- mlebench/competitions/jigsaw-toxic-comment-classification-challenge/grade.py +54 -0
- mlebench/competitions/jigsaw-toxic-comment-classification-challenge/prepare.py +42 -0
- mlebench/competitions/jigsaw-toxic-comment-classification-challenge/prepare_val.py +88 -0
- mlebench/competitions/jigsaw-unintended-bias-in-toxicity-classification/grade.py +153 -0
- mlebench/competitions/jigsaw-unintended-bias-in-toxicity-classification/prepare.py +36 -0
- mlebench/competitions/jigsaw-unintended-bias-in-toxicity-classification/prepare_val.py +117 -0
- mlebench/competitions/kuzushiji-recognition/grade.py +58 -0
- mlebench/competitions/kuzushiji-recognition/kuzushiji_metric.py +118 -0
- mlebench/competitions/kuzushiji-recognition/prepare.py +92 -0
- mlebench/competitions/kuzushiji-recognition/prepare_val.py +149 -0
- mlebench/competitions/leaf-classification/classes.py +101 -0
- mlebench/competitions/leaf-classification/grade.py +44 -0
- mlebench/competitions/leaf-classification/prepare.py +60 -0
- mlebench/competitions/leaf-classification/prepare_val.py +116 -0
- mlebench/competitions/learning-agency-lab-automated-essay-scoring-2/grade.py +44 -0
- mlebench/competitions/learning-agency-lab-automated-essay-scoring-2/prepare.py +51 -0
- mlebench/competitions/learning-agency-lab-automated-essay-scoring-2/prepare_val.py +96 -0
- mlebench/competitions/liverpool-ion-switching/__init__.py +0 -0
- mlebench/competitions/liverpool-ion-switching/grade.py +52 -0
- mlebench/competitions/liverpool-ion-switching/prepare.py +27 -0
- mlebench/competitions/liverpool_ion_switching/__init__.py +0 -0
- mlebench/competitions/liverpool_ion_switching/grade.py +52 -0
- mlebench/competitions/liverpool_ion_switching/prepare.py +27 -0
- mlebench/competitions/lmsys-chatbot-arena/grade.py +63 -0
- mlebench/competitions/lmsys-chatbot-arena/prepare.py +52 -0
- mlebench/competitions/lmsys-chatbot-arena/prepare_val.py +115 -0
- mlebench/competitions/mcm_2024_c_test/grade.py +107 -0
- mlebench/competitions/mcm_2024_c_test/prepare.py +2 -0
- mlebench/competitions/ml2021spring-hw2/grade.py +11 -0
- mlebench/competitions/ml2021spring-hw2/prepare.py +58 -0
- mlebench/competitions/ml2021spring-hw2/prepare_val.py +135 -0
- mlebench/competitions/mlsp-2013-birds/grade.py +11 -0
- mlebench/competitions/mlsp-2013-birds/prepare.py +182 -0
- mlebench/competitions/mlsp-2013-birds/prepare_val.py +241 -0
- mlebench/competitions/movie-review-sentiment-analysis-kernels-only/grade.py +11 -0
- mlebench/competitions/movie-review-sentiment-analysis-kernels-only/prepare.py +58 -0
- mlebench/competitions/movie-review-sentiment-analysis-kernels-only/prepare_val.py +120 -0
- mlebench/competitions/multi-modal-gesture-recognition/grade.py +58 -0
- mlebench/competitions/multi-modal-gesture-recognition/prepare.py +85 -0
- mlebench/competitions/multi-modal-gesture-recognition/prepare_val.py +139 -0
- mlebench/competitions/my-custom-task-01/prepare.py +2 -0
- mlebench/competitions/new-my-task-01/prepare.py +2 -0
- mlebench/competitions/new-my-task-03/grade.py +107 -0
- mlebench/competitions/new-my-task-03/prepare.py +2 -0
- mlebench/competitions/new-york-city-taxi-fare-prediction/grade.py +28 -0
- mlebench/competitions/new-york-city-taxi-fare-prediction/prepare.py +44 -0
- mlebench/competitions/new-york-city-taxi-fare-prediction/prepare_val.py +89 -0
- mlebench/competitions/nfl-player-contact-detection/grade.py +36 -0
- mlebench/competitions/nfl-player-contact-detection/prepare.py +101 -0
- mlebench/competitions/nfl-player-contact-detection/prepare_val.py +186 -0
- mlebench/competitions/nomad2018-predict-transparent-conductors/grade.py +47 -0
- mlebench/competitions/nomad2018-predict-transparent-conductors/prepare.py +77 -0
- mlebench/competitions/nomad2018-predict-transparent-conductors/prepare_val.py +144 -0
- mlebench/competitions/osic-pulmonary-fibrosis-progression/grade.py +74 -0
- mlebench/competitions/osic-pulmonary-fibrosis-progression/prepare.py +95 -0
- mlebench/competitions/osic-pulmonary-fibrosis-progression/prepare_val.py +167 -0
- mlebench/competitions/paddy-disease-classification/grade.py +35 -0
- mlebench/competitions/paddy-disease-classification/prepare.py +69 -0
- mlebench/competitions/paddy-disease-classification/prepare_val.py +122 -0
- mlebench/competitions/petfinder-pawpularity-score/grade.py +41 -0
- mlebench/competitions/petfinder-pawpularity-score/prepare.py +76 -0
- mlebench/competitions/petfinder-pawpularity-score/prepare_val.py +154 -0
- mlebench/competitions/plant-pathology-2020-fgvc7/grade.py +41 -0
- mlebench/competitions/plant-pathology-2020-fgvc7/prepare.py +74 -0
- mlebench/competitions/plant-pathology-2020-fgvc7/prepare_val.py +160 -0
- mlebench/competitions/plant-pathology-2021-fgvc8/grade.py +54 -0
- mlebench/competitions/plant-pathology-2021-fgvc8/prepare.py +65 -0
- mlebench/competitions/plant-pathology-2021-fgvc8/prepare_val.py +130 -0
- mlebench/competitions/plant-seedlings-classification/grade.py +39 -0
- mlebench/competitions/plant-seedlings-classification/prepare.py +91 -0
- mlebench/competitions/plant-seedlings-classification/prepare_val.py +158 -0
- mlebench/competitions/playground-series-s3e1/__init__.py +0 -0
- mlebench/competitions/playground-series-s3e1/grade.py +52 -0
- mlebench/competitions/playground-series-s3e1/prepare.py +25 -0
- mlebench/competitions/playground-series-s3e11/__init__.py +0 -0
- mlebench/competitions/playground-series-s3e11/grade.py +55 -0
- mlebench/competitions/playground-series-s3e11/prepare.py +25 -0
- mlebench/competitions/playground-series-s3e18/grade.py +39 -0
- mlebench/competitions/playground-series-s3e18/prepare.py +36 -0
- mlebench/competitions/playground-series-s3e18/prepare_val.py +89 -0
- mlebench/competitions/playground_series_s3e1/__init__.py +0 -0
- mlebench/competitions/playground_series_s3e1/grade.py +52 -0
- mlebench/competitions/playground_series_s3e1/prepare.py +25 -0
- mlebench/competitions/playground_series_s3e11/__init__.py +0 -0
- mlebench/competitions/playground_series_s3e11/grade.py +55 -0
- mlebench/competitions/playground_series_s3e11/prepare.py +25 -0
- mlebench/competitions/predict-volcanic-eruptions-ingv-oe/grade.py +44 -0
- mlebench/competitions/predict-volcanic-eruptions-ingv-oe/prepare.py +68 -0
- mlebench/competitions/predict-volcanic-eruptions-ingv-oe/prepare_val.py +146 -0
- mlebench/competitions/random-acts-of-pizza/grade.py +14 -0
- mlebench/competitions/random-acts-of-pizza/prepare.py +80 -0
- mlebench/competitions/random-acts-of-pizza/prepare_val.py +144 -0
- mlebench/competitions/ranzcr-clip-catheter-line-classification/classes.py +11 -0
- mlebench/competitions/ranzcr-clip-catheter-line-classification/grade.py +31 -0
- mlebench/competitions/ranzcr-clip-catheter-line-classification/prepare.py +53 -0
- mlebench/competitions/ranzcr-clip-catheter-line-classification/prepare_val.py +113 -0
- mlebench/competitions/rsna-2022-cervical-spine-fracture-detection/grade.py +124 -0
- mlebench/competitions/rsna-2022-cervical-spine-fracture-detection/prepare.py +219 -0
- mlebench/competitions/rsna-2022-cervical-spine-fracture-detection/prepare_val.py +257 -0
- mlebench/competitions/rsna-breast-cancer-detection/grade.py +65 -0
- mlebench/competitions/rsna-breast-cancer-detection/prepare.py +141 -0
- mlebench/competitions/rsna-breast-cancer-detection/prepare_val.py +201 -0
- mlebench/competitions/rsna-miccai-brain-tumor-radiogenomic-classification/grade.py +13 -0
- mlebench/competitions/rsna-miccai-brain-tumor-radiogenomic-classification/prepare.py +47 -0
- mlebench/competitions/rsna-miccai-brain-tumor-radiogenomic-classification/prepare_val.py +97 -0
- mlebench/competitions/santander-customer-satisfaction/grade.py +10 -0
- mlebench/competitions/santander-customer-satisfaction/prepare.py +41 -0
- mlebench/competitions/sciencebench-001-clintox-nn/__init__.py +0 -0
- mlebench/competitions/sciencebench-001-clintox-nn/grade.py +56 -0
- mlebench/competitions/sciencebench-001-clintox-nn/prepare.py +75 -0
- mlebench/competitions/sciencebench-015-aai/grade.py +37 -0
- mlebench/competitions/sciencebench-015-aai/prepare.py +102 -0
- mlebench/competitions/sciencebench-051-brain-blood-qsar/grade.py +58 -0
- mlebench/competitions/sciencebench-051-brain-blood-qsar/prepare.py +69 -0
- mlebench/competitions/sciencebench-101-experimental-band-gap-prediction/grade.py +55 -0
- mlebench/competitions/sciencebench-101-experimental-band-gap-prediction/prepare.py +88 -0
- mlebench/competitions/see-click-predict-fix/__init__.py +0 -0
- mlebench/competitions/see-click-predict-fix/grade.py +66 -0
- mlebench/competitions/see-click-predict-fix/prepare.py +25 -0
- mlebench/competitions/see_click_predict_fix/__init__.py +0 -0
- mlebench/competitions/see_click_predict_fix/grade.py +66 -0
- mlebench/competitions/see_click_predict_fix/prepare.py +25 -0
- mlebench/competitions/seti-breakthrough-listen/grade.py +11 -0
- mlebench/competitions/seti-breakthrough-listen/prepare.py +71 -0
- mlebench/competitions/seti-breakthrough-listen/prepare_val.py +159 -0
- mlebench/competitions/siim-covid19-detection/grade.py +194 -0
- mlebench/competitions/siim-covid19-detection/prepare.py +123 -0
- mlebench/competitions/siim-covid19-detection/prepare_val.py +164 -0
- mlebench/competitions/siim-isic-melanoma-classification/grade.py +11 -0
- mlebench/competitions/siim-isic-melanoma-classification/prepare.py +127 -0
- mlebench/competitions/siim-isic-melanoma-classification/prepare_val.py +158 -0
- mlebench/competitions/smartphone-decimeter-2022/grade.py +55 -0
- mlebench/competitions/smartphone-decimeter-2022/notebook.py +86 -0
- mlebench/competitions/smartphone-decimeter-2022/prepare.py +143 -0
- mlebench/competitions/smartphone-decimeter-2022/prepare_val.py +199 -0
- mlebench/competitions/spaceship-titanic/grade.py +11 -0
- mlebench/competitions/spaceship-titanic/prepare.py +23 -0
- mlebench/competitions/spaceship-titanic/prepare_val.py +61 -0
- mlebench/competitions/spooky-author-identification/classes.py +1 -0
- mlebench/competitions/spooky-author-identification/grade.py +38 -0
- mlebench/competitions/spooky-author-identification/prepare.py +40 -0
- mlebench/competitions/spooky-author-identification/prepare_val.py +78 -0
- mlebench/competitions/stanford-covid-vaccine/grade.py +65 -0
- mlebench/competitions/stanford-covid-vaccine/prepare.py +129 -0
- mlebench/competitions/stanford-covid-vaccine/prepare_val.py +199 -0
- mlebench/competitions/statoil-iceberg-classifier-challenge/grade.py +41 -0
- mlebench/competitions/statoil-iceberg-classifier-challenge/prepare.py +105 -0
- mlebench/competitions/statoil-iceberg-classifier-challenge/prepare_val.py +157 -0
- mlebench/competitions/tabular-playground-series-dec-2021/grade.py +11 -0
- mlebench/competitions/tabular-playground-series-dec-2021/prepare.py +39 -0
- mlebench/competitions/tabular-playground-series-dec-2021/prepare_val.py +99 -0
- mlebench/competitions/tabular-playground-series-may-2022/grade.py +9 -0
- mlebench/competitions/tabular-playground-series-may-2022/prepare.py +56 -0
- mlebench/competitions/tabular-playground-series-may-2022/prepare_val.py +116 -0
- mlebench/competitions/tensorflow-speech-recognition-challenge/grade.py +11 -0
- mlebench/competitions/tensorflow-speech-recognition-challenge/prepare.py +90 -0
- mlebench/competitions/tensorflow-speech-recognition-challenge/prepare_val.py +148 -0
- mlebench/competitions/tensorflow2-question-answering/grade.py +122 -0
- mlebench/competitions/tensorflow2-question-answering/prepare.py +122 -0
- mlebench/competitions/tensorflow2-question-answering/prepare_val.py +187 -0
- mlebench/competitions/text-normalization-challenge-english-language/grade.py +49 -0
- mlebench/competitions/text-normalization-challenge-english-language/prepare.py +115 -0
- mlebench/competitions/text-normalization-challenge-english-language/prepare_val.py +213 -0
- mlebench/competitions/text-normalization-challenge-russian-language/grade.py +49 -0
- mlebench/competitions/text-normalization-challenge-russian-language/prepare.py +113 -0
- mlebench/competitions/text-normalization-challenge-russian-language/prepare_val.py +165 -0
- mlebench/competitions/tgs-salt-identification-challenge/grade.py +144 -0
- mlebench/competitions/tgs-salt-identification-challenge/prepare.py +158 -0
- mlebench/competitions/tgs-salt-identification-challenge/prepare_val.py +166 -0
- mlebench/competitions/the-icml-2013-whale-challenge-right-whale-redux/grade.py +11 -0
- mlebench/competitions/the-icml-2013-whale-challenge-right-whale-redux/prepare.py +95 -0
- mlebench/competitions/the-icml-2013-whale-challenge-right-whale-redux/prepare_val.py +141 -0
- mlebench/competitions/tmdb-box-office-prediction/__init__.py +0 -0
- mlebench/competitions/tmdb-box-office-prediction/grade.py +55 -0
- mlebench/competitions/tmdb-box-office-prediction/prepare.py +35 -0
- mlebench/competitions/tweet-sentiment-extraction/grade.py +67 -0
- mlebench/competitions/tweet-sentiment-extraction/prepare.py +36 -0
- mlebench/competitions/tweet-sentiment-extraction/prepare_val.py +106 -0
- mlebench/competitions/us-patent-phrase-to-phrase-matching/grade.py +31 -0
- mlebench/competitions/us-patent-phrase-to-phrase-matching/prepare.py +33 -0
- mlebench/competitions/us-patent-phrase-to-phrase-matching/prepare_val.py +71 -0
- mlebench/competitions/utils.py +266 -0
- mlebench/competitions/uw-madison-gi-tract-image-segmentation/grade.py +158 -0
- mlebench/competitions/uw-madison-gi-tract-image-segmentation/prepare.py +139 -0
- mlebench/competitions/uw-madison-gi-tract-image-segmentation/prepare_val.py +193 -0
- mlebench/competitions/ventilator-pressure-prediction/__init__.py +0 -0
- mlebench/competitions/ventilator-pressure-prediction/grade.py +52 -0
- mlebench/competitions/ventilator-pressure-prediction/prepare.py +27 -0
- mlebench/competitions/ventilator-pressure-prediction/prepare_val.py +142 -0
- mlebench/competitions/ventilator_pressure_prediction/__init__.py +0 -0
- mlebench/competitions/ventilator_pressure_prediction/grade.py +52 -0
- mlebench/competitions/ventilator_pressure_prediction/prepare.py +27 -0
- mlebench/competitions/vesuvius-challenge-ink-detection/grade.py +97 -0
- mlebench/competitions/vesuvius-challenge-ink-detection/prepare.py +122 -0
- mlebench/competitions/vesuvius-challenge-ink-detection/prepare_val.py +170 -0
- mlebench/competitions/vinbigdata-chest-xray-abnormalities-detection/grade.py +220 -0
- mlebench/competitions/vinbigdata-chest-xray-abnormalities-detection/prepare.py +129 -0
- mlebench/competitions/vinbigdata-chest-xray-abnormalities-detection/prepare_val.py +204 -0
- mlebench/competitions/whale-categorization-playground/grade.py +41 -0
- mlebench/competitions/whale-categorization-playground/prepare.py +103 -0
- mlebench/competitions/whale-categorization-playground/prepare_val.py +196 -0
- mlebench/data.py +420 -0
- mlebench/grade.py +209 -0
- mlebench/grade_helpers.py +235 -0
- mlebench/metrics.py +75 -0
- mlebench/registry.py +332 -0
- mlebench/utils.py +346 -0
- {dslighting-1.7.1.dist-info → dslighting-1.7.8.dist-info}/WHEEL +0 -0
- {dslighting-1.7.1.dist-info → dslighting-1.7.8.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
|
|
3
|
+
import pandas as pd
|
|
4
|
+
from sklearn.model_selection import train_test_split
|
|
5
|
+
from tqdm import tqdm
|
|
6
|
+
|
|
7
|
+
from mlebench.utils import get_logger
|
|
8
|
+
|
|
9
|
+
logger = get_logger(__name__)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def extract_string(document_text: str, start_token_idx: int, end_token_idx: int) -> str:
|
|
13
|
+
document_tokens = document_text.split(" ")
|
|
14
|
+
extract_tokens = document_tokens[start_token_idx:end_token_idx]
|
|
15
|
+
return " ".join(extract_tokens)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def create_submission_files(
|
|
19
|
+
lightweight_test_df: pd.DataFrame, public_path: Path, private_path: Path, n_test_samples: int
|
|
20
|
+
):
|
|
21
|
+
"""
|
|
22
|
+
Creates the gold submission (private) and sample submission (public) files.
|
|
23
|
+
"""
|
|
24
|
+
# Create a gold submission with columns "example_id", "PredictionString"
|
|
25
|
+
gold_rows = []
|
|
26
|
+
for idx, sample in tqdm(
|
|
27
|
+
lightweight_test_df.iterrows(),
|
|
28
|
+
total=len(lightweight_test_df),
|
|
29
|
+
desc=f"Creating submission files for {public_path.name}",
|
|
30
|
+
):
|
|
31
|
+
sample = sample.to_dict()
|
|
32
|
+
assert len(sample["annotations"]) == 1
|
|
33
|
+
annotation = sample["annotations"][0]
|
|
34
|
+
|
|
35
|
+
# Create short answer
|
|
36
|
+
# Multiple answers are possible: yes_no_answer or one of short_answers
|
|
37
|
+
# We just take the first one
|
|
38
|
+
if annotation["yes_no_answer"] != "NONE":
|
|
39
|
+
answer = annotation["yes_no_answer"]
|
|
40
|
+
elif len(annotation["short_answers"]) > 0:
|
|
41
|
+
start_token = annotation["short_answers"][0]["start_token"]
|
|
42
|
+
end_token = annotation["short_answers"][0]["end_token"]
|
|
43
|
+
answer = f"{start_token}:{end_token}"
|
|
44
|
+
else:
|
|
45
|
+
answer = ""
|
|
46
|
+
|
|
47
|
+
gold_rows.append(
|
|
48
|
+
{"example_id": f"{sample['example_id']}_short", "PredictionString": answer}
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
# Create long answer
|
|
52
|
+
if annotation["long_answer"]["start_token"] != -1:
|
|
53
|
+
start_token = annotation["long_answer"]["start_token"]
|
|
54
|
+
end_token = annotation["long_answer"]["end_token"]
|
|
55
|
+
answer = f"{start_token}:{end_token}"
|
|
56
|
+
else:
|
|
57
|
+
answer = ""
|
|
58
|
+
|
|
59
|
+
gold_rows.append({"example_id": f"{sample['example_id']}_long", "PredictionString": answer})
|
|
60
|
+
|
|
61
|
+
gold_submission = pd.DataFrame(gold_rows)
|
|
62
|
+
gold_submission.to_csv(private_path / "gold_submission.csv", index=False)
|
|
63
|
+
|
|
64
|
+
# Sample submission
|
|
65
|
+
sample_submission = gold_submission.copy()
|
|
66
|
+
sample_submission["PredictionString"] = ""
|
|
67
|
+
sample_submission.to_csv(public_path / "sample_submission.csv", index=False)
|
|
68
|
+
|
|
69
|
+
assert len(gold_submission) == 2 * n_test_samples
|
|
70
|
+
assert len(sample_submission) == 2 * n_test_samples
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def prepare(raw: Path, public: Path, private: Path):
|
|
74
|
+
"""
|
|
75
|
+
Splits the data in raw into public and private datasets with appropriate test/train splits.
|
|
76
|
+
Then, it further splits the created train set into a smaller train set and a validation set.
|
|
77
|
+
"""
|
|
78
|
+
# Define and create paths for the new validation split
|
|
79
|
+
public_val = public.parent / "public_val"
|
|
80
|
+
private_val = private.parent / "private_val"
|
|
81
|
+
public_val.mkdir(exist_ok=True)
|
|
82
|
+
private_val.mkdir(exist_ok=True)
|
|
83
|
+
|
|
84
|
+
# --- STAGE 1: Create Original Train/Test Split ---
|
|
85
|
+
# This section creates the original `public` and `private` outputs.
|
|
86
|
+
|
|
87
|
+
train_file = "simplified-nq-train.jsonl"
|
|
88
|
+
public_train_file = public / "simplified-nq-train.jsonl"
|
|
89
|
+
|
|
90
|
+
logger.info("Counting lines in raw data file...")
|
|
91
|
+
with open(raw / train_file, "r") as f:
|
|
92
|
+
n_lines_raw = sum(1 for _ in f)
|
|
93
|
+
logger.info(f"Found {n_lines_raw} lines in raw data file.")
|
|
94
|
+
|
|
95
|
+
# Read data in chunks to avoid memory issues
|
|
96
|
+
train_ids, test_ids = [], []
|
|
97
|
+
lightweight_test = [] # We'll use this to create a gold submission later
|
|
98
|
+
with tqdm(total=n_lines_raw, desc="Splitting raw data -> train/test") as pbar:
|
|
99
|
+
for df in pd.read_json(raw / train_file, orient="records", lines=True, chunksize=1_000):
|
|
100
|
+
# Convert IDs to strings, Kaggle.com is inconsistent about this but strings make more sense
|
|
101
|
+
df["example_id"] = df["example_id"].astype(str)
|
|
102
|
+
new_train, new_test = train_test_split(df, test_size=0.1, random_state=0)
|
|
103
|
+
|
|
104
|
+
keys_to_keep = [
|
|
105
|
+
"example_id",
|
|
106
|
+
"question_text",
|
|
107
|
+
"document_text",
|
|
108
|
+
"long_answer_candidates",
|
|
109
|
+
]
|
|
110
|
+
new_test_without_labels = new_test.copy()[keys_to_keep]
|
|
111
|
+
|
|
112
|
+
# Append lines to new train and test
|
|
113
|
+
with open(public_train_file, "a") as f:
|
|
114
|
+
f.write(new_train.to_json(orient="records", lines=True))
|
|
115
|
+
with open(private / "test.jsonl", "a") as f:
|
|
116
|
+
f.write(new_test.to_json(orient="records", lines=True))
|
|
117
|
+
with open(public / "simplified-nq-test.jsonl", "a") as f:
|
|
118
|
+
f.write(new_test_without_labels.to_json(orient="records", lines=True))
|
|
119
|
+
|
|
120
|
+
train_ids.extend(new_train["example_id"].tolist())
|
|
121
|
+
test_ids.extend(new_test["example_id"].tolist())
|
|
122
|
+
lightweight_test.append(
|
|
123
|
+
new_test.copy()[["example_id", "question_text", "annotations"]]
|
|
124
|
+
) # For gold submission
|
|
125
|
+
pbar.update(len(df))
|
|
126
|
+
|
|
127
|
+
lightweight_test_df = pd.concat(lightweight_test, ignore_index=True)
|
|
128
|
+
|
|
129
|
+
assert len(train_ids) + len(test_ids) == n_lines_raw
|
|
130
|
+
assert len(lightweight_test_df) == len(test_ids)
|
|
131
|
+
|
|
132
|
+
# Create submission files for the original test set
|
|
133
|
+
create_submission_files(lightweight_test_df, public, private, len(test_ids))
|
|
134
|
+
logger.info("Finished creating original `public` and `private` directories.")
|
|
135
|
+
|
|
136
|
+
# --- STAGE 2: Create Validation Split from the new Train Set ---
|
|
137
|
+
# This section reads the train set created in Stage 1 and splits it again.
|
|
138
|
+
# The outputs are written to `public_val` and `private_val` directories.
|
|
139
|
+
|
|
140
|
+
logger.info("Counting lines in the created train file for validation split...")
|
|
141
|
+
with open(public_train_file, "r") as f:
|
|
142
|
+
n_lines_train = sum(1 for _ in f)
|
|
143
|
+
logger.info(f"Found {n_lines_train} lines in train file.")
|
|
144
|
+
|
|
145
|
+
train_val_ids, test_val_ids = [], []
|
|
146
|
+
lightweight_test_val = [] # For the validation set's gold submission
|
|
147
|
+
with tqdm(total=n_lines_train, desc="Splitting train data -> train_val/test_val") as pbar:
|
|
148
|
+
# Read the newly created train file in chunks for the second split
|
|
149
|
+
for df_train_chunk in pd.read_json(
|
|
150
|
+
public_train_file, orient="records", lines=True, chunksize=1_000
|
|
151
|
+
):
|
|
152
|
+
# Replicate the splitting logic on the training data
|
|
153
|
+
new_train_val, new_test_val = train_test_split(
|
|
154
|
+
df_train_chunk, test_size=0.1, random_state=0
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
keys_to_keep = [
|
|
158
|
+
"example_id",
|
|
159
|
+
"question_text",
|
|
160
|
+
"document_text",
|
|
161
|
+
"long_answer_candidates",
|
|
162
|
+
]
|
|
163
|
+
new_test_val_without_labels = new_test_val.copy()[keys_to_keep]
|
|
164
|
+
|
|
165
|
+
# Append lines to the new validation-split train and test files
|
|
166
|
+
with open(public_val / "simplified-nq-train.jsonl", "a") as f:
|
|
167
|
+
f.write(new_train_val.to_json(orient="records", lines=True))
|
|
168
|
+
with open(private_val / "test.jsonl", "a") as f:
|
|
169
|
+
f.write(new_test_val.to_json(orient="records", lines=True))
|
|
170
|
+
with open(public_val / "simplified-nq-test.jsonl", "a") as f:
|
|
171
|
+
f.write(new_test_val_without_labels.to_json(orient="records", lines=True))
|
|
172
|
+
|
|
173
|
+
train_val_ids.extend(new_train_val["example_id"].tolist())
|
|
174
|
+
test_val_ids.extend(new_test_val["example_id"].tolist())
|
|
175
|
+
lightweight_test_val.append(
|
|
176
|
+
new_test_val.copy()[["example_id", "question_text", "annotations"]]
|
|
177
|
+
)
|
|
178
|
+
pbar.update(len(df_train_chunk))
|
|
179
|
+
|
|
180
|
+
lightweight_test_val_df = pd.concat(lightweight_test_val, ignore_index=True)
|
|
181
|
+
|
|
182
|
+
assert len(train_val_ids) + len(test_val_ids) == n_lines_train
|
|
183
|
+
assert len(lightweight_test_val_df) == len(test_val_ids)
|
|
184
|
+
|
|
185
|
+
# Create submission files for the new validation set
|
|
186
|
+
create_submission_files(lightweight_test_val_df, public_val, private_val, len(test_val_ids))
|
|
187
|
+
logger.info("Finished creating new `public_val` and `private_val` directories.")
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
from sklearn.metrics import accuracy_score
|
|
3
|
+
|
|
4
|
+
from mlebench.grade_helpers import InvalidSubmissionError
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def grade(submission: pd.DataFrame, answers: pd.DataFrame) -> float:
|
|
8
|
+
accuracy_inputs = prepare_for_metric(
|
|
9
|
+
submission=submission,
|
|
10
|
+
answers=answers,
|
|
11
|
+
target_column="after",
|
|
12
|
+
id_column="id",
|
|
13
|
+
)
|
|
14
|
+
return accuracy_score(y_pred=accuracy_inputs["y_pred"], y_true=accuracy_inputs["y_true"])
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def prepare_for_metric(
|
|
18
|
+
submission: pd.DataFrame,
|
|
19
|
+
answers: pd.DataFrame,
|
|
20
|
+
target_column: str,
|
|
21
|
+
id_column: str,
|
|
22
|
+
) -> dict:
|
|
23
|
+
|
|
24
|
+
# Answers checks
|
|
25
|
+
assert target_column in answers.columns, f"Answers must have a `{target_column}` column"
|
|
26
|
+
assert id_column in answers.columns, f"Answers must have a `{id_column}` column"
|
|
27
|
+
|
|
28
|
+
# Submission checks
|
|
29
|
+
if len(submission) != len(answers):
|
|
30
|
+
raise InvalidSubmissionError("Submission must have the same length as the answers.")
|
|
31
|
+
if target_column not in submission.columns:
|
|
32
|
+
raise InvalidSubmissionError(f"Submission must have a `{target_column}` column")
|
|
33
|
+
if id_column not in submission.columns:
|
|
34
|
+
raise InvalidSubmissionError(f"Submission must have a `{id_column}` column")
|
|
35
|
+
|
|
36
|
+
# sort on id to ensure correct order
|
|
37
|
+
submission = submission.sort_values(id_column)
|
|
38
|
+
answers = answers.sort_values(id_column)
|
|
39
|
+
|
|
40
|
+
if (submission[id_column].values != answers[id_column].values).any():
|
|
41
|
+
raise InvalidSubmissionError(f"Submission and Answers `{id_column}`'s do not match")
|
|
42
|
+
|
|
43
|
+
submission[target_column] = submission[target_column].astype(str)
|
|
44
|
+
answers[target_column] = answers[target_column].astype(str)
|
|
45
|
+
|
|
46
|
+
y_pred = submission[target_column].to_numpy()
|
|
47
|
+
y_true = answers[target_column].to_numpy()
|
|
48
|
+
|
|
49
|
+
return {"y_true": y_true, "y_pred": y_pred}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import csv
|
|
2
|
+
import zipfile
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from sklearn.model_selection import train_test_split
|
|
6
|
+
|
|
7
|
+
from mlebench.utils import compress, extract, read_csv
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def prepare(raw: Path, public: Path, private: Path):
|
|
11
|
+
|
|
12
|
+
# Extract
|
|
13
|
+
extract(raw / "en_test_2.csv.zip", raw) # We only use the 2nd stage test set
|
|
14
|
+
extract(raw / "en_train.csv.zip", raw)
|
|
15
|
+
extract(raw / "en_sample_submission_2.csv.zip", raw)
|
|
16
|
+
|
|
17
|
+
# Create train and test splits from train set
|
|
18
|
+
old_train = read_csv(raw / "en_train.csv")
|
|
19
|
+
|
|
20
|
+
# We split so that we don't share any sentence_ids between train and test
|
|
21
|
+
# This gives us len(new_train) = 8924976 and len(answers) = 993465
|
|
22
|
+
# Original was len(old_train) = 9918441 and len(old_test) = 956046
|
|
23
|
+
unique_sentence_ids = old_train["sentence_id"].unique()
|
|
24
|
+
train_sentence_ids, test_sentence_ids = train_test_split(
|
|
25
|
+
unique_sentence_ids, test_size=0.1, random_state=0
|
|
26
|
+
)
|
|
27
|
+
new_train = old_train[old_train["sentence_id"].isin(train_sentence_ids)]
|
|
28
|
+
answers = old_train[old_train["sentence_id"].isin(test_sentence_ids)]
|
|
29
|
+
assert set(new_train["sentence_id"]).isdisjoint(
|
|
30
|
+
set(answers["sentence_id"])
|
|
31
|
+
), f"sentence_id is not disjoint between train and test sets"
|
|
32
|
+
|
|
33
|
+
# "sentence_id" counts need to be reset for new_train and answers
|
|
34
|
+
new_train_id_mapping = {
|
|
35
|
+
old_id: new_id for new_id, old_id in enumerate(new_train["sentence_id"].unique())
|
|
36
|
+
}
|
|
37
|
+
new_train.loc[:, "sentence_id"] = new_train["sentence_id"].map(new_train_id_mapping)
|
|
38
|
+
answers_id_mapping = {
|
|
39
|
+
old_id: new_id for new_id, old_id in enumerate(answers["sentence_id"].unique())
|
|
40
|
+
}
|
|
41
|
+
answers.loc[:, "sentence_id"] = answers["sentence_id"].map(answers_id_mapping)
|
|
42
|
+
|
|
43
|
+
# Create new test set
|
|
44
|
+
new_test = answers.drop(["after", "class"], axis=1).copy()
|
|
45
|
+
|
|
46
|
+
# Reformat answers to match sample submission format
|
|
47
|
+
answers = answers[["sentence_id", "token_id", "after"]].copy()
|
|
48
|
+
answers["id"] = answers["sentence_id"].astype(str) + "_" + answers["token_id"].astype(str)
|
|
49
|
+
answers = answers[["id", "after"]]
|
|
50
|
+
|
|
51
|
+
# Create sample submission
|
|
52
|
+
sample_submission = new_test[["sentence_id", "token_id", "before"]].copy()
|
|
53
|
+
sample_submission["id"] = (
|
|
54
|
+
sample_submission["sentence_id"].astype(str)
|
|
55
|
+
+ "_"
|
|
56
|
+
+ sample_submission["token_id"].astype(str)
|
|
57
|
+
)
|
|
58
|
+
sample_submission["after"] = sample_submission["before"]
|
|
59
|
+
sample_submission = sample_submission[["id", "after"]]
|
|
60
|
+
|
|
61
|
+
# Checks
|
|
62
|
+
assert new_train.columns.tolist() == [
|
|
63
|
+
"sentence_id",
|
|
64
|
+
"token_id",
|
|
65
|
+
"class",
|
|
66
|
+
"before",
|
|
67
|
+
"after",
|
|
68
|
+
], f"new_train.columns.tolist() == {new_train.columns.tolist()}"
|
|
69
|
+
assert new_test.columns.tolist() == [
|
|
70
|
+
"sentence_id",
|
|
71
|
+
"token_id",
|
|
72
|
+
"before",
|
|
73
|
+
], f"new_test.columns.tolist() == {new_test.columns.tolist()}"
|
|
74
|
+
assert sample_submission.columns.tolist() == [
|
|
75
|
+
"id",
|
|
76
|
+
"after",
|
|
77
|
+
], f"sample_submission.columns.tolist() == {sample_submission.columns.tolist()}"
|
|
78
|
+
assert answers.columns.tolist() == [
|
|
79
|
+
"id",
|
|
80
|
+
"after",
|
|
81
|
+
], f"answers.columns.tolist() == {answers.columns.tolist()}"
|
|
82
|
+
assert len(new_test) + len(new_train) == len(
|
|
83
|
+
old_train
|
|
84
|
+
), f"New train and test sets do not sum to old train set, got {len(new_test) + len(new_train)} and {len(old_train)}"
|
|
85
|
+
|
|
86
|
+
# Write CSVs
|
|
87
|
+
answers.to_csv(
|
|
88
|
+
private / "answers.csv", index=False, quotechar='"', quoting=csv.QUOTE_NONNUMERIC
|
|
89
|
+
)
|
|
90
|
+
sample_submission.to_csv(
|
|
91
|
+
private / "sample_submission.csv", index=False, quotechar='"', quoting=csv.QUOTE_NONNUMERIC
|
|
92
|
+
)
|
|
93
|
+
new_train.to_csv(
|
|
94
|
+
public / "en_train.csv", index=False, quotechar='"', quoting=csv.QUOTE_NONNUMERIC
|
|
95
|
+
)
|
|
96
|
+
new_test.to_csv(
|
|
97
|
+
public / "en_test_2.csv", index=False, quotechar='"', quoting=csv.QUOTE_NONNUMERIC
|
|
98
|
+
)
|
|
99
|
+
sample_submission.to_csv(
|
|
100
|
+
public / "en_sample_submission_2.csv",
|
|
101
|
+
index=False,
|
|
102
|
+
quotechar='"',
|
|
103
|
+
quoting=csv.QUOTE_NONNUMERIC,
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
# Zip up
|
|
107
|
+
with zipfile.ZipFile(public / "en_train.csv.zip", "w") as zipf:
|
|
108
|
+
zipf.write(public / "en_train.csv", arcname="en_train.csv")
|
|
109
|
+
with zipfile.ZipFile(public / "en_test_2.csv.zip", "w") as zipf:
|
|
110
|
+
zipf.write(public / "en_test_2.csv", arcname="en_test_2.csv")
|
|
111
|
+
with zipfile.ZipFile(public / "en_sample_submission_2.csv.zip", "w") as zipf:
|
|
112
|
+
zipf.write(public / "en_sample_submission_2.csv", arcname="en_sample_submission_2.csv")
|
|
113
|
+
(public / "en_train.csv").unlink()
|
|
114
|
+
(public / "en_test_2.csv").unlink()
|
|
115
|
+
(public / "en_sample_submission_2.csv").unlink()
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import csv
|
|
2
|
+
import zipfile
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Tuple
|
|
5
|
+
|
|
6
|
+
import pandas as pd
|
|
7
|
+
from sklearn.model_selection import train_test_split
|
|
8
|
+
|
|
9
|
+
from mlebench.utils import extract, read_csv
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _split_and_process(
|
|
13
|
+
input_df: pd.DataFrame, test_size: float, random_state: int
|
|
14
|
+
) -> Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame, pd.DataFrame]:
|
|
15
|
+
"""
|
|
16
|
+
Splits a DataFrame into train/test sets and processes them for the competition format.
|
|
17
|
+
|
|
18
|
+
This function encapsulates the core logic of splitting data based on unique sentence IDs,
|
|
19
|
+
re-indexing the new splits, and creating the corresponding test data, answers, and
|
|
20
|
+
sample submission files.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
input_df: The DataFrame to split.
|
|
24
|
+
test_size: The proportion of the dataset to allocate to the test split.
|
|
25
|
+
random_state: The seed used by the random number generator.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
A tuple containing:
|
|
29
|
+
- new_train_df: The processed training data.
|
|
30
|
+
- new_test_df: The processed, unlabeled test data.
|
|
31
|
+
- answers_df: The ground truth labels for the test data.
|
|
32
|
+
- submission_df: A sample submission file for the test data.
|
|
33
|
+
"""
|
|
34
|
+
# We split so that we don't share any sentence_ids between train and test
|
|
35
|
+
unique_sentence_ids = input_df["sentence_id"].unique()
|
|
36
|
+
train_sentence_ids, test_sentence_ids = train_test_split(
|
|
37
|
+
unique_sentence_ids, test_size=test_size, random_state=random_state
|
|
38
|
+
)
|
|
39
|
+
new_train_df = input_df[input_df["sentence_id"].isin(train_sentence_ids)].copy()
|
|
40
|
+
answers_df = input_df[input_df["sentence_id"].isin(test_sentence_ids)].copy()
|
|
41
|
+
assert set(new_train_df["sentence_id"]).isdisjoint(
|
|
42
|
+
set(answers_df["sentence_id"])
|
|
43
|
+
), f"sentence_id is not disjoint between train and test sets"
|
|
44
|
+
|
|
45
|
+
# "sentence_id" counts need to be reset for new_train_df and answers_df
|
|
46
|
+
new_train_id_mapping = {
|
|
47
|
+
old_id: new_id
|
|
48
|
+
for new_id, old_id in enumerate(new_train_df["sentence_id"].unique())
|
|
49
|
+
}
|
|
50
|
+
new_train_df.loc[:, "sentence_id"] = new_train_df["sentence_id"].map(
|
|
51
|
+
new_train_id_mapping
|
|
52
|
+
)
|
|
53
|
+
answers_id_mapping = {
|
|
54
|
+
old_id: new_id
|
|
55
|
+
for new_id, old_id in enumerate(answers_df["sentence_id"].unique())
|
|
56
|
+
}
|
|
57
|
+
answers_df.loc[:, "sentence_id"] = answers_df["sentence_id"].map(answers_id_mapping)
|
|
58
|
+
|
|
59
|
+
# Create new test set
|
|
60
|
+
new_test_df = answers_df.drop(["after", "class"], axis=1).copy()
|
|
61
|
+
|
|
62
|
+
# Reformat answers to match sample submission format
|
|
63
|
+
answers_formatted = answers_df[["sentence_id", "token_id", "after"]].copy()
|
|
64
|
+
answers_formatted["id"] = (
|
|
65
|
+
answers_formatted["sentence_id"].astype(str)
|
|
66
|
+
+ "_"
|
|
67
|
+
+ answers_formatted["token_id"].astype(str)
|
|
68
|
+
)
|
|
69
|
+
answers_formatted = answers_formatted[["id", "after"]]
|
|
70
|
+
|
|
71
|
+
# Create sample submission
|
|
72
|
+
submission_df = new_test_df[["sentence_id", "token_id", "before"]].copy()
|
|
73
|
+
submission_df["id"] = (
|
|
74
|
+
submission_df["sentence_id"].astype(str)
|
|
75
|
+
+ "_"
|
|
76
|
+
+ submission_df["token_id"].astype(str)
|
|
77
|
+
)
|
|
78
|
+
submission_df["after"] = submission_df["before"]
|
|
79
|
+
submission_df = submission_df[["id", "after"]]
|
|
80
|
+
|
|
81
|
+
# Checks
|
|
82
|
+
assert new_train_df.columns.tolist() == [
|
|
83
|
+
"sentence_id",
|
|
84
|
+
"token_id",
|
|
85
|
+
"class",
|
|
86
|
+
"before",
|
|
87
|
+
"after",
|
|
88
|
+
], f"new_train_df.columns.tolist() == {new_train_df.columns.tolist()}"
|
|
89
|
+
assert new_test_df.columns.tolist() == [
|
|
90
|
+
"sentence_id",
|
|
91
|
+
"token_id",
|
|
92
|
+
"before",
|
|
93
|
+
], f"new_test_df.columns.tolist() == {new_test_df.columns.tolist()}"
|
|
94
|
+
assert submission_df.columns.tolist() == [
|
|
95
|
+
"id",
|
|
96
|
+
"after",
|
|
97
|
+
], f"submission_df.columns.tolist() == {submission_df.columns.tolist()}"
|
|
98
|
+
assert answers_formatted.columns.tolist() == [
|
|
99
|
+
"id",
|
|
100
|
+
"after",
|
|
101
|
+
], f"answers_formatted.columns.tolist() == {answers_formatted.columns.tolist()}"
|
|
102
|
+
assert len(new_test_df) + len(new_train_df) == len(
|
|
103
|
+
input_df
|
|
104
|
+
), f"New train and test sets do not sum to old train set, got {len(new_test_df) + len(new_train_df)} and {len(input_df)}"
|
|
105
|
+
|
|
106
|
+
return new_train_df, new_test_df, answers_formatted, submission_df
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _write_and_zip_outputs(
|
|
110
|
+
public_dir: Path,
|
|
111
|
+
private_dir: Path,
|
|
112
|
+
train_df: pd.DataFrame,
|
|
113
|
+
test_df: pd.DataFrame,
|
|
114
|
+
answers_df: pd.DataFrame,
|
|
115
|
+
submission_df: pd.DataFrame,
|
|
116
|
+
):
|
|
117
|
+
"""
|
|
118
|
+
Writes the processed DataFrames to the specified directories and creates zip archives.
|
|
119
|
+
"""
|
|
120
|
+
public_dir.mkdir(exist_ok=True, parents=True)
|
|
121
|
+
private_dir.mkdir(exist_ok=True, parents=True)
|
|
122
|
+
|
|
123
|
+
# Define file paths
|
|
124
|
+
answers_path = private_dir / "answers.csv"
|
|
125
|
+
private_submission_path = private_dir / "sample_submission.csv"
|
|
126
|
+
public_train_path = public_dir / "en_train.csv"
|
|
127
|
+
public_test_path = public_dir / "en_test_2.csv"
|
|
128
|
+
public_submission_path = public_dir / "en_sample_submission_2.csv"
|
|
129
|
+
|
|
130
|
+
# Write CSVs
|
|
131
|
+
answers_df.to_csv(
|
|
132
|
+
answers_path, index=False, quotechar='"', quoting=csv.QUOTE_NONNUMERIC
|
|
133
|
+
)
|
|
134
|
+
submission_df.to_csv(
|
|
135
|
+
private_submission_path,
|
|
136
|
+
index=False,
|
|
137
|
+
quotechar='"',
|
|
138
|
+
quoting=csv.QUOTE_NONNUMERIC,
|
|
139
|
+
)
|
|
140
|
+
train_df.to_csv(
|
|
141
|
+
public_train_path, index=False, quotechar='"', quoting=csv.QUOTE_NONNUMERIC
|
|
142
|
+
)
|
|
143
|
+
test_df.to_csv(
|
|
144
|
+
public_test_path, index=False, quotechar='"', quoting=csv.QUOTE_NONNUMERIC
|
|
145
|
+
)
|
|
146
|
+
submission_df.to_csv(
|
|
147
|
+
public_submission_path,
|
|
148
|
+
index=False,
|
|
149
|
+
quotechar='"',
|
|
150
|
+
quoting=csv.QUOTE_NONNUMERIC,
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
# Zip up public files
|
|
154
|
+
with zipfile.ZipFile(public_dir / "en_train.csv.zip", "w", zipfile.ZIP_DEFLATED) as zipf:
|
|
155
|
+
zipf.write(public_train_path, arcname="en_train.csv")
|
|
156
|
+
with zipfile.ZipFile(public_dir / "en_test_2.csv.zip", "w", zipfile.ZIP_DEFLATED) as zipf:
|
|
157
|
+
zipf.write(public_test_path, arcname="en_test_2.csv")
|
|
158
|
+
with zipfile.ZipFile(
|
|
159
|
+
public_dir / "en_sample_submission_2.csv.zip", "w", zipfile.ZIP_DEFLATED
|
|
160
|
+
) as zipf:
|
|
161
|
+
zipf.write(public_submission_path, arcname="en_sample_submission_2.csv")
|
|
162
|
+
|
|
163
|
+
# Clean up intermediate CSVs
|
|
164
|
+
public_train_path.unlink()
|
|
165
|
+
public_test_path.unlink()
|
|
166
|
+
public_submission_path.unlink()
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def prepare(raw: Path, public: Path, private: Path):
|
|
170
|
+
|
|
171
|
+
# Extract
|
|
172
|
+
extract(raw / "en_test_2.csv.zip", raw) # We only use the 2nd stage test set
|
|
173
|
+
extract(raw / "en_train.csv.zip", raw)
|
|
174
|
+
extract(raw / "en_sample_submission_2.csv.zip", raw)
|
|
175
|
+
|
|
176
|
+
# Load original training data
|
|
177
|
+
old_train = read_csv(raw / "en_train.csv")
|
|
178
|
+
|
|
179
|
+
# --- Stage 1: Create the original train/test split ---
|
|
180
|
+
new_train, new_test, answers, sample_submission = _split_and_process(
|
|
181
|
+
input_df=old_train, test_size=0.1, random_state=0
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
# Write the original public and private directory files
|
|
185
|
+
_write_and_zip_outputs(
|
|
186
|
+
public_dir=public,
|
|
187
|
+
private_dir=private,
|
|
188
|
+
train_df=new_train,
|
|
189
|
+
test_df=new_test,
|
|
190
|
+
answers_df=answers,
|
|
191
|
+
submission_df=sample_submission,
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
# --- Stage 2: Create the new train_val/test_val split ---
|
|
195
|
+
# Define new output directories for the validation split
|
|
196
|
+
public_val = public.parent / "public_val"
|
|
197
|
+
private_val = private.parent / "private_val"
|
|
198
|
+
|
|
199
|
+
# Create the validation split from the 'new_train' data generated in Stage 1
|
|
200
|
+
# We use the same splitting logic and parameters to ensure consistency.
|
|
201
|
+
train_val, test_val, answers_val, submission_val = _split_and_process(
|
|
202
|
+
input_df=new_train, test_size=0.1, random_state=0
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
# Write the validation public and private directory files
|
|
206
|
+
_write_and_zip_outputs(
|
|
207
|
+
public_dir=public_val,
|
|
208
|
+
private_dir=private_val,
|
|
209
|
+
train_df=train_val,
|
|
210
|
+
test_df=test_val,
|
|
211
|
+
answers_df=answers_val,
|
|
212
|
+
submission_df=submission_val,
|
|
213
|
+
)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import pandas as pd
|
|
2
|
+
from sklearn.metrics import accuracy_score
|
|
3
|
+
|
|
4
|
+
from mlebench.grade_helpers import InvalidSubmissionError
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def grade(submission: pd.DataFrame, answers: pd.DataFrame) -> float:
|
|
8
|
+
accuracy_inputs = prepare_for_metric(
|
|
9
|
+
submission=submission,
|
|
10
|
+
answers=answers,
|
|
11
|
+
target_column="after",
|
|
12
|
+
id_column="id",
|
|
13
|
+
)
|
|
14
|
+
return accuracy_score(y_pred=accuracy_inputs["y_pred"], y_true=accuracy_inputs["y_true"])
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def prepare_for_metric(
|
|
18
|
+
submission: pd.DataFrame,
|
|
19
|
+
answers: pd.DataFrame,
|
|
20
|
+
target_column: str,
|
|
21
|
+
id_column: str,
|
|
22
|
+
) -> dict:
|
|
23
|
+
|
|
24
|
+
# Answers checks
|
|
25
|
+
assert target_column in answers.columns, f"Answers must have a `{target_column}` column"
|
|
26
|
+
assert id_column in answers.columns, f"Answers must have a `{id_column}` column"
|
|
27
|
+
|
|
28
|
+
# Submission checks
|
|
29
|
+
if len(submission) != len(answers):
|
|
30
|
+
raise InvalidSubmissionError("Submission must have the same length as the answers.")
|
|
31
|
+
if target_column not in submission.columns:
|
|
32
|
+
raise InvalidSubmissionError(f"Submission must have a `{target_column}` column")
|
|
33
|
+
if id_column not in submission.columns:
|
|
34
|
+
raise InvalidSubmissionError(f"Submission must have a `{id_column}` column")
|
|
35
|
+
|
|
36
|
+
# sort on id to ensure correct order
|
|
37
|
+
submission = submission.sort_values(id_column)
|
|
38
|
+
answers = answers.sort_values(id_column)
|
|
39
|
+
|
|
40
|
+
if (submission[id_column].values != answers[id_column].values).any():
|
|
41
|
+
raise InvalidSubmissionError(f"Submission and Answers `{id_column}`'s do not match")
|
|
42
|
+
|
|
43
|
+
submission[target_column] = submission[target_column].astype(str)
|
|
44
|
+
answers[target_column] = answers[target_column].astype(str)
|
|
45
|
+
|
|
46
|
+
y_pred = submission[target_column].to_numpy()
|
|
47
|
+
y_true = answers[target_column].to_numpy()
|
|
48
|
+
|
|
49
|
+
return {"y_true": y_true, "y_pred": y_pred}
|