Registry / ai-ml / datasets

datasets

JSON →
library5.0.1pypypi✓ verified 27d ago

HuggingFace library for loading, processing, and sharing datasets for ML. Provides load_dataset() for one-line access to 100k+ public datasets on the Hub, plus local file loading (CSV, JSON, Parquet, Arrow, audio, image, etc.). Built on Apache Arrow for memory-efficient, zero-copy data access. Package name on PyPI is 'datasets' (not 'huggingface-datasets'). Import name is also 'datasets'. CRITICAL: datasets 4.0 (July 2025) removed dataset loading scripts and trust_remote_code entirely. Many older community datasets relying on .py loading scripts now fail with datasets>=4.

pip install datasets
INSTALL
IMPORT
SIG · DATASETS
D
datasets
ai-mlpythonv5.0.1
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v5.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
15/30 runs
26/30 runs
py 3.11
15/30 runs
26/30 runs
py 3.12
15/30 runs
26/30 runs
py 3.13
16/30 runs
26/30 runs
py 3.9
15/30 runs
16/30 runs
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

load_dataset
from datasets import load_dataset
import huggingface-datasets
Package name is 'datasets' on PyPI, not 'huggingface-datasets'. pip install datasets. from datasets import load_dataset.
Dataset / DatasetDict
from datasets import Dataset, DatasetDict
load_dataset() returns DatasetDict (multiple splits) or Dataset (single split). Access splits: ds['train'], ds['test'].
Audio / Image features
from datasets import Audio, Image
Cast columns to Audio() or Image() features to enable automatic decoding. Requires datasets[audio] or datasets[vision] extras.

load_dataset() downloads and caches to HF_HOME. Streaming mode avoids full download for large datasets. map() with batched=True is significantly faster for large datasets. set_format() enables framework-specific tensor output without copying data.

