跳转到主要内容

HuggingFace社区驱动的开源数据集库

项目描述

Hugging Face Datasets Library

Build GitHub Documentation GitHub release Number of datasets Contributor Covenant DOI

🤗 Datasets 是一个轻量级库,提供以下两个主要功能

  • 针对多个公共数据集的一行式数据加载器:一行代码即可下载和预处理HuggingFace数据集库(https://hugging-face.cn/datasets)上提供的所有主要公共数据集(图像数据集、音频数据集、467种语言和方言的文本数据集等)。只需简单命令如squad_dataset = load_dataset("squad"),即可准备这些数据集,用于训练/评估机器学习模型(Numpy/Pandas/PyTorch/TensorFlow/JAX)。
  • 高效数据预处理:对公共数据集以及CSV、JSON、文本、PNG、JPEG、WAV、MP3、Parquet等本地数据集进行简单、快速且可重复的数据预处理。使用简单命令如processed_dataset = dataset.map(process_example),高效准备数据集以进行审查和机器学习模型评估及训练。

🎓 文档 🔎 在Hub中查找数据集 🌟 在Hub上分享数据集

🤗 Datasets旨在让社区轻松添加和共享新的数据集。

🤗 Datasets具有许多其他有趣的功能

  • 在大型数据集上茁壮成长:🤗 Datasets自然地使用高效的零序列化成本后端(Apache Arrow)对数据集进行内存映射,从而使用户从RAM内存限制中解放出来。
  • 智能缓存:无需等待数据多次处理。
  • 轻量级且快速,具有透明且Pythonic的API(多进程/缓存/内存映射)。
  • 与NumPy、pandas、PyTorch、TensorFlow 2和JAX内置互操作性。
  • 原生支持音频和图像数据。
  • 启用流模式以节省磁盘空间,并立即开始遍历数据集。

🤗 Datasets起源于TensorFlow Datasets的分支,HuggingFace团队衷心感谢TensorFlow Datasets团队构建了这个惊人的库。有关🤗 Datasets与tfds之间主要差异的更多详细信息,请参阅🤗 Datasets与tfds的主要差异部分。

安装

使用pip

🤗 Datasets可以从PyPi安装,并需要在虚拟环境中安装(例如venv或conda)。

pip install datasets

使用conda

🤗 Datasets可以使用以下命令使用conda进行安装:

conda install -c huggingface -c conda-forge datasets

请遵循TensorFlow和PyTorch的安装页面,了解如何使用conda安装它们。

有关安装的更多详细信息,请参阅文档中的安装页面:https://hugging-face.cn/docs/datasets/installation

安装以与PyTorch/TensorFlow/pandas一起使用

如果您计划使用🤗 Datasets与PyTorch(1.0+)、TensorFlow(2.2+)或pandas一起使用,您还应安装PyTorch、TensorFlow或pandas。

有关使用NumPy、pandas、PyTorch或TensorFlow的库的更多详细信息,请参阅文档中的快速入门页面:https://hugging-face.cn/docs/datasets/quickstart

使用

🤗 Datasets旨在非常易于使用 - API围绕单个函数构建,即datasets.load_dataset(dataset_name, **kwargs),该函数实例化数据集。

此库可用于文本、图像、音频等数据集。以下是一个加载文本数据集的示例:

以下是一个快速示例:

from datasets import load_dataset

# Print all the available datasets
from huggingface_hub import list_datasets
print([dataset.id for dataset in list_datasets()])

# Load a dataset and print the first example in the training set
squad_dataset = load_dataset('squad')
print(squad_dataset['train'][0])

# Process the dataset - add a column with the length of the context texts
dataset_with_length = squad_dataset.map(lambda x: {"length": len(x["context"])})

# Process the dataset - tokenize the context texts (using a tokenizer from the 🤗 Transformers library)
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained('bert-base-cased')

tokenized_dataset = squad_dataset.map(lambda x: tokenizer(x['context']), batched=True)

如果您的数据集大于您的磁盘,或者您不想等待下载数据,则可以使用流模式。

# If you want to use the dataset immediately and efficiently stream the data as you iterate over the dataset
image_dataset = load_dataset('cifar100', streaming=True)
for example in image_dataset["train"]:
    break

有关使用库的更多详细信息,请参阅文档中的快速入门页面:https://hugging-face.cn/docs/datasets/quickstart 和具体页面

将新的数据集添加到 Hub

我们有一个非常详细的一步一步指南,指导您将新的数据集添加到 number of datasets 数据集,这些数据集已经提供在 HuggingFace Datasets Hub 上。

您可以在以下位置找到

🤗 Datasets 与 tfds 之间的主要区别

如果您熟悉出色的 TensorFlow Datasets,以下是 🤗 Datasets 与 tfds 之间的主要区别

  • 🤗 Datasets 中的脚本不是库中提供的,而是在请求时查询、下载/缓存和动态加载的
  • 🤗 Datasets 的后端序列化基于 Apache Arrow 而不是 TF Records,并利用 Python 数据类来提供信息和功能(具有一些不同的功能,我们主要不进行编码,并在后端序列化缓存中尽可能多地存储原始数据)。
  • 🤗 Datasets 的用户界面数据集对象不是 tf.data.Dataset,而是一个内置的框架无关的数据集类,其方法灵感来自我们对 tf.data 的喜爱(如 map() 方法)。它基本上封装了一个内存映射的 Arrow 表缓存。

免责声明

🤗 Datasets 可能会运行数据集作者定义的 Python 代码来解析某些数据格式或结构。出于安全原因,我们要求用户

  • 在运行之前检查他们将要运行的数据集脚本,并
  • 锁定他们使用的存储库的 修订版

如果您是数据集的所有者并希望更新其任何部分(描述、引用、许可证等),或者不希望您的数据集包含在 Hugging Face Hub 中,请在数据集页面的“社区”选项卡中打开一个讨论或拉取请求。感谢您对机器学习社区的贡献!

BibTeX

如果您想引用我们的 🤗 Datasets 库,您可以使用我们的 论文

@inproceedings{lhoest-etal-2021-datasets,
    title = "Datasets: A Community Library for Natural Language Processing",
    author = "Lhoest, Quentin  and
      Villanova del Moral, Albert  and
      Jernite, Yacine  and
      Thakur, Abhishek  and
      von Platen, Patrick  and
      Patil, Suraj  and
      Chaumond, Julien  and
      Drame, Mariama  and
      Plu, Julien  and
      Tunstall, Lewis  and
      Davison, Joe  and
      {\v{S}}a{\v{s}}ko, Mario  and
      Chhablani, Gunjan  and
      Malik, Bhavitvya  and
      Brandeis, Simon  and
      Le Scao, Teven  and
      Sanh, Victor  and
      Xu, Canwen  and
      Patry, Nicolas  and
      McMillan-Major, Angelina  and
      Schmid, Philipp  and
      Gugger, Sylvain  and
      Delangue, Cl{\'e}ment  and
      Matussi{\`e}re, Th{\'e}o  and
      Debut, Lysandre  and
      Bekman, Stas  and
      Cistac, Pierric  and
      Goehringer, Thibault  and
      Mustar, Victor  and
      Lagunas, Fran{\c{c}}ois  and
      Rush, Alexander  and
      Wolf, Thomas",
    booktitle = "Proceedings of the 2021 Conference on Empirical Methods in Natural Language Processing: System Demonstrations",
    month = nov,
    year = "2021",
    address = "Online and Punta Cana, Dominican Republic",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2021.emnlp-demo.21",
    pages = "175--184",
    abstract = "The scale, variety, and quantity of publicly-available NLP datasets has grown rapidly as researchers propose new tasks, larger models, and novel benchmarks. Datasets is a community library for contemporary NLP designed to support this ecosystem. Datasets aims to standardize end-user interfaces, versioning, and documentation, while providing a lightweight front-end that behaves similarly for small datasets as for internet-scale corpora. The design of the library incorporates a distributed, community-driven approach to adding datasets and documenting usage. After a year of development, the library now includes more than 650 unique datasets, has more than 250 contributors, and has helped support a variety of novel cross-dataset research projects and shared tasks. The library is available at https://github.com/huggingface/datasets.",
    eprint={2109.02846},
    archivePrefix={arXiv},
    primaryClass={cs.CL},
}

如果您需要引用我们 🤗 Datasets 库的特定版本以实现可重复性,您可以使用此 列表 中相应的 Zenodo DOI 版本。

项目详情


发布历史 发布通知 | RSS 源

下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

datasets-3.0.1.tar.gz (1.9 MB 查看哈希值)

上传时间

构建分布

datasets-3.0.1-py3-none-any.whl (471.6 kB 查看哈希值)

上传时间 Python 3

由以下机构支持