Download make_oversampled.py from DevGwardo/minicpm5-toolcall-code: direct link, hf CLI and curl.
- Browser
- Download file 990 Bytes
-
https://huggingface.co/datasets/DevGwardo/minicpm5-toolcall-code/resolve/main/make_oversampled.py
- Command line
-
hf download hf://datasets/DevGwardo/minicpm5-toolcall-code/make_oversampled.py
-
curl -L -o make_oversampled.py https://huggingface.co/datasets/DevGwardo/minicpm5-toolcall-code/resolve/main/make_oversampled.py
990 Bytes
| """Build an abstention-heavy training file by repeating no-tool examples. | |
| The base run under-called abstention (0.71 vs the 0.90 gate), so v4 trains on | |
| every call example once and every abstention example three times. | |
| """ | |
| import json | |
| import random | |
| from pathlib import Path | |
| SRC = Path("data_native/train.jsonl") | |
| OUT = Path("data_native/train_neg3x.jsonl") | |
| REPEAT = 3 | |
| SEED = 21 | |
| def is_negative(row): | |
| last = row["messages"][-1] | |
| return last.get("role") == "assistant" and not last.get("tool_calls") | |
| rows = [json.loads(l) for l in SRC.read_text(encoding="utf-8").splitlines() if l.strip()] | |
| pos = [r for r in rows if not is_negative(r)] | |
| neg = [r for r in rows if is_negative(r)] | |
| out = pos + neg * REPEAT | |
| random.Random(SEED).shuffle(out) | |
| OUT.write_text("\n".join(json.dumps(r, ensure_ascii=False) for r in out) + "\n", encoding="utf-8") | |
| print(f"pos={len(pos)} neg={len(neg)} repeat={REPEAT} total={len(out)} -> {OUT}") | |
| print(f"abstention share={(len(neg) * REPEAT) / len(out):.1%}") | |