把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分于上海.

相关推荐
消失的旧时光-19433 分钟前
第六篇:Redis Hash——一个用户对象应该保存成 JSON,还是保存成 Hash?
redis·json·哈希算法
SEO_juper2 小时前
2026年Schema自动注入实战:用Python批量给1000个页面加上JSON-LD,AI引用率实测提升38%
人工智能·python·json·seo·独立站
Wang's Blog4 小时前
AI Agent白手起家37: LangChain 输出解析器实战:文本、JSON、XML 与 Pydantic
xml·langchain·json
灵析表格5 小时前
json_ObjectToKV 函数深度研究报告
json·excel·wps·灵析表格·excel公式盒子
wtsolutions6 小时前
JSON 怎么导入 WPS?怎么转换成 WPS 表格?WPS 怎么打开 JSON?完整教程
json·wps
IDIOT___IDIOT1 天前
JSON-RPC 2.0 与 MCP 协议:从消息格式到进程通信 大模型MCP
rpc·大模型·json·agent·mcp
憧憬成为原神糕手1 天前
Playwright、Selenium、DrissionPage 与 JSON 接口怎么选?
数据库·selenium·json
SelectDB技术团队1 天前
Apache Doris 4.1:面向 AI & Search 的统一数据底座怎么选?向量检索 + 全文搜索 + 100MB JSON 完整能力拆解
人工智能·json·apache doris
进击切图仔1 天前
VS Code 调试 launch.json 解析
json
码智社2 天前
JSON 零基础到资深全体系教程
java·json