minicpm5-toolcall-code / make_oversampled.py
DevGwardo's picture
v4: oversampled abstention + metric fix
17b0632 verified
Raw History Blame Contribute Delete
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%}")