Download scripts/sample.py from CyberNative-AI/so-arm-task-clock: direct link, hf CLI and curl.
- Browser
- Download file 1.33 kB
-
https://huggingface.co/datasets/CyberNative-AI/so-arm-task-clock/resolve/main/scripts/sample.py
- Command line
-
hf download hf://datasets/CyberNative-AI/so-arm-task-clock/scripts/sample.py
-
curl -L -o sample.py https://huggingface.co/datasets/CyberNative-AI/so-arm-task-clock/resolve/main/scripts/sample.py
1.33 kB
| """SO-arm datasets in the listing, and the per-author sample that was read. | |
| usage: sample.py OUT_DIR/datasets.jsonl OUT_DIR | |
| Replaces OUT_DIR/so_ids.txt (every SO-arm id, sorted) and OUT_DIR/sample_ids.txt (up to 3 per author, sorted). | |
| SO-arm rule: the case-insensitive pattern below matches anywhere in the full repository id (author namespace included) | |
| or in any tag. Sample: for each author in sorted order, that author's sorted ids are shuffled with one random.Random(SEED) | |
| and the first 3 kept.""" | |
| import collections, json, os, random, re, sys | |
| SO = re.compile(r"so[\W_]?10[01]|so[\W_]?arm|so[\W_]?follower", re.I) | |
| SEED = 20261118 | |
| rows = [json.loads(l) for l in open(sys.argv[1]) if l.strip()] | |
| ids = sorted({r["id"] for r in rows if r.get("id") and SO.search(" ".join([r["id"]] + (r.get("tags") or [])))}) | |
| by = collections.defaultdict(list) | |
| for i in ids: | |
| by[i.split("/")[0]].append(i) | |
| rng, sample = random.Random(SEED), [] | |
| for a in sorted(by): | |
| xs = sorted(by[a]); rng.shuffle(xs); sample += xs[:3] | |
| os.makedirs(sys.argv[2], exist_ok=True) | |
| for name, xs in (("so_ids.txt", ids), ("sample_ids.txt", sorted(sample))): | |
| with open(os.path.join(sys.argv[2], name), "w") as f: | |
| f.write("".join(x + "\n" for x in xs)) | |
| print(len(rows), "listed;", len(ids), "SO-arm from", len(by), "authors;", len(sample), "sampled") | |