Datasets:
Tasks:
Token Classification
Modalities:
Text
Formats:
json
Languages:
Thai
Size:
10K - 100K
ArXiv:
License:
Download fetch_sources.py from iapp/OpenThai2.0-WordSeg-Benchmark: direct link, hf CLI and curl.
- Browser
- Download file 2.56 kB
-
https://huggingface.co/datasets/iapp/OpenThai2.0-WordSeg-Benchmark/resolve/main/fetch_sources.py
- Command line
-
hf download hf://datasets/iapp/OpenThai2.0-WordSeg-Benchmark/fetch_sources.py
-
curl -L -o fetch_sources.py https://huggingface.co/datasets/iapp/OpenThai2.0-WordSeg-Benchmark/resolve/main/fetch_sources.py
2.56 kB
| """Download the original files of every test set (sources.json) into raw/ and verify their SHA-256. | |
| python fetch_sources.py # everything (about 830 MB, most of it khammoon's training text) | |
| python fetch_sources.py --no-khmdd # without khammoon's training text: every set except khmdd | |
| Files already present with the right SHA-256 are not downloaded again. Standard library only. `fetch(raw, sets)` | |
| downloads only the files of the given test sets (benchmark.py uses it on its first run). | |
| """ | |
| import argparse | |
| import hashlib | |
| import json | |
| import sys | |
| import urllib.request | |
| from pathlib import Path | |
| HERE = Path(__file__).resolve().parent | |
| def sha256(path: Path) -> str: | |
| h = hashlib.sha256() | |
| with path.open("rb") as f: | |
| for chunk in iter(lambda: f.read(1 << 20), b""): | |
| h.update(chunk) | |
| return h.hexdigest() | |
| def fetch(raw: Path, sets: set[str] | None = None, skip_khmdd: bool = False, quiet: bool = False) -> list[str]: | |
| """Download the original files (of the given test sets, or all) into raw/; return the files whose SHA-256 differs.""" | |
| files = json.loads((HERE / "sources.json").read_text())["files"] | |
| bad = [] | |
| for rel, info in files.items(): | |
| if sets is not None and not set(info["sets"]) & sets: | |
| continue | |
| if skip_khmdd and info["sets"] == ["khmdd"]: | |
| continue | |
| dest = raw / rel | |
| if dest.exists() and sha256(dest) == info["sha256"]: | |
| if not quiet: | |
| print(f"ok {rel}") | |
| continue | |
| dest.parent.mkdir(parents=True, exist_ok=True) | |
| print(f"fetch {rel} ({info['licence']})", flush=True) | |
| req = urllib.request.Request(info["url"], headers={"User-Agent": "thai-ws-bench"}) | |
| with urllib.request.urlopen(req) as r, dest.open("wb") as f: | |
| while chunk := r.read(1 << 20): | |
| f.write(chunk) | |
| if sha256(dest) != info["sha256"]: | |
| bad.append(rel) | |
| print(f"WRONG SHA-256: {rel} (the upstream file changed?)") | |
| return bad | |
| def main() -> None: | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--raw", type=Path, default=HERE / "raw") | |
| ap.add_argument("--no-khmdd", action="store_true", help="skip khammoon's training text (only needed for khmdd)") | |
| args = ap.parse_args() | |
| bad = fetch(args.raw, skip_khmdd=args.no_khmdd) | |
| if bad: | |
| sys.exit(f"{len(bad)} file(s) differ from the versions the benchmark was built from: {bad}") | |
| print("all sources present and verified") | |
| if __name__ == "__main__": | |
| main() | |