Datasets:
Tasks:
Text Generation
Languages:
English
Size:
n<1K
Tags:
code
notebooks
training-scripts
dataset:Nanthasit/sakthai-kaggle-notebooks
license-mit
dataset-card
License:
Download validate_exp.py from Nanthasit/sakthai-kaggle-notebooks: direct link, hf CLI and curl.
- Browser
- Download file 3.81 kB
-
https://huggingface.co/datasets/Nanthasit/sakthai-kaggle-notebooks/resolve/main/validate_exp.py
- Command line
-
hf download hf://datasets/Nanthasit/sakthai-kaggle-notebooks/validate_exp.py
-
curl -L -o validate_exp.py https://huggingface.co/datasets/Nanthasit/sakthai-kaggle-notebooks/resolve/main/validate_exp.py
3.81 kB
| """Validate the prompt/completion explode locally, before any paid run. | |
| Checks: | |
| 1. explode produces the predicted row count and respects the turn cap | |
| 2. every prompt ends with the assistant generation marker and every completion | |
| is non-empty and terminated (otherwise the mask trains on nothing useful) | |
| 3. oracle: parsing each completion recovers exactly that turn's gold tool calls | |
| 4. no bench row and no held-out tool schema survives into training | |
| """ | |
| import json, re, random, hashlib, pathlib, collections, sys | |
| random.seed(20260729) | |
| src = pathlib.Path("job-0.5b-exp.py").read_text() | |
| ns = {"json": json, "hashlib": __import__("hashlib")} | |
| exec(compile(src[src.index("def _text(c):"):src.index("# ── Data: explode")], "pure", "exec"), ns) | |
| render_chatml, _assistant_body, fingerprint = ns["render_chatml"], ns["_assistant_body"], ns["fingerprint"] | |
| _TC = re.compile(r"<tool_call>\s*(\{.*?\})\s*</tool_call>", re.DOTALL) | |
| MAX_TURNS = 4 | |
| def names(text): | |
| o = [] | |
| for m in _TC.findall(text): | |
| try: o.append(json.loads(m).get("name")) | |
| except Exception: pass | |
| return [n for n in o if n] | |
| def gold_of(msg): | |
| o = [(tc.get("function") or {}).get("name") for tc in (msg.get("tool_calls") or [])] | |
| o = [n for n in o if n] | |
| if not o: | |
| o = names(msg.get("content") or "") | |
| return o | |
| train = [json.loads(l) for l in open("v7/data/train.jsonl") if l.strip()] | |
| meta = json.load(open("bench/train_exclude_fingerprints.json")) | |
| EXCLUDE, HELD = set(meta["fingerprints"]), set(meta["held_out_tools"]) | |
| bench_fps = {json.loads(l)["fingerprint"] for l in open("bench/data/test.jsonl") if l.strip()} | |
| def keep(ex): | |
| if fingerprint(ex["messages"]) in EXCLUDE: return False | |
| n = {(t.get("function") or {}).get("name") or t.get("name") for t in (ex.get("tools") or [])} | |
| return not (n & HELD) | |
| kept = [e for e in train if keep(e)] | |
| fail = 0 | |
| pairs, over_cap = [], 0 | |
| for ex in kept: | |
| msgs, tools = ex["messages"], (ex.get("tools") or None) | |
| idxs = [i for i, m in enumerate(msgs) if m.get("role") == "assistant"] | |
| if len(idxs) > MAX_TURNS: | |
| idxs = sorted(random.sample(idxs, MAX_TURNS)); over_cap += 1 | |
| for i in idxs: | |
| c = _assistant_body(msgs[i]) | |
| if not c.strip(): continue | |
| g = gold_of(msgs[i]) | |
| row = (render_chatml(msgs[:i], tools, add_generation_prompt=True), c + "<|im_end|>", g) | |
| pairs.extend([row] * (3 if len(g) > 1 else 1)) # PARALLEL_OVERSAMPLE | |
| print(f"1. explode: {len(kept)} conversations -> {len(pairs)} pairs " | |
| f"({over_cap} conversations hit the {MAX_TURNS}-turn cap)") | |
| bad_prompt = sum(1 for p, _, _ in pairs if not p.endswith("<|im_start|>assistant\n")) | |
| bad_comp = sum(1 for _, c, _ in pairs if not c.endswith("<|im_end|>") or len(c) < 12) | |
| print(f"2. shape: {bad_prompt} prompts missing the generation marker, " | |
| f"{bad_comp} completions empty or unterminated") | |
| fail += bad_prompt + bad_comp | |
| mismatch = sum(1 for _, c, g in pairs if names(c) != g) | |
| print(f"3. oracle: {mismatch} completions whose parsed calls differ from gold") | |
| fail += mismatch | |
| leak = sum(1 for e in kept if fingerprint(e["messages"]) in bench_fps) | |
| tool_leak = sum(1 for e in kept | |
| if {(t.get("function") or {}).get("name") or t.get("name") | |
| for t in (e.get("tools") or [])} & HELD) | |
| print(f"4. leakage: {leak} bench rows, {tool_leak} held-out tool schemas") | |
| fail += leak + tool_leak | |
| cats = collections.Counter("irrelevance" if not g else ("simple" if len(g) == 1 else "parallel") | |
| for _, _, g in pairs) | |
| tot = sum(cats.values()) | |
| print(f"5. category mix of training turns: " + | |
| " ".join(f"{k} {v} ({100*v/tot:.0f}%)" for k, v in cats.most_common())) | |
| print("\nRESULT:", "PASS" if fail == 0 else f"FAIL ({fail} problems)") | |
| sys.exit(1 if fail else 0) | |