Datasets 文档
安装
开始使用
教程
操作指南
概览
通用
加载过程流式传输配合 PyTorch 使用配合 TensorFlow 使用配合 NumPy 使用配合 JAX 使用配合 Pandas 使用配合 Polars 使用配合 PyArrow 使用配合 Spark 使用缓存管理云存储搜索索引CLI故障排除
音频
视觉
文本
表格
数据集仓库
概念指南
参考
加入 Hugging Face 社区
并获得增强的文档体验
开始使用
安装
在开始之前,您需要设置环境并安装相应的软件包。🤗 Datasets 已在 Python 3.10+ 上通过测试。
如果您想将 🤗 Datasets 与 TensorFlow 或 PyTorch 配合使用,则需要单独安装它们。请参阅 TensorFlow 安装页面 或 PyTorch 安装页面 以获取适用于您框架的具体安装命令。
虚拟环境
您应该在 虚拟环境 中安装 🤗 Datasets,以保持环境整洁并避免依赖冲突。
创建并导航到你的项目目录:
mkdir ~/my-project cd ~/my-project在您的目录中启动一个虚拟环境
python -m venv .env使用以下命令激活和停用虚拟环境:
# Activate the virtual environment source .env/bin/activate # Deactivate the virtual environment source .env/bin/deactivate
创建虚拟环境后,您可以在其中安装 🤗 Datasets。
pip
安装 🤗 Datasets 最直接的方法是使用 pip
pip install datasets
运行以下命令以检查 🤗 Datasets 是否已正确安装
python -c "from datasets import load_dataset; print(load_dataset('rajpurkar/squad', split='train')[0])"此命令将下载第一版 斯坦福问答数据集 (SQuAD),加载训练集分片,并打印第一个训练示例。您应该会看到
{'answers': {'answer_start': [515], 'text': ['Saint Bernadette Soubirous']}, 'context': 'Architecturally, the school has a Catholic character. Atop the Main Building\'s gold dome is a golden statue of the Virgin Mary. Immediately in front of the Main Building and facing it, is a copper statue of Christ with arms upraised with the legend "Venite Ad Me Omnes". Next to the Main Building is the Basilica of the Sacred Heart. Immediately behind the basilica is the Grotto, a Marian place of prayer and reflection. It is a replica of the grotto at Lourdes, France where the Virgin Mary reputedly appeared to Saint Bernadette Soubirous in 1858. At the end of the main drive (and in a direct line that connects through 3 statues and the Gold Dome), is a simple, modern stone statue of Mary.', 'id': '5733be284776f41900661182', 'question': 'To whom did the Virgin Mary allegedly appear in 1858 in Lourdes France?', 'title': 'University_of_Notre_Dame'}音频
要处理音频数据集,您需要将 Audio 功能作为额外的依赖项安装
pip install datasets[audio]
视觉
要处理图像数据集,您需要将 Image 功能作为额外的依赖项安装
pip install datasets[vision]
源码安装
从源代码构建 🤗 Datasets 可以让您对代码库进行修改。要从源代码安装,请克隆仓库并使用以下命令进行安装
git clone https://github.com/huggingface/datasets.git
cd datasets
pip install -e .同样,您可以使用以下命令检查 🤗 Datasets 是否正确安装
python -c "from datasets import load_dataset; print(load_dataset('rajpurkar/squad', split='train')[0])"conda
🤗 Datasets 也可以通过 conda(一种软件包管理系统)进行安装
conda install -c huggingface -c conda-forge datasets