Datasets:
Download validate_dataset.py from Axilo67/openstem-qa: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/datasets/Axilo67/openstem-qa/resolve/main/validate_dataset.py
- Command line
-
hf download hf://datasets/Axilo67/openstem-qa/validate_dataset.py
-
curl -L -o validate_dataset.py https://huggingface.co/datasets/Axilo67/openstem-qa/resolve/main/validate_dataset.py
1.04 kB
| #!/usr/bin/env python3 | |
| import json, sys | |
| from pathlib import Path | |
| def check(path): | |
| rows=[json.loads(line) for line in Path(path).open(encoding="utf-8") if line.strip()] | |
| ids=set() | |
| for n,row in enumerate(rows,1): | |
| assert row["id"] not in ids, f"duplicate id at line {n}" | |
| ids.add(row["id"]) | |
| assert set(row["options"]) == {"A","B","C","D"}, f"bad options at line {n}" | |
| assert len(set(row["options"].values())) == 4, f"duplicate options at line {n}" | |
| assert row["correct_answer"] in "ABCD", f"bad answer label at line {n}" | |
| assert row["options"][row["correct_answer"]] == row["correct_answer_value"], f"answer mismatch at line {n}" | |
| assert set(row["option_explanations"]) == {"A","B","C","D"}, f"missing option explanation at line {n}" | |
| assert row["question"].strip() and row["solution"].strip(), f"empty question/solution at line {n}" | |
| print(f"{path}: {len(rows)} records passed structural checks") | |
| if __name__ == "__main__": | |
| for p in sys.argv[1:]: | |
| check(p) | |