├── .env.template ├── .github └── workflows │ ├── check_filesize.yml │ ├── quality.yml │ ├── run_evaluation_jobs.yml │ └── sync_with_spaces.yml ├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── app.py ├── evaluation.py ├── images ├── autotrain_job.png └── autotrain_projects.png ├── notebooks └── flush-prediction-repos.ipynb ├── pyproject.toml ├── requirements.txt ├── run_evaluation_jobs.py └── utils.py /.env.template: -------------------------------------------------------------------------------- 1 | AUTOTRAIN_USERNAME=autoevaluator # The bot or user that authors evaluation jobs 2 | HF_TOKEN=hf_xxx # An API token of the `autoevaluator` user 3 | AUTOTRAIN_BACKEND_API=https://api-staging.autotrain.huggingface.co # The AutoTrain backend to send jobs to. Use https://api.autotrain.huggingface.co for prod or http://localhost:8000 for local development 4 | DATASETS_PREVIEW_API=https://datasets-server.huggingface.co # The API to grab dataset information from -------------------------------------------------------------------------------- /.github/workflows/check_filesize.yml: -------------------------------------------------------------------------------- 1 | name: Check file size 2 | on: # or directly `on: [push]` to run the action on every push on any branch 3 | pull_request: 4 | branches: [main] 5 | 6 | # to run this workflow manually from the Actions tab 7 | workflow_dispatch: 8 | 9 | jobs: 10 | sync-to-hub: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Check large files 14 | uses: ActionsDesk/lfs-warning@v2.0 15 | with: 16 | filesizelimit: 10485760 # this is 10MB so we can sync to HF Spaces -------------------------------------------------------------------------------- /.github/workflows/quality.yml: -------------------------------------------------------------------------------- 1 | name: Code quality 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | branches: 9 | - main 10 | 11 | jobs: 12 | 13 | check_code_quality: 14 | name: Check code quality 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Checkout code 18 | uses: actions/checkout@v2 19 | - name: Setup Python environment 20 | uses: actions/setup-python@v2 21 | with: 22 | python-version: 3.9 23 | - name: Install dependencies 24 | run: | 25 | python -m pip install --upgrade pip 26 | python -m pip install black isort flake8 27 | - name: Code quality 28 | run: | 29 | make quality -------------------------------------------------------------------------------- /.github/workflows/run_evaluation_jobs.yml: -------------------------------------------------------------------------------- 1 | name: Start evaluation jobs 2 | 3 | on: 4 | schedule: 5 | - cron: '*/15 * * * *' # Start evaluations every 15th minute 6 | 7 | jobs: 8 | 9 | build: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Checkout code 14 | uses: actions/checkout@v2 15 | 16 | - name: Setup Python Environment 17 | uses: actions/setup-python@v2 18 | with: 19 | python-version: 3.8 20 | 21 | - name: Install requirements 22 | run: pip install -r requirements.txt 23 | 24 | - name: Execute scoring script 25 | env: 26 | HF_TOKEN: ${{ secrets.HF_TOKEN }} 27 | AUTOTRAIN_USERNAME: ${{ secrets.AUTOTRAIN_USERNAME }} 28 | AUTOTRAIN_BACKEND_API: ${{ secrets.AUTOTRAIN_BACKEND_API }} 29 | run: | 30 | HF_TOKEN=$HF_TOKEN AUTOTRAIN_USERNAME=$AUTOTRAIN_USERNAME AUTOTRAIN_BACKEND_API=$AUTOTRAIN_BACKEND_API python run_evaluation_jobs.py -------------------------------------------------------------------------------- /.github/workflows/sync_with_spaces.yml: -------------------------------------------------------------------------------- 1 | name: Sync to Hugging Face hub 2 | on: 3 | push: 4 | branches: [main] 5 | 6 | # to run this workflow manually from the Actions tab 7 | workflow_dispatch: 8 | 9 | jobs: 10 | sync-to-hub: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | with: 15 | fetch-depth: 0 16 | - name: Push to hub 17 | env: 18 | HF_TOKEN: ${{ secrets.HF_TOKEN }} 19 | run: | 20 | git push https://lewtun:$HF_TOKEN@huggingface.co/spaces/autoevaluate/model-evaluator main 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | 131 | scratch/ 132 | 133 | # Evaluation job logs 134 | evaluation-job-logs/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | style: 2 | python -m black --line-length 119 --target-version py39 . 3 | python -m isort . 4 | 5 | quality: 6 | python -m black --check --line-length 119 --target-version py39 . 7 | python -m isort --check-only . 8 | python -m flake8 --max-line-length 119 --exclude app.py -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Model Evaluator 3 | emoji: 📊 4 | colorFrom: red 5 | colorTo: red 6 | sdk: streamlit 7 | sdk_version: 1.10.0 8 | app_file: app.py 9 | --- 10 | 11 | # Model Evaluator 12 | 13 | > Submit evaluation jobs to AutoTrain from the Hugging Face Hub 14 | 15 | **⚠️ This project has been archived. If you want to evaluate LLMs, checkout [this collection](https://huggingface.co/collections/clefourrier/llm-leaderboards-and-benchmarks-✨-64f99d2e11e92ca5568a7cce) of leaderboards.** 16 | 17 | ## Supported tasks 18 | 19 | The table below shows which tasks are currently supported for evaluation in the AutoTrain backend: 20 | 21 | | Task | Supported | 22 | |:-----------------------------------|:---------:| 23 | | `binary_classification` | ✅ | 24 | | `multi_class_classification` | ✅ | 25 | | `multi_label_classification` | ❌ | 26 | | `entity_extraction` | ✅ | 27 | | `extractive_question_answering` | ✅ | 28 | | `translation` | ✅ | 29 | | `summarization` | ✅ | 30 | | `image_binary_classification` | ✅ | 31 | | `image_multi_class_classification` | ✅ | 32 | | `text_zero_shot_evaluation` | ✅ | 33 | 34 | 35 | ## Installation 36 | 37 | To run the application locally, first clone this repository and install the dependencies as follows: 38 | 39 | ``` 40 | pip install -r requirements.txt 41 | ``` 42 | 43 | Next, copy the example file of environment variables: 44 | 45 | ``` 46 | cp .env.template .env 47 | ``` 48 | 49 | and set the `HF_TOKEN` variable with a valid API token from the [`autoevaluator`](https://huggingface.co/autoevaluator) bot user. Finally, spin up the application by running: 50 | 51 | ``` 52 | streamlit run app.py 53 | ``` 54 | 55 | ## Usage 56 | 57 | Evaluation on the Hub involves two main steps: 58 | 59 | 1. Submitting an evaluation job via the UI. This creates an AutoTrain project with `N` models for evaluation. At this stage, the dataset is also processed and prepared for evaluation. 60 | 2. Triggering the evaluation itself once the dataset is processed. 61 | 62 | From the user perspective, only step (1) is needed since step (2) is handled by a cron job on GitHub Actions that executes the `run_evaluation_jobs.py` script every 15 minutes. 63 | 64 | See below for details on manually triggering evaluation jobs. 65 | 66 | ### Triggering an evaluation 67 | 68 | To evaluate the models in an AutoTrain project, run: 69 | 70 | ``` 71 | python run_evaluation_jobs.py 72 | ``` 73 | 74 | This will download the [`autoevaluate/evaluation-job-logs`](https://huggingface.co/datasets/autoevaluate/evaluation-job-logs) dataset from the Hub and check which evaluation projects are ready for evaluation (i.e. those whose dataset has been processed). 75 | 76 | ## AutoTrain configuration details 77 | 78 | Models are evaluated by the [`autoevaluator`](https://huggingface.co/autoevaluator) bot user in AutoTrain, with the payload sent to the `AUTOTRAIN_BACKEND_API` environment variable. Evaluation projects are created and run on either the `prod` or `staging` environments. You can view the status of projects in the AutoTrain UI by navigating to one of the links below (ask internally for access to the staging UI): 79 | 80 | | AutoTrain environment | AutoTrain UI URL | `AUTOTRAIN_BACKEND_API` | 81 | |:---------------------:|:--------------------------------------------------------------------------------------------------------------:|:--------------------------------------------:| 82 | | `prod` | [`https://ui.autotrain.huggingface.co/projects`](https://ui.autotrain.huggingface.co/projects) | https://api.autotrain.huggingface.co | 83 | | `staging` | [`https://ui-staging.autotrain.huggingface.co/projects`](https://ui-staging.autotrain.huggingface.co/projects) | https://api-staging.autotrain.huggingface.co | 84 | 85 | 86 | The current configuration for evaluation jobs running on [Spaces](https://huggingface.co/spaces/autoevaluate/model-evaluator) is: 87 | 88 | ``` 89 | AUTOTRAIN_BACKEND_API=https://api.autotrain.huggingface.co 90 | ``` 91 | 92 | To evaluate models with a _local_ instance of AutoTrain, change the environment to: 93 | 94 | ``` 95 | AUTOTRAIN_BACKEND_API=http://localhost:8000 96 | ``` 97 | 98 | ### Migrating from staging to production (and vice versa) 99 | 100 | In general, evaluation jobs should run in AutoTrain's `prod` environment, which is defined by the following environment variable: 101 | 102 | ``` 103 | AUTOTRAIN_BACKEND_API=https://api.autotrain.huggingface.co 104 | ``` 105 | 106 | However, there are times when it is necessary to run evaluation jobs in AutoTrain's `staging` environment (e.g. because a new evaluation pipeline is being deployed). In these cases the corresponding environement variable is: 107 | 108 | ``` 109 | AUTOTRAIN_BACKEND_API=https://api-staging.autotrain.huggingface.co 110 | ``` 111 | 112 | To migrate between these two environments, update the `AUTOTRAIN_BACKEND_API` in two places: 113 | 114 | * In the [repo secrets](https://huggingface.co/spaces/autoevaluate/model-evaluator/settings) associated with the `model-evaluator` Space. This will ensure evaluation projects are created in the desired environment. 115 | * In the [GitHub Actions secrets](https://github.com/huggingface/model-evaluator/settings/secrets/actions) associated with this repo. This will ensure that the correct evaluation jobs are approved and launched via the `run_evaluation_jobs.py` script. 116 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | import os 2 | import time 3 | from pathlib import Path 4 | 5 | import pandas as pd 6 | import streamlit as st 7 | import yaml 8 | from datasets import get_dataset_config_names 9 | from dotenv import load_dotenv 10 | from huggingface_hub import list_datasets 11 | 12 | from evaluation import filter_evaluated_models 13 | from utils import ( 14 | AUTOTRAIN_TASK_TO_HUB_TASK, 15 | commit_evaluation_log, 16 | create_autotrain_project_name, 17 | format_col_mapping, 18 | get_compatible_models, 19 | get_config_metadata, 20 | get_dataset_card_url, 21 | get_key, 22 | get_metadata, 23 | http_get, 24 | http_post, 25 | ) 26 | 27 | if Path(".env").is_file(): 28 | load_dotenv(".env") 29 | 30 | HF_TOKEN = os.getenv("HF_TOKEN") 31 | AUTOTRAIN_USERNAME = os.getenv("AUTOTRAIN_USERNAME") 32 | AUTOTRAIN_BACKEND_API = os.getenv("AUTOTRAIN_BACKEND_API") 33 | DATASETS_PREVIEW_API = os.getenv("DATASETS_PREVIEW_API") 34 | 35 | # Put image tasks on top 36 | TASK_TO_ID = { 37 | "image_binary_classification": 17, 38 | "image_multi_class_classification": 18, 39 | "binary_classification": 1, 40 | "multi_class_classification": 2, 41 | "natural_language_inference": 22, 42 | "entity_extraction": 4, 43 | "extractive_question_answering": 5, 44 | "translation": 6, 45 | "summarization": 8, 46 | "text_zero_shot_classification": 23, 47 | } 48 | 49 | TASK_TO_DEFAULT_METRICS = { 50 | "binary_classification": ["f1", "precision", "recall", "auc", "accuracy"], 51 | "multi_class_classification": [ 52 | "f1", 53 | "precision", 54 | "recall", 55 | "accuracy", 56 | ], 57 | "natural_language_inference": ["f1", "precision", "recall", "auc", "accuracy"], 58 | "entity_extraction": ["precision", "recall", "f1", "accuracy"], 59 | "extractive_question_answering": ["f1", "exact_match"], 60 | "translation": ["sacrebleu"], 61 | "summarization": ["rouge1", "rouge2", "rougeL", "rougeLsum"], 62 | "image_binary_classification": ["f1", "precision", "recall", "auc", "accuracy"], 63 | "image_multi_class_classification": [ 64 | "f1", 65 | "precision", 66 | "recall", 67 | "accuracy", 68 | ], 69 | "text_zero_shot_classification": ["accuracy", "loss"], 70 | } 71 | 72 | AUTOTRAIN_TASK_TO_LANG = { 73 | "translation": "en2de", 74 | "image_binary_classification": "unk", 75 | "image_multi_class_classification": "unk", 76 | } 77 | 78 | AUTOTRAIN_MACHINE = {"text_zero_shot_classification": "r5.16x"} 79 | 80 | 81 | SUPPORTED_TASKS = list(TASK_TO_ID.keys()) 82 | 83 | # Extracted from utils.get_supported_metrics 84 | # Hardcoded for now due to speed / caching constraints 85 | SUPPORTED_METRICS = [ 86 | "accuracy", 87 | "bertscore", 88 | "bleu", 89 | "cer", 90 | "chrf", 91 | "code_eval", 92 | "comet", 93 | "competition_math", 94 | "coval", 95 | "cuad", 96 | "exact_match", 97 | "f1", 98 | "frugalscore", 99 | "google_bleu", 100 | "mae", 101 | "mahalanobis", 102 | "matthews_correlation", 103 | "mean_iou", 104 | "meteor", 105 | "mse", 106 | "pearsonr", 107 | "perplexity", 108 | "precision", 109 | "recall", 110 | "roc_auc", 111 | "rouge", 112 | "sacrebleu", 113 | "sari", 114 | "seqeval", 115 | "spearmanr", 116 | "squad", 117 | "squad_v2", 118 | "ter", 119 | "trec_eval", 120 | "wer", 121 | "wiki_split", 122 | "xnli", 123 | "angelina-wang/directional_bias_amplification", 124 | "jordyvl/ece", 125 | "lvwerra/ai4code", 126 | "lvwerra/amex", 127 | ] 128 | 129 | 130 | ####### 131 | # APP # 132 | ####### 133 | st.title("Evaluation on the Hub") 134 | st.warning( 135 | "**⚠️ This project has been archived. If you want to evaluate LLMs, checkout [this collection](https://huggingface.co/collections/clefourrier/llm-leaderboards-and-benchmarks-✨-64f99d2e11e92ca5568a7cce) of leaderboards.**" 136 | ) 137 | st.markdown( 138 | """ 139 | Welcome to Hugging Face's automatic model evaluator 👋! 140 | 141 | This application allows you to evaluate 🤗 Transformers 142 | [models](https://huggingface.co/models?library=transformers&sort=downloads) 143 | across a wide variety of [datasets](https://huggingface.co/datasets) on the 144 | Hub. Please select the dataset and configuration below. The results of your 145 | evaluation will be displayed on the [public 146 | leaderboards](https://huggingface.co/spaces/autoevaluate/leaderboards). For 147 | more details, check out out our [blog 148 | post](https://huggingface.co/blog/eval-on-the-hub). 149 | """ 150 | ) 151 | 152 | # all_datasets = [d.id for d in list_datasets()] 153 | # query_params = st.experimental_get_query_params() 154 | # if "first_query_params" not in st.session_state: 155 | # st.session_state.first_query_params = query_params 156 | # first_query_params = st.session_state.first_query_params 157 | # default_dataset = all_datasets[0] 158 | # if "dataset" in first_query_params: 159 | # if len(first_query_params["dataset"]) > 0 and first_query_params["dataset"][0] in all_datasets: 160 | # default_dataset = first_query_params["dataset"][0] 161 | 162 | # selected_dataset = st.selectbox( 163 | # "Select a dataset", 164 | # all_datasets, 165 | # index=all_datasets.index(default_dataset), 166 | # help="""Datasets with metadata can be evaluated with 1-click. Configure an evaluation job to add \ 167 | # new metadata to a dataset card.""", 168 | # ) 169 | # st.experimental_set_query_params(**{"dataset": [selected_dataset]}) 170 | 171 | # # Check if selected dataset can be streamed 172 | # is_valid_dataset = http_get( 173 | # path="/is-valid", 174 | # domain=DATASETS_PREVIEW_API, 175 | # params={"dataset": selected_dataset}, 176 | # ).json() 177 | # if is_valid_dataset["viewer"] is False and is_valid_dataset["preview"] is False: 178 | # st.error( 179 | # """The dataset you selected is not currently supported. Open a \ 180 | # [discussion](https://huggingface.co/spaces/autoevaluate/model-evaluator/discussions) for support.""" 181 | # ) 182 | 183 | # metadata = get_metadata(selected_dataset, token=HF_TOKEN) 184 | # print(f"INFO -- Dataset metadata: {metadata}") 185 | # if metadata is None: 186 | # st.warning("No evaluation metadata found. Please configure the evaluation job below.") 187 | 188 | # with st.expander("Advanced configuration"): 189 | # # Select task 190 | # selected_task = st.selectbox( 191 | # "Select a task", 192 | # SUPPORTED_TASKS, 193 | # index=SUPPORTED_TASKS.index(metadata[0]["task_id"]) if metadata is not None else 0, 194 | # help="""Don't see your favourite task here? Open a \ 195 | # [discussion](https://huggingface.co/spaces/autoevaluate/model-evaluator/discussions) to request it!""", 196 | # ) 197 | # # Select config 198 | # configs = get_dataset_config_names(selected_dataset) 199 | # selected_config = st.selectbox( 200 | # "Select a config", 201 | # configs, 202 | # help="""Some datasets contain several sub-datasets, known as _configurations_. \ 203 | # Select one to evaluate your models on. \ 204 | # See the [docs](https://huggingface.co/docs/datasets/master/en/load_hub#configurations) for more details. 205 | # """, 206 | # ) 207 | # # Some datasets have multiple metadata (one per config), so we grab the one associated with the selected config 208 | # config_metadata = get_config_metadata(selected_config, metadata) 209 | # print(f"INFO -- Config metadata: {config_metadata}") 210 | 211 | # # Select splits 212 | # splits_resp = http_get( 213 | # path="/splits", 214 | # domain=DATASETS_PREVIEW_API, 215 | # params={"dataset": selected_dataset}, 216 | # ) 217 | # if splits_resp.status_code == 200: 218 | # split_names = [] 219 | # all_splits = splits_resp.json() 220 | # for split in all_splits["splits"]: 221 | # if split["config"] == selected_config: 222 | # split_names.append(split["split"]) 223 | 224 | # if config_metadata is not None: 225 | # eval_split = config_metadata["splits"].get("eval_split", None) 226 | # else: 227 | # eval_split = None 228 | # selected_split = st.selectbox( 229 | # "Select a split", 230 | # split_names, 231 | # index=split_names.index(eval_split) if eval_split is not None else 0, 232 | # help="Be wary when evaluating models on the `train` split.", 233 | # ) 234 | 235 | # # Select columns 236 | # rows_resp = http_get( 237 | # path="/first-rows", 238 | # domain=DATASETS_PREVIEW_API, 239 | # params={ 240 | # "dataset": selected_dataset, 241 | # "config": selected_config, 242 | # "split": selected_split, 243 | # }, 244 | # ).json() 245 | # col_names = list(pd.json_normalize(rows_resp["rows"][0]["row"]).columns) 246 | 247 | # st.markdown("**Map your dataset columns**") 248 | # st.markdown( 249 | # """The model evaluator uses a standardised set of column names for the input examples and labels. \ 250 | # Please define the mapping between your dataset columns (right) and the standardised column names (left).""" 251 | # ) 252 | # col1, col2 = st.columns(2) 253 | 254 | # # TODO: find a better way to layout these items 255 | # # TODO: need graceful way of handling dataset <--> task mismatch for datasets with metadata 256 | # col_mapping = {} 257 | # if selected_task in ["binary_classification", "multi_class_classification"]: 258 | # with col1: 259 | # st.markdown("`text` column") 260 | # st.text("") 261 | # st.text("") 262 | # st.text("") 263 | # st.text("") 264 | # st.markdown("`target` column") 265 | # with col2: 266 | # text_col = st.selectbox( 267 | # "This column should contain the text to be classified", 268 | # col_names, 269 | # index=col_names.index(get_key(config_metadata["col_mapping"], "text")) 270 | # if config_metadata is not None 271 | # else 0, 272 | # ) 273 | # target_col = st.selectbox( 274 | # "This column should contain the labels associated with the text", 275 | # col_names, 276 | # index=col_names.index(get_key(config_metadata["col_mapping"], "target")) 277 | # if config_metadata is not None 278 | # else 0, 279 | # ) 280 | # col_mapping[text_col] = "text" 281 | # col_mapping[target_col] = "target" 282 | 283 | # elif selected_task == "text_zero_shot_classification": 284 | # with col1: 285 | # st.markdown("`text` column") 286 | # st.text("") 287 | # st.text("") 288 | # st.text("") 289 | # st.text("") 290 | # st.markdown("`classes` column") 291 | # st.text("") 292 | # st.text("") 293 | # st.text("") 294 | # st.text("") 295 | # st.markdown("`target` column") 296 | # with col2: 297 | # text_col = st.selectbox( 298 | # "This column should contain the text to be classified", 299 | # col_names, 300 | # index=col_names.index(get_key(config_metadata["col_mapping"], "text")) 301 | # if config_metadata is not None 302 | # else 0, 303 | # ) 304 | # classes_col = st.selectbox( 305 | # "This column should contain the classes associated with the text", 306 | # col_names, 307 | # index=col_names.index(get_key(config_metadata["col_mapping"], "classes")) 308 | # if config_metadata is not None 309 | # else 0, 310 | # ) 311 | # target_col = st.selectbox( 312 | # "This column should contain the index of the correct class", 313 | # col_names, 314 | # index=col_names.index(get_key(config_metadata["col_mapping"], "target")) 315 | # if config_metadata is not None 316 | # else 0, 317 | # ) 318 | # col_mapping[text_col] = "text" 319 | # col_mapping[classes_col] = "classes" 320 | # col_mapping[target_col] = "target" 321 | 322 | # if selected_task in ["natural_language_inference"]: 323 | # config_metadata = get_config_metadata(selected_config, metadata) 324 | # with col1: 325 | # st.markdown("`text1` column") 326 | # st.text("") 327 | # st.text("") 328 | # st.text("") 329 | # st.text("") 330 | # st.text("") 331 | # st.markdown("`text2` column") 332 | # st.text("") 333 | # st.text("") 334 | # st.text("") 335 | # st.text("") 336 | # st.text("") 337 | # st.markdown("`target` column") 338 | # with col2: 339 | # text1_col = st.selectbox( 340 | # "This column should contain the first text passage to be classified", 341 | # col_names, 342 | # index=col_names.index(get_key(config_metadata["col_mapping"], "text1")) 343 | # if config_metadata is not None 344 | # else 0, 345 | # ) 346 | # text2_col = st.selectbox( 347 | # "This column should contain the second text passage to be classified", 348 | # col_names, 349 | # index=col_names.index(get_key(config_metadata["col_mapping"], "text2")) 350 | # if config_metadata is not None 351 | # else 0, 352 | # ) 353 | # target_col = st.selectbox( 354 | # "This column should contain the labels associated with the text", 355 | # col_names, 356 | # index=col_names.index(get_key(config_metadata["col_mapping"], "target")) 357 | # if config_metadata is not None 358 | # else 0, 359 | # ) 360 | # col_mapping[text1_col] = "text1" 361 | # col_mapping[text2_col] = "text2" 362 | # col_mapping[target_col] = "target" 363 | 364 | # elif selected_task == "entity_extraction": 365 | # with col1: 366 | # st.markdown("`tokens` column") 367 | # st.text("") 368 | # st.text("") 369 | # st.text("") 370 | # st.text("") 371 | # st.markdown("`tags` column") 372 | # with col2: 373 | # tokens_col = st.selectbox( 374 | # "This column should contain the array of tokens to be classified", 375 | # col_names, 376 | # index=col_names.index(get_key(config_metadata["col_mapping"], "tokens")) 377 | # if config_metadata is not None 378 | # else 0, 379 | # ) 380 | # tags_col = st.selectbox( 381 | # "This column should contain the labels associated with each part of the text", 382 | # col_names, 383 | # index=col_names.index(get_key(config_metadata["col_mapping"], "tags")) 384 | # if config_metadata is not None 385 | # else 0, 386 | # ) 387 | # col_mapping[tokens_col] = "tokens" 388 | # col_mapping[tags_col] = "tags" 389 | 390 | # elif selected_task == "translation": 391 | # with col1: 392 | # st.markdown("`source` column") 393 | # st.text("") 394 | # st.text("") 395 | # st.text("") 396 | # st.text("") 397 | # st.markdown("`target` column") 398 | # with col2: 399 | # text_col = st.selectbox( 400 | # "This column should contain the text to be translated", 401 | # col_names, 402 | # index=col_names.index(get_key(config_metadata["col_mapping"], "source")) 403 | # if config_metadata is not None 404 | # else 0, 405 | # ) 406 | # target_col = st.selectbox( 407 | # "This column should contain the target translation", 408 | # col_names, 409 | # index=col_names.index(get_key(config_metadata["col_mapping"], "target")) 410 | # if config_metadata is not None 411 | # else 0, 412 | # ) 413 | # col_mapping[text_col] = "source" 414 | # col_mapping[target_col] = "target" 415 | 416 | # elif selected_task == "summarization": 417 | # with col1: 418 | # st.markdown("`text` column") 419 | # st.text("") 420 | # st.text("") 421 | # st.text("") 422 | # st.text("") 423 | # st.markdown("`target` column") 424 | # with col2: 425 | # text_col = st.selectbox( 426 | # "This column should contain the text to be summarized", 427 | # col_names, 428 | # index=col_names.index(get_key(config_metadata["col_mapping"], "text")) 429 | # if config_metadata is not None 430 | # else 0, 431 | # ) 432 | # target_col = st.selectbox( 433 | # "This column should contain the target summary", 434 | # col_names, 435 | # index=col_names.index(get_key(config_metadata["col_mapping"], "target")) 436 | # if config_metadata is not None 437 | # else 0, 438 | # ) 439 | # col_mapping[text_col] = "text" 440 | # col_mapping[target_col] = "target" 441 | 442 | # elif selected_task == "extractive_question_answering": 443 | # if config_metadata is not None: 444 | # col_mapping = config_metadata["col_mapping"] 445 | # # Hub YAML parser converts periods to hyphens, so we remap them here 446 | # col_mapping = format_col_mapping(col_mapping) 447 | # with col1: 448 | # st.markdown("`context` column") 449 | # st.text("") 450 | # st.text("") 451 | # st.text("") 452 | # st.text("") 453 | # st.markdown("`question` column") 454 | # st.text("") 455 | # st.text("") 456 | # st.text("") 457 | # st.text("") 458 | # st.markdown("`answers.text` column") 459 | # st.text("") 460 | # st.text("") 461 | # st.text("") 462 | # st.text("") 463 | # st.markdown("`answers.answer_start` column") 464 | # with col2: 465 | # context_col = st.selectbox( 466 | # "This column should contain the question's context", 467 | # col_names, 468 | # index=col_names.index(get_key(col_mapping, "context")) if config_metadata is not None else 0, 469 | # ) 470 | # question_col = st.selectbox( 471 | # "This column should contain the question to be answered, given the context", 472 | # col_names, 473 | # index=col_names.index(get_key(col_mapping, "question")) if config_metadata is not None else 0, 474 | # ) 475 | # answers_text_col = st.selectbox( 476 | # "This column should contain example answers to the question, extracted from the context", 477 | # col_names, 478 | # index=col_names.index(get_key(col_mapping, "answers.text")) if config_metadata is not None else 0, 479 | # ) 480 | # answers_start_col = st.selectbox( 481 | # "This column should contain the indices in the context of the first character of each `answers.text`", 482 | # col_names, 483 | # index=col_names.index(get_key(col_mapping, "answers.answer_start")) 484 | # if config_metadata is not None 485 | # else 0, 486 | # ) 487 | # col_mapping[context_col] = "context" 488 | # col_mapping[question_col] = "question" 489 | # col_mapping[answers_text_col] = "answers.text" 490 | # col_mapping[answers_start_col] = "answers.answer_start" 491 | # elif selected_task in ["image_binary_classification", "image_multi_class_classification"]: 492 | # with col1: 493 | # st.markdown("`image` column") 494 | # st.text("") 495 | # st.text("") 496 | # st.text("") 497 | # st.text("") 498 | # st.markdown("`target` column") 499 | # with col2: 500 | # image_col = st.selectbox( 501 | # "This column should contain the images to be classified", 502 | # col_names, 503 | # index=col_names.index(get_key(config_metadata["col_mapping"], "image")) 504 | # if config_metadata is not None 505 | # else 0, 506 | # ) 507 | # target_col = st.selectbox( 508 | # "This column should contain the labels associated with the images", 509 | # col_names, 510 | # index=col_names.index(get_key(config_metadata["col_mapping"], "target")) 511 | # if config_metadata is not None 512 | # else 0, 513 | # ) 514 | # col_mapping[image_col] = "image" 515 | # col_mapping[target_col] = "target" 516 | 517 | # # Select metrics 518 | # st.markdown("**Select metrics**") 519 | # st.markdown("The following metrics will be computed") 520 | # html_string = " ".join( 521 | # [ 522 | # '