reverse_text_dataset_debug
收藏魔搭社区2025-12-05 更新2025-06-14 收录
下载链接:
https://modelscope.cn/datasets/PrimeIntellect/reverse_text_dataset_debug
下载链接
链接失效反馈官方服务:
资源简介:
```
"""
This is just an example of how to preprocess a dataset in the genesys/prime format.
"""
import argparse
import json
from pathlib import Path
from datasets import load_dataset
from huggingface_hub import upload_folder
if __name__ == "__main__":
args = argparse.ArgumentParser()
args.add_argument("--push_to_hub", type=bool, default=False)
args.add_argument("--hf_path", type=str, default="PrimeIntellect/reverse_text_dataset_debug")
args.add_argument("--output_path", type=str, default="example_dataset")
args = args.parse_args()
dataset = load_dataset("agentlans/wikipedia-paragraphs", split="train").map(
lambda x: {
"prompt": f"Reverse the given text.{x['text']}",
"verification_info": json.dumps({"ground_truth": x["text"][::-1]}),
"task_type": "reverse_text",
}
)
dataset.save_to_disk(args.output_path)
readme_path = Path(args.output_path) / "README.md"
with open(__file__, "r") as f:
script_content = f.read()
with open(readme_path, "w") as f:
f.write(f"```\n{script_content}\n```")
if args.push_to_hub:
upload_folder(repo_id=args.hf_path, folder_path=args.output_path, repo_type="dataset")
```
本示例用于演示如何以genesys/prime格式预处理数据集。
### 代码实现与功能说明
导入所需依赖库:argparse(命令行参数解析库)、json(JSON序列化工具)、pathlib.Path(路径处理工具)、datasets.load_dataset(数据集加载工具)以及huggingface_hub.upload_folder(Hugging Face Hub 上传工具)。
在主程序入口中,首先初始化命令行参数解析器,定义三个参数:
1. `--push_to_hub`:布尔类型参数,默认值为`False`,用于控制是否将处理后的数据集推送至Hugging Face Hub;
2. `--hf_path`:字符串类型参数,默认值为`PrimeIntellect/reverse_text_dataset_debug`,指定Hugging Face Hub上的目标数据集仓库ID;
3. `--output_path`:字符串类型参数,默认值为`example_dataset`,指定本地数据集的保存目录路径。随后完成参数解析。
加载`agentlans/wikipedia-paragraphs`数据集的训练拆分子集,并通过`map`方法对每个样本进行批量处理:为每个样本新增`prompt`字段,内容为提示文本"Reverse the given text."拼接原段落文本;新增`verification_info`字段,通过`json.dumps`序列化存储包含真实标签(原文本反转后的结果)的字典;同时新增`task_type`字段,值为`reverse_text`,用于标识该任务为文本反转任务。
将处理完成的数据集保存至本地指定目录,并在数据集保存目录下创建README.md文件,将当前运行脚本的完整内容以代码块形式写入该文件。
若`--push_to_hub`参数被设置为`True`,则将本地数据集目录上传至指定的Hugging Face Hub数据集仓库。
提供机构:
maas
创建时间:
2025-05-24



