Spaces:
Runtime error
Runtime error
Download ml/tokenizer/download_data.py from TheAbyss99/abyss-api: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/spaces/TheAbyss99/abyss-api/resolve/main/ml/tokenizer/download_data.py
- Command line
-
hf download hf://spaces/TheAbyss99/abyss-api/ml/tokenizer/download_data.py
-
curl -L -o download_data.py https://huggingface.co/spaces/TheAbyss99/abyss-api/resolve/main/ml/tokenizer/download_data.py
1.27 kB
| """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") |