Datasets:
File size: 7,174 Bytes
4f040da 52e8aa2 4f040da 52e8aa2 4f040da 52e8aa2 4f040da 52e8aa2 4f040da | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | #!/usr/bin/env python3
"""Audit pinned task datasets without assigning train/evaluation roles."""
from __future__ import annotations
import argparse
import csv
import hashlib
import json
import re
from pathlib import Path
import pyarrow.parquet as pq
def sha256(path: Path) -> str:
digest = hashlib.sha256()
with path.open("rb") as handle:
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
digest.update(chunk)
return digest.hexdigest()
def write_csv(path: Path, rows: list[dict[str, object]]) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
with path.open("w", newline="") as handle:
writer = csv.DictWriter(handle, fieldnames=list(rows[0]))
writer.writeheader()
writer.writerows(rows)
def audit_swe(path: Path, output: Path, revision: str) -> None:
table = pq.read_table(path, columns=["language", "repo", "base_commit", "license"])
data = table.to_pydict()
languages = sorted(set(data["language"]))
rows = []
for language in languages:
indices = [i for i, value in enumerate(data["language"]) if value == language]
rows.append(
{
"language": language,
"tasks": len(indices),
"unique_repositories": len({data["repo"][i] for i in indices}),
"unique_base_commits": len({data["base_commit"][i] for i in indices}),
"license_values": len({data["license"][i] for i in indices}),
"source_revision": revision,
"source_sha256": sha256(path),
}
)
rows.sort(key=lambda row: (-int(row["tasks"]), str(row["language"])))
write_csv(output, rows)
def audit_mceval_instruct(path: Path, output: Path, revision: str) -> None:
records = json.loads(path.read_text())
grouped: dict[str, list[dict[str, str]]] = {}
for record in records:
grouped.setdefault(record["language"].casefold(), []).append(record)
rows = []
for language, group in grouped.items():
rows.append(
{
"normalized_language": language,
"rows": len(group),
"unique_instructions": len({record["instruction"] for record in group}),
"unique_outputs": len({record["output"] for record in group}),
"output_utf8_bytes": sum(len(record["output"].encode()) for record in group),
"original_labels": ";".join(sorted({record["language"] for record in group})),
"source_revision": revision,
"source_sha256": sha256(path),
}
)
rows.sort(key=lambda row: (-int(row["rows"]), str(row["normalized_language"])))
write_csv(output, rows)
def audit_mceval_eval(root: Path, output: Path, revision: str) -> None:
grouped: dict[tuple[str, str], dict[str, object]] = {}
source_files = sorted(root.glob("generation/*.jsonl"))
source_files += sorted(root.glob("explanation/*.jsonl"))
source_files += sorted(root.glob("completion/*/*.jsonl"))
for path in source_files:
relative = path.relative_to(root)
surface = "/".join(relative.parts[:-1])
language = path.stem
group = grouped.setdefault(
(surface, language),
{"rows": 0, "base_ids": set(), "solutions": set(), "tests": set()},
)
with path.open() as handle:
for line in handle:
record = json.loads(line)
group["rows"] = int(group["rows"]) + 1
match = re.match(r"^([^/]+)/(\d+)", record["task_id"])
group["base_ids"].add(match.group(2) if match else record["task_id"])
group["solutions"].add(record.get("canonical_solution", ""))
group["tests"].add(record.get("test", ""))
tree_hash = hashlib.sha256()
for path in source_files:
tree_hash.update(str(path.relative_to(root)).encode())
tree_hash.update(bytes.fromhex(sha256(path)))
rows = []
for (surface, language), group in grouped.items():
rows.append(
{
"surface": surface,
"language": language,
"rows": group["rows"],
"unique_base_problem_ids": len(group["base_ids"]),
"unique_canonical_solutions": len(group["solutions"]),
"unique_tests": len(group["tests"]),
"source_revision": revision,
"audited_tree_sha256": tree_hash.hexdigest(),
}
)
rows.sort(key=lambda row: (str(row["surface"]), str(row["language"])))
write_csv(output, rows)
def audit_swe_leaderboard(root: Path, output: Path, revision: str) -> None:
"""Inventory every frozen leaderboard split without treating it as training data."""
source_files = sorted((root / "data").glob("*.parquet"))
if not source_files:
raise FileNotFoundError(f"no parquet files found under {root / 'data'}")
rows = []
for path in source_files:
table = pq.read_table(path, columns=["repo", "instance_id", "base_commit"])
data = table.to_pydict()
rows.append(
{
"split": path.stem.split("-00000", 1)[0],
"rows": table.num_rows,
"unique_instances": len(set(data["instance_id"])),
"unique_repositories": len(set(data["repo"])),
"unique_base_commits": len(set(data["base_commit"])),
"source_revision": revision,
"file_sha256": sha256(path),
}
)
write_csv(output, rows)
def main() -> None:
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest="source", required=True)
swe = subparsers.add_parser("swe-rebench-v2")
swe.add_argument("--input", type=Path, required=True)
swe.add_argument("--output", type=Path, required=True)
swe.add_argument("--revision", required=True)
mceval = subparsers.add_parser("mceval-instruct")
mceval.add_argument("--input", type=Path, required=True)
mceval.add_argument("--output", type=Path, required=True)
mceval.add_argument("--revision", required=True)
mceval_eval = subparsers.add_parser("mceval-eval")
mceval_eval.add_argument("--input", type=Path, required=True)
mceval_eval.add_argument("--output", type=Path, required=True)
mceval_eval.add_argument("--revision", required=True)
leaderboard = subparsers.add_parser("swe-rebench-leaderboard")
leaderboard.add_argument("--input", type=Path, required=True)
leaderboard.add_argument("--output", type=Path, required=True)
leaderboard.add_argument("--revision", required=True)
args = parser.parse_args()
if args.source == "swe-rebench-v2":
audit_swe(args.input, args.output, args.revision)
elif args.source == "mceval-instruct":
audit_mceval_instruct(args.input, args.output, args.revision)
elif args.source == "mceval-eval":
audit_mceval_eval(args.input, args.output, args.revision)
else:
audit_swe_leaderboard(args.input, args.output, args.revision)
if __name__ == "__main__":
main()
|