Download/extract/cache a metric module. Metrics codes are cached inside the the dynamic modules cache to allow easy import (avoid ugly sys.path tweaks). Args: path (str): Path or name of the metric script. - if ``path`` is a local metric script or a directory con
(
path: str,
module_type: Optional[str] = None,
revision: Optional[Union[str, Version]] = None,
download_config: Optional[DownloadConfig] = None,
download_mode: Optional[DownloadMode] = None,
force_local_path: Optional[str] = None,
dynamic_modules_path: Optional[str] = None,
**download_kwargs,
)
| 557 | |
| 558 | |
| 559 | def evaluation_module_factory( |
| 560 | path: str, |
| 561 | module_type: Optional[str] = None, |
| 562 | revision: Optional[Union[str, Version]] = None, |
| 563 | download_config: Optional[DownloadConfig] = None, |
| 564 | download_mode: Optional[DownloadMode] = None, |
| 565 | force_local_path: Optional[str] = None, |
| 566 | dynamic_modules_path: Optional[str] = None, |
| 567 | **download_kwargs, |
| 568 | ) -> ImportableModule: |
| 569 | """ |
| 570 | Download/extract/cache a metric module. |
| 571 | |
| 572 | Metrics codes are cached inside the the dynamic modules cache to allow easy import (avoid ugly sys.path tweaks). |
| 573 | |
| 574 | Args: |
| 575 | |
| 576 | path (str): Path or name of the metric script. |
| 577 | |
| 578 | - if ``path`` is a local metric script or a directory containing a local metric script (if the script has the same name as the directory): |
| 579 | -> load the module from the metric script |
| 580 | e.g. ``'./metrics/accuracy'`` or ``'./metrics/accuracy/accuracy.py'``. |
| 581 | - if ``path`` is a metric on the Hugging Face Hub (ex: `glue`, `squad`) |
| 582 | -> load the module from the metric script in the github repository at huggingface/datasets |
| 583 | e.g. ``'accuracy'`` or ``'rouge'``. |
| 584 | |
| 585 | revision (Optional ``Union[str, datasets.Version]``): |
| 586 | If specified, the module will be loaded from the datasets repository at this version. |
| 587 | By default: |
| 588 | - it is set to the local version of the lib. |
| 589 | - it will also try to load it from the master branch if it's not available at the local version of the lib. |
| 590 | Specifying a version that is different from your local version of the lib might cause compatibility issues. |
| 591 | download_config (:class:`DownloadConfig`, optional): Specific download configuration parameters. |
| 592 | download_mode (:class:`DownloadMode`, default ``REUSE_DATASET_IF_EXISTS``): Download/generate mode. |
| 593 | force_local_path (Optional str): Optional path to a local path to download and prepare the script to. |
| 594 | Used to inspect or modify the script folder. |
| 595 | dynamic_modules_path (Optional str, defaults to HF_MODULES_CACHE / "datasets_modules", i.e. ~/.cache/huggingface/modules/datasets_modules): |
| 596 | Optional path to the directory in which the dynamic modules are saved. It must have been initialized with :obj:`init_dynamic_modules`. |
| 597 | By default the datasets and metrics are stored inside the `datasets_modules` module. |
| 598 | download_kwargs: optional attributes for DownloadConfig() which will override the attributes in download_config if supplied. |
| 599 | |
| 600 | Returns: |
| 601 | ImportableModule |
| 602 | """ |
| 603 | if download_config is None: |
| 604 | download_config = DownloadConfig(**download_kwargs) |
| 605 | download_mode = DownloadMode(download_mode or DownloadMode.REUSE_DATASET_IF_EXISTS) |
| 606 | download_config.extract_compressed_file = True |
| 607 | download_config.force_extract = True |
| 608 | |
| 609 | filename = list(filter(lambda x: x, path.replace(os.sep, "/").split("/")))[-1] |
| 610 | if not filename.endswith(".py"): |
| 611 | filename = filename + ".py" |
| 612 | combined_path = os.path.join(path, filename) |
| 613 | # Try locally |
| 614 | if path.endswith(filename): |
| 615 | if os.path.isfile(path): |
| 616 | return LocalEvaluationModuleFactory( |
searching dependent graphs…