Datasets: A Community Library for Natural Language Processing

Quentin Lhoest, Albert Villanova del Moral, Yacine Jernite, Abhishek Thakur, Patrick von Platen, Suraj Patil, Julien Chaumond, Mariama Drame, Julien Plu, Lewis Tunstall, Joe Davison, Mario Sasko, Gunjan Chhablani, Bhavitvya Malik, Simon Brandeis, Teven Le Scao, Victor Sanh, Canwen Xu, Nicolas Patry, Angelina McMillan-Major, Philipp Schmid, Sylvain Gugger, Clément Delangue, Théo Matussière, Lysandre Debut, Stas Bekman, Pierric Cistac, Thibault Goehringer, Victor Mustar, François Lagunas, Alexander M. Rush, Thomas Wolf

Introduction

In the modern NLP era, researchers face an "N-dataset problem": utilizing $N$ different datasets often requires writing $N$ different loading scripts and data interfaces. As datasets have ballooned from thousands of points to billions (e.g., PubMed or C4), memory management has become a massive bottleneck. Furthermore, reproducibility is hampered by inconsistent versioning and poor documentation. Practitioners often lack easy access to "metadata"—social biases, licensing, and collection methods—crucial for ethical AI development.

The datasets library by Hugging Face is a community-driven, high-performance toolkit designed to standardize how NLP researchers access and process data. By leveraging Apache Arrow for memory mapping, it allows users to manipulate massive, internet-scale corpora on modest hardware using a simple, unified API.

Technical Architecture

The authors introduce datasets as an open-source library built on four technical pillars:

  1. Standardized Tabular Interface: Every dataset, regardless of its original format (CSV, JSON, text), is converted into a typed tabular format. This allows for a single API (load_dataset) to manage diverse data sources.
  2. Apache Arrow Backend: This is the library's "secret sauce." By using Apache Arrow, a cross-language columnar data framework, files are memory-mapped. The library can "look up" data on disk almost instantly without loading the entire file into RAM, enabling a laptop to process datasets hundreds of gigabytes in size.
  3. The map Function: To handle processing, the library provides a powerful .map() function. It supports batched processing, multi-processing, and automatic caching, ensuring that expensive operations like tokenization do not need to be re-run every time a script starts.
  4. Community-Driven Builder Scripts: Rather than a centralized team writing every loader, the library uses a distributed model where the community contributes "builder scripts" that define how to fetch and format specific datasets.

Library Scope and Diversity

While datasets is a library for data rather than a new benchmark, it successfully standardizes over 650 unique datasets. These include large-scale corpora (C4, PubMed), fine-tuning sets (SQuAD, ELI5), and major benchmarks (GLUE, SuperGLUE). The library specifically aims to support the "long-tail" of languages and tasks that are often overlooked by major frameworks.

Overview of the library's dataset distribution by downloads, tasks, sizes, and languages.

Key Features and Insights

  • Decoupling Data from Frameworks: Unlike framework-specific tools, datasets is framework-agnostic. It provides copy-free hand-offs to NumPy, Pandas, PyTorch, and TensorFlow, acting as a universal "data layer" for the ecosystem.
  • Data Cards as Living Documents: Documentation is not a static PDF but a community-maintained "Data Card" on the Hugging Face Hub. These READMEs track social biases, limitations, and technical specs.
  • Streaming for "Infinite" Data: For datasets too large to download, the library introduces a streaming mode that buffers data on the fly, allowing models to begin training immediately without waiting for massive downloads to finish.
  • Standardized Metrics: The library provides a standardized interface for evaluation metrics (like BLEU or ROUGE), ensuring researchers calculate results consistently.
Example of a Dataset Card for the ELI5 dataset, providing metadata and documentation.

Impact and Future Work

Within its first year, the library reached over 250 contributors and became the backbone for major research projects like the LM Evaluation Harness. Its efficiency in memory-mapping allows for near-zero-copy data access, significantly reducing hardware requirements for state-of-the-art NLP research.

Future directions include expansion into multimodal domains such as images, video, and audio—a direction supported by the underlying Arrow framework. However, as the number of datasets grows, keeping community-contributed scripts up to date with upstream changes in raw data formats remains a significant engineering challenge.

Summary updated

BibTeX
@inproceedings{lhoest2021datasets,
  author = {Quentin Lhoest and Albert Villanova del Moral and Yacine Jernite and Abhishek Thakur and Patrick von Platen and Suraj Patil and Julien Chaumond and Mariama Drame and Julien Plu and Lewis Tunstall and Joe Davison and Mario Sasko and Gunjan Chhablani and Bhavitvya Malik and Simon Brandeis and Teven Le Scao and Victor Sanh and Canwen Xu and Nicolas Patry and Angelina McMillan-Major and Philipp Schmid and Sylvain Gugger and Clément Delangue and Théo Matussière and Lysandre Debut and Stas Bekman and Pierric Cistac and Thibault Goehringer and Victor Mustar and François Lagunas and Alexander M. Rush and Thomas Wolf},
  title = {{Datasets: A Community Library for Natural Language Processing}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2021},
  doi = {10.18653/v1/2021.emnlp-demo.21},
}
Figure