把Huggingface下载的arrow数据集转化为json格式

Arrow2json

使用默认的Huggingface路径

allenai/tulu-3-sft-mixture数据集为例。

使用load_dataset即可:

go 复制代码
from datasets import load_dataset

# 加载数据集
dataset = load_dataset("allenai/tulu-3-sft-mixture")

# 指定保存路径
output_dir = "~/xxx/open-instruct/data/tulu-3-sft-mixture-json"

# 将数据集转换为 JSON 格式
for split in dataset.keys():  # 处理所有划分 (train, validation 等)
    dataset[split].to_json(f"{output_dir}/{split}.json", orient="records", lines=True)

使用ls -sh输出可以看到数据集train.json大小是3.3GB

go 复制代码
3.3G train.json

从本地路径

本地路径如下:

查看一下文件大小:

go 复制代码
ls -sh ~/.cache/huggingface/datasets/allenai___tulu-3-sft-mixture-1024/train
total 1.2G
223M data-00000-of-00005.arrow  283M data-00002-of-00005.arrow  132M data-00004-of-00005.arrow
273M data-00001-of-00005.arrow  252M data-00003-of-00005.arrow  4.0K state.json

使用load_from_disk函数从本地路径加载

go 复制代码
from datasets import load_dataset, load_from_disk

# 加载数据集
dataset = load_from_disk("~/.cache/huggingface/datasets/allenai___tulu-3-sft-mixture-1024")

# 指定保存路径
output_dir = "~/xxx/open-instruct/data/tulu-3-sft-mixture-seqlen-1024-json"

# 将数据集转换为 JSON 格式
for split in dataset.keys():  # 处理所有划分 (train, validation 等)
    dataset[split].to_json(f"{output_dir}/{split}.json", orient="records", lines=True)

这样就可以转换为json了。

查看一下大小:

go 复制代码
ls -sh xxx/open-instruct/data/tulu-3-sft-mixture-seqlen-1024-json
total 1.3G
1.3G train.json

后记

2024年12月29日20点16分于上海.

相关推荐
就叫飞六吧3 小时前
JSON 与 JSON Schema:从“数据快递”到“使用说明书”
json
奇树谦4 小时前
YAML、XML、JSON、TOML、INI、CSV 全面对比:配置文件和数据交换到底该怎么选?
xml·json
TheRouter20 小时前
LLM 流式输出工程实践:SSE、背压、断流重连与JSON 流解析的 6 个生产陷阱
人工智能·json
chushiyunen1 天前
json-rpc笔记
笔记·rpc·json
装不满的克莱因瓶1 天前
JSON 处理与内嵌 Tomcat 部署:Spring Boot 如何实现前后端数据交互与一键启动?
java·spring boot·spring·架构·tomcat·json
ID_180079054732 天前
淘宝 API 详情类 JSON 结构化解析实战(核心章节)
json
haven-8522 天前
AI Agent 生态核心概念详解:Agent、MCP、Skill 与 JSON-RPC
人工智能·rpc·json
_xaboy2 天前
开源Vue组件FormCreate通过 JSON 生成TinyVue表单
前端·vue.js·低代码·开源·json·表单设计器
yumgpkpm2 天前
华为HUAWEI昇腾910B下千问Qwen3.6-27B在的推理加速实践
sql·华为·langchain·json·ai编程·ai写作·gpu算力
SilentSamsara2 天前
文件与数据处理:CSV/JSON/Excel/Parquet 高效操作与内存优化
开发语言·python·青少年编程·性能优化·json·excel