Download example.py from EasyOctopus/german-dictation-punctuation-data: direct link, hf CLI and curl.
- Browser
- Download file 1.87 kB
-
https://huggingface.co/datasets/EasyOctopus/german-dictation-punctuation-data/resolve/main/example.py
- Command line
-
hf download hf://datasets/EasyOctopus/german-dictation-punctuation-data/example.py
-
curl -L -o example.py https://huggingface.co/datasets/EasyOctopus/german-dictation-punctuation-data/resolve/main/example.py
1.87 kB
| #!/usr/bin/env -S uv run --script | |
| # /// script | |
| # requires-python = ">=3.11" | |
| # dependencies = [] | |
| # /// | |
| """Inspect one fictional row and validate every local split without network access.""" | |
| import argparse | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| HERE=Path(__file__).absolute().parent | |
| def main(): | |
| parser=argparse.ArgumentParser() | |
| parser.add_argument("--self-test",action="store_true") | |
| args=parser.parse_args() | |
| meta=json.loads((HERE/"provenance.json").read_text()) | |
| texts=set() | |
| families=set() | |
| for split,counts in meta["splits"].items(): | |
| path=HERE/"data"/(split+".jsonl") | |
| assert hashlib.sha256(path.read_bytes()).hexdigest()==counts["sha256"] | |
| rows=[json.loads(line) for line in path.read_text().splitlines()] | |
| if not args.self_test: | |
| print(json.dumps(rows[0],indent=2,ensure_ascii=False)) | |
| return | |
| assert len(rows)==counts["rows"] | |
| current={r["scenario"] for r in rows} | |
| assert not families & current | |
| families.update(current) | |
| for r in rows: | |
| key=" ".join(r["text"].casefold().split()) | |
| assert key not in texts | |
| texts.add(key) | |
| if meta["task"]=="pii": | |
| end=0 | |
| for s in r["gold"]: | |
| assert end<=s["start"]<s["end"]<=len(r["text"]) and s["label"] | |
| end=s["end"] | |
| else: | |
| words=r["text"].split() | |
| for s in r["gold"]: | |
| words[s["index"]]+=s["mark"] | |
| assert " ".join(words)==r["reference"] | |
| if "replay" in meta: | |
| assert hashlib.sha256((HERE/"replay/replay.jsonl").read_bytes()).hexdigest()==meta["replay"]["sha256"] | |
| print(f"Verified {len(texts)} distinct messages in {len(families)} disjoint scenario families.") | |
| if __name__=="__main__": | |
| main() | |