"""Download TinyStories text into ml/data/tinystories/. Run from the project root: python -m ml.tokenizer.download_data """ import os import urllib.request BASE = "https://huggingface.co/datasets/roneneldan/TinyStories/resolve/main" FILES = [ "TinyStoriesV2-GPT4-valid.txt", "TinyStoriesV2-GPT4-train.txt", ] OUT_DIR = os.path.join("ml", "data", "tinystories") def download(name): os.makedirs(OUT_DIR, exist_ok=True) dest = os.path.join(OUT_DIR, name) if os.path.exists(dest): print(f"{name}: already present, skipping") return url = f"{BASE}/{name}" print(f"{name}: downloading...") req = urllib.request.Request(url, headers={"User-Agent": "abyss/0.1"}) with urllib.request.urlopen(req) as r, open(dest, "wb") as f: total = int(r.headers.get("Context-Length", 0)) done = 0 while True: chunk = r.read(1 << 20) if not chunk: break f.write(chunk) done += len(chunk) if total: print(f"\r {done/1e6:8.1f} / {total/1e6:.1f} MB", end="") print(f"\n{name}: saved to {dest}") if __name__ == "__main__": for f in FILES: download(f) print("done")