[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

相关推荐
Baihai_IDP11 分钟前
剖析大模型产生幻觉的三大根源
人工智能·面试·llm
DatGuy31 分钟前
Week 26: 深度学习补遗:LSTM 原理与代码复现
人工智能·深度学习·lstm
杜子不疼.1 小时前
光影交织:基于Rokid AI眼镜的沉浸式影视剧情互动体验开发实战
人工智能
IT_陈寒1 小时前
Python高手都在用的5个隐藏技巧,让你的代码效率提升50%
前端·人工智能·后端
love530love1 小时前
【保姆级教程】Windows + Podman 从零部署 Duix-Avatar 数字人项目
人工智能·windows·笔记·python·数字人·podman·duix-avatar
周杰伦_Jay1 小时前
【 2025年必藏】8个开箱即用的优质开源智能体(Agent)项目
人工智能·机器学习·架构·开源
大模型真好玩1 小时前
低代码Agent开发框架使用指南(八)—Coze 知识库详解
人工智能·agent·coze
2***57422 小时前
人工智能在智能投顾中的算法
人工智能·算法
草莓熊Lotso3 小时前
Git 分支管理:从基础操作到协作流程(本地篇)
大数据·服务器·开发语言·c++·人工智能·git·sql
youngfengying3 小时前
Swin Transformer
人工智能·深度学习·transformer