Exebench

简易教程

git lfs install # 确保你安装了git-lfs
git clone https://hf-mirror.com/datasets/jordiae/exebench
cd exebench
git lfs pull
for file in *.tar.gz; do
    tar -xvf "$file" -C ./  # 解压到当前目录
done
rm -rf ./*.gz
rm -rf .git/
sudo apt install zstd # 如果已经安装了可以忽略
find . -name "*.zst" -exec bash -c 'zstd -d "{}" -o "${0%.zst}"' {} \;
find . -name "*.zst" -exec rm {} \;

然后编写脚本文件,放在exebench文件夹中:

import os
import json

def create_directory_and_files(file_path):
    # 创建一个新文件夹,以 JSONL 文件名命名
    file_name = os.path.basename(file_path).replace(".jsonl", "")
    dir_name = os.path.join(os.path.dirname(file_path), file_name)
    os.makedirs(dir_name, exist_ok=True)
    
    # 打印正在处理的 JSONL 文件
    print(f"正在处理 JSONL 文件: {file_path}")
    
    with open(file_path, "r") as file:
        for idx, line in enumerate(file):
            # 解析 JSONL 数据
            data = json.loads(line)
            
            # 提取函数源码
            func_def = data.get("text", {}).get("func_def", "")
            func_head = data.get("text", {}).get("func_head", "")
            
            # 保存源码到 .c 文件
            if func_def:
                source_file = os.path.join(dir_name, f"function_{idx + 1}.c")
                with open(source_file, "w") as src_file:
                    src_file.write(func_def)
            
            # 提取输入和输出,确保 io_pairs 存在且可迭代
            io_pairs = data.get("text", {}).get("angha_io_pairs", [])
            if not isinstance(io_pairs, list):
                io_pairs = []  # 如果为空或不可迭代,则使用空列表
            
            inputs = [pair.get("input") for pair in io_pairs]
            outputs = [pair.get("output") for pair in io_pairs]
            
            # 保存输入数据到 inputs.json
            input_file = os.path.join(dir_name, f"inputs_{idx + 1}.json")
            with open(input_file, "w") as inp_file:
                json.dump(inputs, inp_file, indent=4)
            
            # 保存输出数据到 outputs.json
            output_file = os.path.join(dir_name, f"outputs_{idx + 1}.json")
            with open(output_file, "w") as out_file:
                json.dump(outputs, out_file, indent=4)


def process_jsonl_files(root_dir):
    # 遍历所有子文件夹和文件
    for root, _, files in os.walk(root_dir):
        for file in files:
            if file.endswith(".jsonl"):
                jsonl_file_path = os.path.join(root, file)
                create_directory_and_files(jsonl_file_path)

# 设置目标目录
root_dir = "./"  # 替换为你的 JSONL 文件所在文件夹的根目录

# 执行处理
process_jsonl_files(root_dir)

print("处理完成,所有数据已保存到对应文件夹。")

然后可以find . -name "*.jsonl" -exec rm {} \;删掉原来的jsonl文件

下载到本地:tar --use-compress-program=zstd -cf - . | split -b 10G - dataset.tar.zst.part
-program=zstd -cf - . | split -b 10G - dataset.tar.zst.part`