[huggingface]—离线加载数据集

前言

服务器没网,需要手动下载,离线加载数据。

步骤

以加载下面这个数据集为例:

复制代码
dataset = load_dataset('stereoset', 'intrasentence')
  1. 去hugginface找到这个仓库,看files and versions里面的py文件,需要下载什么文件,比如:

    https://huggingface.co/datasets/stereoset/blob/main/stereoset.py
    _DOWNLOAD_URL = "https://github.com/moinnadeem/Stereoset/raw/master/data/dev.json"

  2. 把这个dev.json,以及files and versions里面的其他文件(这里是dataset_infos.json,stereoset.py)都下载下来,放入目录X。

  3. 把加载数据的那行代码改成:

    dataset = load_dataset("X/stereoset.py", 'intrasentence')

(如果是dataset = load_dataset("X", 'intrasentence'),会走site-packages/datasets/builder.pydef _prepare_split_single,可能会报如下错)

复制代码
ValueError: Not able to read records in the JSON file at /data/syxu/representation-engineering/data/fairness/dev.json. You should probably indicate the field of the JSON file containing your records. This JSON file contain the following fields: ['version', 'data']. Select the correct one and provide it as `field='XXX'` to the dataset loading method. 
  1. 改_split_generators中得到data_path的方式

原来可能是:

复制代码
data_path = dl_manager.download_and_extract(self._DOWNLOAD_URL)

注释掉这行,把data_path直接改成'X/dev.json'

  1. 最后,通过环境变量设置为离线模式

    export HF_DATASETS_OFFLINE=1

其他情况

parquet文件:

复制代码
from datasets import load_dataset
dataset = load_dataset("parquet", data_files={'train': [文件路径], 'test': [同]})

参考

https://huggingface.co/docs/datasets/v1.12.0/loading.html

相关推荐
吴佳浩2 分钟前
Vibe Coding 时代:Vue 消失了还是 React 太强?
人工智能
Elastic 中国社区官方博客4 分钟前
Elasticsearch:如何在 Elastic AI Builder 里使用 DSL 来查询 Elasticsearch
大数据·人工智能·elasticsearch·搜索引擎·ai·全文检索
musicml12 分钟前
从 Vibe Coding 到 SDD(规范驱动开发):AI 原生时代的软件工程化实践
人工智能·驱动开发·软件工程
Deepoch16 分钟前
Deepoc具身模型:重塑无人机无遥控器作业
人工智能·科技·无人机·具身模型·deepoc
i建模18 分钟前
Claude Code在编程之外的能力
人工智能
言之。20 分钟前
用Claude Code搞定产品上线
人工智能
HIT_Weston23 分钟前
31、【Agent】【OpenCode】模型配置(OpenRouter&OpenCode)
人工智能·agent·opencode
Coder个人博客35 分钟前
06_apollo_third_party子模块整体软件架构深入分析文档
linux·人工智能·架构
uzong36 分钟前
ClaudeCode 入门详细教程,手把手带你Vibe Coding
前端·人工智能
rebekk38 分钟前
PyTorch Dispatcher介绍
人工智能·pytorch·python