Datasets:
File size: 4,201 Bytes
8a9c862 | 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 | from __future__ import annotations
import argparse
import collections
import concurrent.futures
import hashlib
import json
import shutil
import subprocess
from pathlib import Path
from sedweave.execution import run_sed
def sed_version() -> str:
executable = shutil.which("sed")
if executable is None:
return "sed unavailable"
result = subprocess.run([executable, "--version"], capture_output=True, text=True, check=False)
output = (result.stdout or result.stderr).strip().splitlines()
if result.returncode == 0 and output:
return output[0]
return "unknown sed"
def validate_row(row: dict) -> tuple[str, str | None]:
try:
if run_sed(row["command"], row["input_text"]) != row["expected_output"]:
return row["id"], "primary output mismatch"
if run_sed(row["command"], row["validation_input"]) != row["validation_output"]:
return row["id"], "validation output mismatch"
return row["id"], None
except Exception as error:
return row["id"], str(error)[:500]
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("data", type=Path)
parser.add_argument("--workers", type=int, default=8)
parser.add_argument("--output", type=Path)
args = parser.parse_args()
rows = [json.loads(line) for line in args.data.open(encoding="utf-8")]
ids = [row["id"] for row in rows]
if len(ids) != len(set(ids)):
raise ValueError("Duplicate row IDs")
by_id = {row["id"]: row for row in rows}
for row in rows:
if row.get("paraphrase_of"):
original = by_id.get(row["paraphrase_of"])
if original is None:
raise ValueError(f"Missing paraphrase source: {row['id']}")
for key in ("command", "input_text", "expected_output", "validation_input", "validation_output", "split"):
if row[key] != original[key]:
raise ValueError(f"Paraphrase changed {key}: {row['id']}")
if row["split"] != "train":
raise ValueError(f"Paraphrase outside train split: {row['id']}")
errors = []
with concurrent.futures.ProcessPoolExecutor(max_workers=args.workers) as executor:
for completed, (row_id, error) in enumerate(executor.map(validate_row, rows, chunksize=20), 1):
if error:
errors.append({"id": row_id, "error": error})
if completed % 5000 == 0:
print(f"validated {completed}/{len(rows)}", flush=True)
split_integrity = {}
for left, right in (
("train", "validation"), ("train", "test"), ("validation", "test"),
("train", "challenge"), ("validation", "challenge"), ("test", "challenge"),
):
left_rows = [row for row in rows if row["split"] == left and not row.get("paraphrase_of")]
right_rows = [row for row in rows if row["split"] == right and not row.get("paraphrase_of")]
split_integrity[f"{left}-{right}"] = {
"input_overlap": len({row["input_text"] for row in left_rows} & {row["input_text"] for row in right_rows}),
"request_command_overlap": len(
{(row["request"], row["command"]) for row in left_rows}
& {(row["request"], row["command"]) for row in right_rows}
),
}
summary = {
"data": str(args.data),
"sha256": hashlib.sha256(args.data.read_bytes()).hexdigest(),
"rows": len(rows),
"executions": len(rows) * 2,
"sed_version": sed_version(),
"errors": errors,
"splits": dict(collections.Counter(row["split"] for row in rows)),
"sources": dict(collections.Counter(row["source"] for row in rows)),
"families": dict(collections.Counter(row["family"] for row in rows)),
"unique_requests": len({row["request"] for row in rows}),
"unique_commands": len({row["command"] for row in rows}),
"split_integrity": split_integrity,
}
text = json.dumps(summary, indent=2)
if args.output:
args.output.write_text(text, encoding="utf-8")
print(text)
if errors:
raise SystemExit(1)
if __name__ == "__main__":
main()
|