|
| 1 | +"""Fetch Phonikud/phonikud-data knesset_nikud_v6 (5M lines, text<TAB>phonemes) |
| 2 | +to the rababa-datasets volume. |
| 3 | +
|
| 4 | +Source: https://huggingface.co/datasets/Phonikud/phonikud-data |
| 5 | +Labels were machine-generated by Dicta's diacritizer (~1k high-frequency |
| 6 | +words manually corrected per their changelog). We keep it as a WEAK |
| 7 | +pretraining corpus candidate only — never as a gold fine-tune stage |
| 8 | +(no-teacher-poison rule). The .7z original is kept alongside the |
| 9 | +extracted .txt for provenance. |
| 10 | +
|
| 11 | +Usage: |
| 12 | + modal run --detach fetch_phonikud.py |
| 13 | +""" |
| 14 | + |
| 15 | +from __future__ import annotations |
| 16 | + |
| 17 | +from pathlib import Path |
| 18 | + |
| 19 | +import modal |
| 20 | + |
| 21 | +datasets_volume = modal.Volume.from_name("rababa-datasets", create_if_missing=True) |
| 22 | + |
| 23 | +URL = "https://huggingface.co/datasets/Phonikud/phonikud-data/resolve/main/knesset_nikud_v6.txt.7z" |
| 24 | +DEST = Path("/datasets/hebrew-phonikud") |
| 25 | + |
| 26 | +image = modal.Image.debian_slim(python_version="3.11").pip_install( |
| 27 | + "requests", "py7zr>=0.21" |
| 28 | +) |
| 29 | + |
| 30 | +app = modal.App("rababa-fetch-phonikud", image=image) |
| 31 | + |
| 32 | + |
| 33 | +@app.function(timeout=45 * 60, volumes={"/datasets": datasets_volume}) |
| 34 | +def fetch() -> dict: |
| 35 | + import py7zr |
| 36 | + import requests |
| 37 | + |
| 38 | + DEST.mkdir(parents=True, exist_ok=True) |
| 39 | + archive = DEST / "knesset_nikud_v6.txt.7z" |
| 40 | + if not archive.exists(): |
| 41 | + print(f"[fetch] {URL}", flush=True) |
| 42 | + with requests.get(URL, stream=True, timeout=120) as r: |
| 43 | + r.raise_for_status() |
| 44 | + with open(archive, "wb") as f: |
| 45 | + for chunk in r.iter_content(chunk_size=1 << 20): |
| 46 | + f.write(chunk) |
| 47 | + print(f"[fetch] {archive.stat().st_size} bytes", flush=True) |
| 48 | + |
| 49 | + txt = DEST / "knesset_nikud_v6.txt" |
| 50 | + if not txt.exists(): |
| 51 | + print("[extract] ...", flush=True) |
| 52 | + with py7zr.SevenZipFile(archive, mode="r") as z: |
| 53 | + z.extractall(DEST) |
| 54 | + |
| 55 | + n = 0 |
| 56 | + sample: list[str] = [] |
| 57 | + with open(txt, encoding="utf-8") as f: |
| 58 | + for line in f: |
| 59 | + n += 1 |
| 60 | + if n <= 3: |
| 61 | + sample.append(line.rstrip("\n")) |
| 62 | + print(f"[inspect] {n} lines, {txt.stat().st_size} bytes", flush=True) |
| 63 | + for s in sample: |
| 64 | + print(f"[inspect] {s[:200]}", flush=True) |
| 65 | + |
| 66 | + datasets_volume.commit() |
| 67 | + return {"lines": n, "bytes": txt.stat().st_size, "sample": sample} |
| 68 | + |
| 69 | + |
| 70 | +@app.local_entrypoint() |
| 71 | +def main(): |
| 72 | + print(fetch.remote()) |
0 commit comments