Methods for listing and loading datasets and metrics:
( with_community_datasets = True with_details = False )
List all the datasets scripts available on the Hugging Face Hub.
( path: str name: typing.Optional[str] = None data_dir: typing.Optional[str] = None data_files: typing.Union[str, typing.Sequence[str], typing.Mapping[str, typing.Union[str, typing.Sequence[str]]], NoneType] = None split: typing.Union[str, datasets.splits.Split, NoneType] = None cache_dir: typing.Optional[str] = None features: typing.Optional[datasets.features.features.Features] = None download_config: typing.Optional[datasets.download.download_config.DownloadConfig] = None download_mode: typing.Optional[datasets.download.download_manager.DownloadMode] = None ignore_verifications: bool = False keep_in_memory: typing.Optional[bool] = None save_infos: bool = False revision: typing.Union[str, datasets.utils.version.Version, NoneType] = None use_auth_token: typing.Union[str, bool, NoneType] = None task: typing.Union[str, datasets.tasks.base.TaskTemplate, NoneType] = None streaming: bool = False **config_kwargs ) → Dataset or DatasetDict
Parameters
str
) — Path or name of the dataset.
Depending on path
, the dataset builder that is used comes from a generic dataset script (JSON, CSV, Parquet, text etc.) or from the dataset script (a python file) inside the dataset directory.
For local datasets:
path
is a local directory (containing data files only)
-> load a generic dataset builder (csv, json, text etc.) based on the content of the directory
e.g. './path/to/directory/with/my/csv/data'
.path
is a local dataset script or a directory containing a local dataset script (if the script has the same name as the directory):
-> load the dataset builder from the dataset script
e.g. './dataset/squad'
or './dataset/squad/squad.py'
.For datasets on the Hugging Face Hub (list all available datasets and ids with datasets.list_datasets()
)
path
is a dataset repository on the HF hub (containing data files only)
-> load a generic dataset builder (csv, text etc.) based on the content of the repository
e.g. 'username/dataset_name'
, a dataset repository on the HF hub containing your data files.path
is a dataset repository on the HF hub with a dataset script (if the script has the same name as the directory)
-> load the dataset builder from the dataset script in the dataset repository
e.g. glue
, squad
, 'username/dataset_name'
, a dataset repository on the HF hub containing a dataset script ‘dataset_name.py’.str
, optional) — Defining the name of the dataset configuration.
str
, optional) — Defining the data_dir of the dataset configuration. If specified for the generic builders (csv, text etc.) or the Hub datasets and data_files is None,
the behavior is equal to passing os.path.join(data_dir, **) as data_files to reference all the files in a directory.
str
or Sequence
or Mapping
, optional) — Path(s) to source data file(s).
str
) — Which split of the data to load.
If None, will return a dict with all splits (typically datasets.Split.TRAIN and datasets.Split.TEST).
If given, will return a single Dataset.
Splits can be combined and specified like in tensorflow-datasets.
str
, optional) — Directory to read/write data. Defaults to ”~/.cache/huggingface/datasets”.
REUSE_DATASET_IF_EXISTS
) — Download/generate mode.
bool
, default False
) — Ignore the verifications of the downloaded/processed dataset information (checksums/size/splits/…).
bool
, default None
) — Whether to copy the dataset in-memory. If None, the dataset
will not be copied in-memory unless explicitly enabled by setting datasets.config.IN_MEMORY_MAX_SIZE to
nonzero. See more details in the load_dataset_enhancing_performance section.
bool
, default False
) — Save the dataset information (checksums/size/splits/…).
str
, optional) — Version of the dataset script to load:
str
or bool
, optional) — Optional string or boolean to use as Bearer token for remote files on the Datasets Hub.
If True, will get token from ”~/.huggingface”.
str
) — The task to prepare the dataset for during training and evaluation. Casts the dataset’s Features to standardized column names and types as detailed in :py:mod:datasets.tasks.
bool
, default False
) — If set to True, don’t download the data files. Instead, it streams the data progressively while
iterating on the dataset. An IterableDataset or IterableDatasetDict is returned instead in this case.
Note that streaming works for datasets that use data formats that support being iterated over like txt, csv, jsonl for example. Json files may be downloaded completely. Also streaming from remote zip or gzip files is supported but other compressed formats like rar and xz are not yet supported. The tgz format doesn’t allow streaming.
Returns
datasets.DatasetDict
with each split.or IterableDataset or IterableDatasetDict: if streaming=True
datasets.streaming.IterableDatasetDict
with each split.Load a dataset from the Hugging Face Hub, or a local dataset.
You can find the list of datasets on the Hub at https://huggingface.co/datasets or with datasets.list_datasets()
.
A dataset is a directory that contains:
Note that dataset scripts can also download and read data files from anywhere - in case your data files already exist online.
This function does the following under the hood:
Download and import in the library the dataset script from path
if it’s not already cached inside the library.
If the dataset has no dataset script, then a generic dataset script is imported instead (JSON, CSV, Parquet, text, etc.)
Dataset scripts are small python scripts that define dataset builders. They define the citation, info and format of the dataset, contain the path or URL to the original data files and the code to load examples from the original data files.
You can find the complete list of datasets in the Datasets Hub at https://huggingface.co/datasets
Run the dataset script which will:
Download the dataset file from the original URL (see the script) if it’s not already available locally or cached.
Process and cache the dataset in typed Arrow tables for caching.
Arrow table are arbitrarily long, typed tables which can store nested objects and be mapped to numpy/pandas/python generic types. They can be directly accessed from disk, loaded in RAM or even streamed over the web.
Return a dataset built from the requested splits in split
(default: all).
It also allows to load a dataset from a local directory or a dataset repository on the Hugging Face Hub without dataset script. In this case, it automatically loads all the data files from the directory or the dataset repository.
Passing use_auth_token=True is required when you want to access a private dataset.
Example:
Load a dataset from the Hugging Face Hub:
>>> from datasets import load_dataset
>>> ds = load_dataset('rotten_tomatoes', split='train')
# Map data files to splits
>>> data_files = {'train': 'train.csv', 'test': 'test.csv'}
>>> ds = load_dataset('namespace/your_dataset_name', data_files=data_files)
Load a local dataset:
# Load a CSV file
>>> from datasets import load_dataset
>>> ds = load_dataset('csv', data_files='path/to/local/my_dataset.csv')
# Load a JSON file
>>> from datasets import load_dataset
>>> ds = load_dataset('json', data_files='path/to/local/my_dataset.json')
# Load from a local loading script
>>> from datasets import load_dataset
>>> ds = load_dataset('path/to/local/loading_script/loading_script.py', split='train')
( dataset_path: str fs = None keep_in_memory: typing.Optional[bool] = None ) → Dataset or DatasetDict
Parameters
str
) — Path (e.g. “dataset/train”) or remote URI (e.g.
“s3://my-bucket/dataset/train”) of the Dataset or DatasetDict directory where the dataset will be
loaded from.
fsspec.spec.AbstractFileSystem
, optional, default None
) —
Instance of the remote filesystem used to download the files from.
bool
, default None
) — Whether to copy the dataset in-memory. If None, the dataset
will not be copied in-memory unless explicitly enabled by setting datasets.config.IN_MEMORY_MAX_SIZE to
nonzero. See more details in the load_dataset_enhancing_performance section.
Returns
datasets.DatasetDict
with each split.Loads a dataset that was previously saved using Dataset.save_to_disk() from a dataset directory, or
from a filesystem using either datasets.filesystems.S3FileSystem or any implementation of
fsspec.spec.AbstractFileSystem
.
( path: str name: typing.Optional[str] = None data_dir: typing.Optional[str] = None data_files: typing.Union[str, typing.Sequence[str], typing.Mapping[str, typing.Union[str, typing.Sequence[str]]], NoneType] = None cache_dir: typing.Optional[str] = None features: typing.Optional[datasets.features.features.Features] = None download_config: typing.Optional[datasets.download.download_config.DownloadConfig] = None download_mode: typing.Optional[datasets.download.download_manager.DownloadMode] = None revision: typing.Union[str, datasets.utils.version.Version, NoneType] = None use_auth_token: typing.Union[str, bool, NoneType] = None **config_kwargs ) → DatasetBuilder
Parameters
str
) — Path or name of the dataset.
Depending on path
, the dataset builder that is used comes from a generic dataset script (JSON, CSV, Parquet, text etc.) or from the dataset script (a python file) inside the dataset directory.
For local datasets:
path
is a local directory (containing data files only)
-> load a generic dataset builder (csv, json, text etc.) based on the content of the directory
e.g. './path/to/directory/with/my/csv/data'
.path
is a local dataset script or a directory containing a local dataset script (if the script has the same name as the directory):
-> load the dataset builder from the dataset script
e.g. './dataset/squad'
or './dataset/squad/squad.py'
.For datasets on the Hugging Face Hub (list all available datasets and ids with datasets.list_datasets()
)
path
is a dataset repository on the HF hub (containing data files only)
-> load a generic dataset builder (csv, text etc.) based on the content of the repository
e.g. 'username/dataset_name'
, a dataset repository on the HF hub containing your data files.path
is a dataset repository on the HF hub with a dataset script (if the script has the same name as the directory)
-> load the dataset builder from the dataset script in the dataset repository
e.g. glue
, squad
, 'username/dataset_name'
, a dataset repository on the HF hub containing a dataset script ‘dataset_name.py’.str
, optional) — Defining the name of the dataset configuration.
str
, optional) — Defining the data_dir of the dataset configuration. If specified for the generic builders (csv, text etc.) or the Hub datasets and data_files is None,
the behavior is equal to passing os.path.join(data_dir, **) as data_files to reference all the files in a directory.
str
or Sequence
or Mapping
, optional) — Path(s) to source data file(s).
str
, optional) — Directory to read/write data. Defaults to ”~/.cache/huggingface/datasets”.
REUSE_DATASET_IF_EXISTS
) — Download/generate mode.
str
, optional) — Version of the dataset script to load:
str
or bool
, optional) — Optional string or boolean to use as Bearer token for remote files on the Datasets Hub.
If True, will get token from ”~/.huggingface”.
Returns
Load a dataset builder from the Hugging Face Hub, or a local dataset. A dataset builder can be used to inspect general information that is required to build a dataset (cache directory, config, dataset info, etc.) without downloading the dataset itself.
You can find the list of datasets on the Hub at https://huggingface.co/datasets or with datasets.list_datasets()
.
A dataset is a directory that contains:
Note that dataset scripts can also download and read data files from anywhere - in case your data files already exist online.
Passing use_auth_token=True is required when you want to access a private dataset.
( path: str revision: typing.Union[str, datasets.utils.version.Version, NoneType] = None download_config: typing.Optional[datasets.download.download_config.DownloadConfig] = None download_mode: typing.Optional[datasets.download.download_manager.DownloadMode] = None dynamic_modules_path: typing.Optional[str] = None data_files: typing.Union[str, typing.List, typing.Dict, NoneType] = None **download_kwargs )
Parameters
str
) — path to the dataset processing script with the dataset builder. Can be either:
'./dataset/squad'
or './dataset/squad/squad.py'
datasets.list_datasets()
)
e.g. 'squad'
, 'glue'
or 'openai/webtext'
Union[str, datasets.Version]
) —
If specified, the dataset module will be loaded from the datasets repository at this version.
By default:
REUSE_DATASET_IF_EXISTS
) — Download/generate mode.
init_dynamic_modules
.
By default the datasets and metrics are stored inside the datasets_modules module.
Union[Dict, List, str]
, optional) — Defining the data_files of the dataset configuration.
use_auth_token
Get the list of available config names for a particular dataset.
( path: str data_files: typing.Union[str, typing.List, typing.Dict, NoneType] = None download_config: typing.Optional[datasets.download.download_config.DownloadConfig] = None download_mode: typing.Optional[datasets.download.download_manager.DownloadMode] = None revision: typing.Union[str, datasets.utils.version.Version, NoneType] = None use_auth_token: typing.Union[str, bool, NoneType] = None **config_kwargs )
Parameters
str
) — path to the dataset processing script with the dataset builder. Can be either:
'./dataset/squad'
or './dataset/squad/squad.py'
datasets.list_datasets()
)
e.g. 'squad'
, 'glue'
or 'openai/webtext'
Union[str, datasets.Version]
) —
If specified, the dataset module will be loaded from the datasets repository at this version.
By default:
REUSE_DATASET_IF_EXISTS
) — Download/generate mode.
Union[Dict, List, str]
, optional) — Defining the data_files of the dataset configuration.
str
or bool
, optional) — Optional string or boolean to use as Bearer token for remote files on the Datasets Hub.
If True, will get token from ”~/.huggingface”.
Get the meta information about a dataset, returned as a dict mapping config name to DatasetInfoDict.
( path: str config_name: typing.Optional[str] = None data_files: typing.Union[str, typing.Sequence[str], typing.Mapping[str, typing.Union[str, typing.Sequence[str]]], NoneType] = None download_config: typing.Optional[datasets.download.download_config.DownloadConfig] = None download_mode: typing.Optional[datasets.download.download_manager.DownloadMode] = None revision: typing.Union[str, datasets.utils.version.Version, NoneType] = None use_auth_token: typing.Union[str, bool, NoneType] = None **config_kwargs )
Parameters
str
) — path to the dataset processing script with the dataset builder. Can be either:
'./dataset/squad'
or './dataset/squad/squad.py'
datasets.list_datasets()
)
e.g. 'squad'
, 'glue'
or 'openai/webtext'
str
, optional) — Defining the name of the dataset configuration.
str
or Sequence
or Mapping
, optional) — Path(s) to source data file(s).
REUSE_DATASET_IF_EXISTS
) — Download/generate mode.
str
, optional) — Version of the dataset script to load:
str
or bool
, optional) — Optional string or boolean to use as Bearer token for remote files on the Datasets Hub.
If True, will get token from ”~/.huggingface”.
Get the list of available splits for a particular config and dataset.
( path: str local_path: str download_config: typing.Optional[datasets.download.download_config.DownloadConfig] = None **download_kwargs )
Parameters
'./dataset/squad'
or './dataset/squad/squad.py'
.'squad'
, 'glue'
or 'openai/webtext'
.Allow inspection/modification of a dataset script by copying on local drive at local_path.
Metrics is deprecated in 🤗 Datasets. To learn more about how to use metrics, take a look at the library 🤗 Evaluate! In addition to metrics, you can find more tools for evaluating models and datasets.
( with_community_metrics = True with_details = False )
List all the metrics script available on the Hugging Face Hub.
Deprecated in 2.5.0
Use evaluate.list_evaluation_modules instead, from the new library 🤗 Evaluate: https://huggingface.co/docs/evaluate
( path: str config_name: typing.Optional[str] = None process_id: int = 0 num_process: int = 1 cache_dir: typing.Optional[str] = None experiment_id: typing.Optional[str] = None keep_in_memory: bool = False download_config: typing.Optional[datasets.download.download_config.DownloadConfig] = None download_mode: typing.Optional[datasets.download.download_manager.DownloadMode] = None revision: typing.Union[str, datasets.utils.version.Version, NoneType] = None **metric_init_kwargs )
Parameters
str
) —
path to the metric processing script with the metric builder. Can be either:'./metrics/rouge'
or './metrics/rogue/rouge.py'
datasets.list_metrics()
)
e.g. 'rouge'
or 'bleu'
str
, optional) — selecting a configuration for the metric (e.g. the GLUE metric has a configuration for each subset)
int
, optional) — for distributed evaluation: id of the process
int
, optional) — for distributed evaluation: total number of processes
str
) — A specific experiment id. This is used if several distributed evaluations share the same file system.
This is useful to compute metrics in distributed setups (in particular non-additive metrics like F1).
datasets.DownloadConfig
— specific download configuration parameters.
REUSE_DATASET_IF_EXISTS
) — Download/generate mode.
Union[str, datasets.Version]
) — if specified, the module will be loaded from the datasets repository
at this version. By default, it is set to the local version of the lib. Specifying a version that is different from
your local version of the lib might cause compatibility issues.
Load a datasets.Metric.
Deprecated in 2.5.0
Use evaluate.load instead, from the new library 🤗 Evaluate: https://huggingface.co/docs/evaluate
( path: str local_path: str download_config: typing.Optional[datasets.download.download_config.DownloadConfig] = None **download_kwargs )
Parameters
str
) — path to the dataset processing script with the dataset builder. Can be either:
'./dataset/squad'
or './dataset/squad/squad.py'
datasets.list_datasets()
)
e.g. 'squad'
, 'glue'
or 'openai/webtext'
str
) — path to the local folder to copy the datset script to.
datasets.DownloadConfig
) — specific download configuration parameters.
Allow inspection/modification of a metric script by copying it on local drive at local_path.
Deprecated in 2.5.0
Use evaluate.inspect_evaluation_module instead, from the new library 🤗 Evaluate instead: https://huggingface.co/docs/evaluate
Configurations used to load data files. They are used when loading local files or a dataset repository:
load_dataset("parquet", data_dir="path/to/data/dir")
load_dataset("allenai/c4")
You can pass arguments to load_dataset
to configure data loading.
For example you can specify the sep
parameter to define the CsvConfig that is used to load the data:
load_dataset("csv", data_dir="path/to/data/dir", sep="\t")
( name: str = 'default' version: typing.Union[str, datasets.utils.version.Version, NoneType] = 0.0.0 data_dir: typing.Optional[str] = None data_files: typing.Optional[datasets.data_files.DataFilesDict] = None description: typing.Optional[str] = None features: typing.Optional[datasets.features.features.Features] = None encoding: str = 'utf-8' chunksize: int = 10485760 keep_linebreaks: bool = False sample_by: str = 'line' )
BuilderConfig for text files.
( name: str = 'default' version: typing.Union[str, datasets.utils.version.Version, NoneType] = 0.0.0 data_dir: typing.Optional[str] = None data_files: typing.Optional[datasets.data_files.DataFilesDict] = None description: typing.Optional[str] = None sep: str = ',' delimiter: typing.Optional[str] = None header: typing.Union[int, typing.List[int], str, NoneType] = 'infer' names: typing.Optional[typing.List[str]] = None column_names: typing.Optional[typing.List[str]] = None index_col: typing.Union[int, str, typing.List[int], typing.List[str], NoneType] = None usecols: typing.Union[typing.List[int], typing.List[str], NoneType] = None prefix: typing.Optional[str] = None mangle_dupe_cols: bool = True engine: typing.Optional[str] = None converters: typing.Dict[typing.Union[int, str], typing.Callable[[typing.Any], typing.Any]] = None true_values: typing.Optional[list] = None false_values: typing.Optional[list] = None skipinitialspace: bool = False skiprows: typing.Union[int, typing.List[int], NoneType] = None nrows: typing.Optional[int] = None na_values: typing.Union[str, typing.List[str], NoneType] = None keep_default_na: bool = True na_filter: bool = True verbose: bool = False skip_blank_lines: bool = True thousands: typing.Optional[str] = None decimal: str = '.' lineterminator: typing.Optional[str] = None quotechar: str = '"' quoting: int = 0 escapechar: typing.Optional[str] = None comment: typing.Optional[str] = None encoding: typing.Optional[str] = None dialect: typing.Optional[str] = None error_bad_lines: bool = True warn_bad_lines: bool = True skipfooter: int = 0 doublequote: bool = True memory_map: bool = False float_precision: typing.Optional[str] = None chunksize: int = 10000 features: typing.Optional[datasets.features.features.Features] = None encoding_errors: typing.Optional[str] = 'strict' on_bad_lines: typing.Literal['error', 'warn', 'skip'] = 'error' )
BuilderConfig for CSV.
( name: str = 'default' version: typing.Union[str, datasets.utils.version.Version, NoneType] = 0.0.0 data_dir: typing.Optional[str] = None data_files: typing.Optional[datasets.data_files.DataFilesDict] = None description: typing.Optional[str] = None features: typing.Optional[datasets.features.features.Features] = None field: typing.Optional[str] = None use_threads: bool = True block_size: typing.Optional[int] = None chunksize: int = 10485760 newlines_in_values: typing.Optional[bool] = None )
BuilderConfig for JSON.
( name: str = 'default' version: typing.Union[str, datasets.utils.version.Version, NoneType] = 0.0.0 data_dir: typing.Optional[str] = None data_files: typing.Optional[datasets.data_files.DataFilesDict] = None description: typing.Optional[str] = None batch_size: int = 10000 columns: typing.Optional[typing.List[str]] = None features: typing.Optional[datasets.features.features.Features] = None )
BuilderConfig for Parquet.
( name: str = 'default' version: typing.Union[str, datasets.utils.version.Version, NoneType] = 0.0.0 data_dir: typing.Optional[str] = None data_files: typing.Optional[datasets.data_files.DataFilesDict] = None description: typing.Optional[str] = None sql: typing.Union[str, ForwardRef('sqlalchemy.sql.Selectable')] = None con: typing.Union[str, ForwardRef('sqlalchemy.engine.Connection'), ForwardRef('sqlalchemy.engine.Engine'), ForwardRef('sqlite3.Connection')] = None index_col: typing.Union[str, typing.List[str], NoneType] = None coerce_float: bool = True params: typing.Union[typing.List, typing.Tuple, typing.Dict, NoneType] = None parse_dates: typing.Union[typing.List, typing.Dict, NoneType] = None columns: typing.Optional[typing.List[str]] = None chunksize: typing.Optional[int] = 10000 features: typing.Optional[datasets.features.features.Features] = None )
BuilderConfig for SQL.
( name: str = 'default' version: typing.Union[str, datasets.utils.version.Version, NoneType] = 0.0.0 data_dir: typing.Optional[str] = None data_files: typing.Optional[datasets.data_files.DataFilesDict] = None description: typing.Optional[str] = None features: typing.Optional[datasets.features.features.Features] = None drop_labels: bool = None drop_metadata: bool = None )
BuilderConfig for ImageFolder.
( name: str = 'default' version: typing.Union[str, datasets.utils.version.Version, NoneType] = 0.0.0 data_dir: typing.Optional[str] = None data_files: typing.Optional[datasets.data_files.DataFilesDict] = None description: typing.Optional[str] = None features: typing.Optional[datasets.features.features.Features] = None drop_labels: bool = None drop_metadata: bool = None )
Builder Config for AudioFolder.