[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

相关推荐
code_pgf2 分钟前
mllm训练过程中有效地利用辅助监督信号来减少幻觉的方法
人工智能·深度学习·计算机视觉
风华圆舞4 分钟前
鸿蒙 + Flutter 下 AI 助手为什么要支持流式输出
人工智能·flutter·harmonyos
爱勇宝5 分钟前
如何评价 Claude Fable 5 全球暂停访问?
人工智能·程序员
装不满的克莱因瓶5 分钟前
自然语言处理常见任务——从文本理解到生成式AI的完整任务体系
人工智能·pytorch·python·深度学习·ai·自然语言处理
朱大喜8 分钟前
AI 数据分析实战:大模型驱动的自动化报表生成,从数据到洞察的工程化链路
人工智能
wb0430720119 分钟前
阿明的二次创业——从阿明用 AI 开第二家店,看 AI 原生创业的四阶段方法论
大数据·人工智能·架构
Godspeed Zhao19 分钟前
Level 4自动驾驶系统设计0——功能与场景0
人工智能·机器学习·自动驾驶
Dola_Zou22 分钟前
边缘智能的“黑暗森林”:工业 AI 模型下沉的资产防护与变现密码
人工智能·安全·自动化·软件工程·软件加密
青岛前景互联信息技术有限公司23 分钟前
前景互联·新一代智能接处警系统:AI+大模型+Agent智能接处警一体化解决方案
大数据·人工智能·物联网
xin_yao_xin26 分钟前
Claude Code 安装与 DeepSeek-V4 模型配置(2026 最新)
人工智能·ai·大模型·deepseek·claude code