[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

相关推荐
IT_陈寒19 分钟前
Vite的热更新突然不香了,排查三小时差点砸键盘
前端·人工智能·后端
阿里云大数据AI技术2 小时前
构建高转化海外电商搜索:阿里云OpenSearch行业算法版的全链路智能优化策略实战
人工智能·搜索引擎
Awu12272 小时前
⚡从零开发 Agent CLI(五)实现一个可治理、可扩展的工具系统
前端·人工智能·claude
字节跳动视频云技术团队2 小时前
让 Agent 成为音视频工作台:AI MediaKit CLI + Skill 发布
人工智能·音视频开发
魏祖潇3 小时前
framework 整合实战——DDD/TDD/SDD 三件套在 framework 仓的真实落地
人工智能·后端
Token炼金师3 小时前
去噪扩散:从随机噪声到高保真图像的数学之路
人工智能·aigc
这个DBA有点耶3 小时前
AI写的SQL跑崩了生产库,这锅谁背?
数据库·人工智能·程序员
阿里云大数据AI技术4 小时前
阿里云 EMR AI 助手正式发布:从问答工具到全栈智能运维助手
运维·人工智能
Larcher5 小时前
从零搭建 MCP 服务——让 AI 拥有无限扩展能力
人工智能·程序员
zzzzzz3105 小时前
你的 AI 写的 React 烂透了?这个 8000+ Star 的开源工具能揪出 90% 的「Agent 屎山」
人工智能