Download code/baselines.py from jncarlo/tinymix: direct link, hf CLI and curl.
- Browser
- Download file 2.25 kB
-
https://huggingface.co/datasets/jncarlo/tinymix/resolve/main/code/baselines.py
- Command line
-
hf download hf://datasets/jncarlo/tinymix/code/baselines.py
-
curl -L -o baselines.py https://huggingface.co/datasets/jncarlo/tinymix/resolve/main/code/baselines.py
2.25 kB
| """Single-source baselines of the same size, for comparison with the mix. | |
| python baselines.py 10M -> out/base_tinystories_10M, out/base_fineweb_edu_10M | |
| Light cleaning only (ftfy + whitespace), no mix, no complexity or dedup filters: | |
| this is what someone would get by just taking the dataset. | |
| """ | |
| import os | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parent.parent | |
| _env = ROOT / ".env" | |
| if _env.exists(): | |
| for _l in _env.read_text(encoding="utf-8").splitlines(): | |
| if "=" in _l and not _l.lstrip().startswith("#"): | |
| _k, _v = _l.split("=", 1) | |
| os.environ.setdefault(_k.strip(), _v.strip().strip("'\"")) | |
| import ftfy | |
| from datasets import load_dataset | |
| from huggingface_hub import HfFileSystem | |
| EOT = "<|endoftext|>" | |
| def tinystories(): | |
| buf = [] | |
| with HfFileSystem().open("datasets/roneneldan/TinyStories/TinyStoriesV2-GPT4-train.txt", "r", | |
| encoding="utf-8", errors="replace") as f: | |
| for line in f: | |
| if EOT in line: | |
| if buf: | |
| yield " ".join(buf) | |
| buf = [] | |
| else: | |
| buf.append(line.strip()) | |
| def fineweb_edu(): | |
| for r in load_dataset("HuggingFaceFW/fineweb-edu", "sample-10BT", split="train", streaming=True): | |
| if r["int_score"] >= 4: | |
| yield r["text"] | |
| SOURCES = {"tinystories": tinystories, "fineweb_edu": fineweb_edu} | |
| def main(): | |
| size = sys.argv[1] | |
| target = {"10M": 10e6, "100M": 100e6}[size] | |
| for name, gen in SOURCES.items(): | |
| if len(sys.argv) > 2 and name not in sys.argv[2:]: | |
| continue | |
| out = ROOT / "out" / f"base_{name}_{size}" | |
| out.mkdir(parents=True, exist_ok=True) | |
| words, n = 0, 0 | |
| with (out / "train.txt").open("w", encoding="utf-8") as f: | |
| for text in gen(): | |
| text = ftfy.fix_text(text).strip() | |
| if not text: | |
| continue | |
| f.write(text + f"\n{EOT}\n") | |
| words += len(text.split()) | |
| n += 1 | |
| if words >= target: | |
| break | |
| print(f"{name} {size}: {words/1e6:.2f}M words, {n} docs", flush=True) | |
| if __name__ == "__main__": | |
| main() | |