from datasets import load_dataset # Load public dataset from Hub ds = load_dataset("rajpurkar/squad") # returns DatasetDict print(ds) # DatasetDict with 'train' and 'validation' splits print(ds['train'][0]) # first example # Streaming mode (no full download) streaming_ds = load_dataset("rajpurkar/squad", split="train", streaming=True) for example in streaming_ds.take(3): print(example['question']) # Load local files local_ds = load_dataset("json", data_files="./my_data.jsonl", split="train") # map() for preprocessing def tokenize(example): return {"tokens": example["text"].split()} processed = ds['train'].map(tokenize, batched=False) # Convert to PyTorch tensors ds['train'].set_format(type='torch', columns=['input_ids', 'attention_mask']) # Create dataset from dict from datasets import Dataset custom_ds = Dataset.from_dict({"text": ["hello", "world"], "label": [0, 1]})
Debug
Known issues
breakingdatasets 4.0 (July 2025) removed all support for dataset loading scripts (.py files) and the trust_remote_code parameter. Datasets that relied on custom .py loaders now raise: 'RuntimeError: Dataset scripts are no longer supported, but found X.py'. This breaks many community datasets (hotpotqa, common_voice, superb, gaia-benchmark, etc.).
fix
Either: (1) pin datasets<4 as a workaround, or (2) find a Parquet-backed version of the dataset on the Hub, or (3) ask the dataset author to migrate to standard Parquet format. Passing trust_remote_code=True no longer silences the error — it raises a separate error.
affects: >=4.0.0
breakingtrust_remote_code parameter is entirely removed in datasets 4.0. Passing it raises an error rather than being silently ignored. Code with trust_remote_code=True will break on import or call.
fix
Remove trust_remote_code from all load_dataset() calls when using datasets>=4.
affects: >=4.0.0
breakingpyarrow version constraints are strict. datasets pins to specific pyarrow ranges. In environments with multiple packages requiring pyarrow, version conflicts cause ImportError or silent data corruption. datasets and pyarrow must be upgraded together.
fix
Always upgrade together: pip install -U datasets pyarrow. Check compatibility in the datasets changelog for your target version.
affects: all
gotchamap() with num_proc>1 (multiprocessing) uses dill for serialization. Lambda functions and closures that reference non-serializable objects (open file handles, locks, etc.) will silently fail or hang. No clear error is raised.
fix
Use named functions instead of lambdas for map(). Avoid referencing non-serializable objects inside map functions. Use batched=True for large datasets to avoid per-example overhead.
affects: all
gotchaload_dataset() caches datasets to disk by default in HF_HOME. Re-running always returns the cached version. In CI or when dataset content changes on the Hub, stale cached versions are silently returned.
fix
Pass download_mode='force_redownload' to bypass cache. Or delete the cached dataset from ~/.cache/huggingface/datasets/.
affects: all
gotchaGated datasets (some Common Voice, medical, legal datasets) require authentication. load_dataset() raises a 401 or confusing FileNotFoundError if HF_TOKEN is not set or the license has not been accepted.
fix
Set HF_TOKEN env var and accept the dataset license on huggingface.co before calling load_dataset().
affects: all
gotchaPackage name on PyPI is 'datasets' — not 'huggingface-datasets'. pip install huggingface-datasets installs an old, unrelated stub package. Import is also 'from datasets import ...' not 'from huggingface_datasets import ...'.
fix
pip install datasets. from datasets import load_dataset.
affects: all
breakingInstalling `datasets` with certain extras (e.g., `[audio]`, `[vision]`, `[text]`) can pull in dependencies (like `scikit-learn`, `numba`, `soxr`, `soundfile`'s underlying C libraries) that require C/C++ compilers (e.g., gcc) and Python development headers to be present on the system for successful installation. This often leads to build failures (e.g., 'Unknown compiler(s)', 'subprocess-exited-with-error') in minimal environments like Alpine Linux or when using a base Docker image without development tools.
fix
Ensure C/C++ build tools and Python development headers are installed in your environment before installing `datasets` with extras. For Alpine Linux, run `apk add build-base python3-dev`. For Debian/Ubuntu-based images, run `apt-get update && apt-get install -y build-essential python3-dev`.
affects: all
Errors
Common errors & fixes
Exception occurred: Dataset scripts are no longer supported.
The `datasets` library version 4.0.0 and above removed support for loading datasets via Python scripts and the `trust_remote_code` argument, which many older community datasets relied on.
fix
Downgrade `datasets` to a version older than 4.0.0 (`pip install 'datasets<4.0.0'`) or ask the dataset author to convert the dataset to a standard format like Parquet.
FileNotFoundError: Couldn't find a dataset script at [path] or any data file in the same directory. Couldn't find '[dataset_name]' on the Hugging Face Hub either.
The `load_dataset` function cannot locate the specified dataset, either because the path to local files is incorrect, the dataset name on the Hugging Face Hub is misspelled, the dataset is private and the user is not logged in, or there's an issue with the cache.
fix
Double-check the dataset name/path, ensure local files exist at the specified location, log in to Hugging Face (`huggingface-cli login`) if accessing private datasets, or clear the `datasets` cache and try again. For local files, explicitly specify the format (e.g., `load_dataset('csv', data_files='my_data.csv')`).
ValueError: Couldn't cast [schema details] because column names don't match.
The schema inferred by `load_dataset` from the data files does not match an expected schema, or when loading CSV/JSON files, the library struggles to automatically determine column structure, especially with complex delimiters or malformed files. An 'Invalid pattern' `ValueError` can also occur with incorrect glob patterns for `data_files`.
fix
For casting errors, explicitly define the `features` argument in `load_dataset` with the correct schema, or for CSV/JSON, manually provide `column_names` to `load_dataset`. For 'Invalid pattern', correct the glob pattern or use simpler file paths.
ModuleNotFoundError: No module named 'datasets'
The `datasets` library is not installed in the current Python environment, or there is a naming conflict (e.g., a local file named `datasets.py` shadows the installed library).
fix
Install the library using `pip install datasets`. If already installed, check for shadowing files in your project directory and rename them. Ensure your virtual environment is activated if applicable.
ModuleNotFoundError: No module named 'datasets.tasks'
An older version of `datasets` might have used `datasets.tasks` for certain functionalities, which has since been removed or refactored. This often happens when custom scripts or older examples try to import from this specific (now non-existent) submodule.
fix
Remove or update the problematic import statement (e.g., `from datasets.tasks import TextClassification`). The `datasets.tasks` module is generally not meant for direct user import in recent versions; task-related information is usually handled differently within the library's features. Upgrade `datasets` and `huggingface_hub` to their latest versions.
Upgrade
Version history
5.0.1latest on PyPI · released Jul 28, 2026
Audit
Dependencies
pyarrowrequiredRequired. All datasets are backed by Arrow tables. Version constraints are strict — pyarrow version mismatches cause import errors.
huggingface-hubrequiredRequired. Used for dataset discovery, download, and Hub interactions.
dillrequiredRequired. Used for serializing map() functions for multiprocessing.
multiprocessrequiredRequired. Used for parallel map() processing.
Agent activity
78 hits · last 30 days
node
74
OpenAI (training)
1
Resources
datasets — pip install datasets · libregistry