[huggingface]—离线加载数据集

前言

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

情况1

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

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"
  1. 把这个dev.json,以及files and versions里面的其他文件(这里是dataset_infos.json,stereoset.py)都下载下来,放入目录X。
  2. 把加载数据的那行代码改成:
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

情况2

更简单的,在有网络的地方,先下载数据集并保存:

from datasets import load_dataset
data = load_dataset(xxx)
data.save_to_disk(path)

之后就可以

from datasets import load_from_disk
data = load_from_disk(path)

其他情况

parquet文件:

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

参考

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

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值