Datasets:
Download scripts/make_data.py from Lottolabs/LFM3-1.7B-SelfDistill-63M: direct link, hf CLI and curl.
- Browser
- Download file 2.1 kB
-
https://huggingface.co/datasets/Lottolabs/LFM3-1.7B-SelfDistill-63M/resolve/main/scripts/make_data.py
- Command line
-
hf download hf://datasets/Lottolabs/LFM3-1.7B-SelfDistill-63M/scripts/make_data.py
-
curl -L -o make_data.py https://huggingface.co/datasets/Lottolabs/LFM3-1.7B-SelfDistill-63M/resolve/main/scripts/make_data.py
2.1 kB
| #!/usr/bin/env python3 | |
| """gen_*.jsonl -> data/train.npz, data/eval.npz, data/draft_vocab.json (+ coverage stats in data/vocab_stats.json). | |
| Draft vocabulary: the V most frequent tokens of the training outputs (the served model's own output; prompt tokens | |
| excluded); ids sorted ascending.""" | |
| import argparse | |
| import json | |
| from collections import Counter | |
| from pathlib import Path | |
| import numpy as np | |
| from data import pack | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--vocab_size", type=int, default=32768) | |
| ap.add_argument("--train", default="data/gen_train.snap.jsonl", help="a complete-lines copy of gen_train.jsonl") | |
| ap.add_argument("--keep_vocab", action="store_true", help="repack only; keep data/draft_vocab.json") | |
| a = ap.parse_args() | |
| D = Path(__file__).parent / "data" | |
| n, t = pack([a.train], D / "train.npz") | |
| print("train records", n, "tokens", t) | |
| n, t = pack([D / "gen_eval.jsonl"], D / "eval.npz") | |
| print("eval records", n, "tokens", t) | |
| cnt = Counter() | |
| dom_cnt = {} | |
| for line in open(a.train): | |
| r = json.loads(line) | |
| cnt.update(r["out_ids"]) | |
| dom_cnt.setdefault(r["domain"], Counter()).update(r["out_ids"]) | |
| if a.keep_vocab: | |
| ids = json.load(open(D / "draft_vocab.json")) | |
| else: | |
| ids = sorted(i for i, _ in cnt.most_common(a.vocab_size)) | |
| json.dump(ids, open(D / "draft_vocab.json", "w")) | |
| S = set(ids) | |
| stats = {"vocab": len(ids), "distinct_output_tokens": len(cnt)} | |
| ecnt = {} | |
| for line in open(D / "gen_eval.jsonl"): | |
| r = json.loads(line) | |
| ecnt.setdefault(r["domain"], Counter()).update(r["out_ids"]) | |
| for name, c in list(dom_cnt.items()) + [("all", cnt)]: | |
| tot = sum(c.values()) | |
| stats[f"train_cov_{name}"] = sum(v for k, v in c.items() if k in S) / tot | |
| for name, c in ecnt.items(): | |
| tot = sum(c.values()) | |
| stats[f"eval_cov_{name}"] = sum(v for k, v in c.items() if k in S) / tot | |
| for V in (8192, 16384, 32768, 65536): | |
| top = set(i for i, _ in cnt.most_common(V)) | |
| stats[f"train_cov_top{V}"] = sum(v for k, v in cnt.items() if k in top) / sum(cnt.values()) | |
| json.dump(stats, open(D / "vocab_stats.json", "w"), indent=1) | |
| print(json.dumps(stats, indent=1)) | |