Datasets:
Tasks:
Text Generation
Languages:
English
Size:
n<1K
Tags:
code
notebooks
training-scripts
dataset:Nanthasit/sakthai-kaggle-notebooks
license-mit
dataset-card
License:
Upload scripts/create-balanced-benchmark.py with huggingface_hub
Browse files
scripts/create-balanced-benchmark.py
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Create a balanced BFCL-style benchmark from ALL cycle data.
|
| 4 |
+
Different from all previous work: this is a PROPER EVAL BENCHMARK (not training data).
|
| 5 |
+
Balanced across simple/parallel/irrelevance categories, in exact bench-v2 format.
|
| 6 |
+
"""
|
| 7 |
+
import json, glob, random, collections
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
from huggingface_hub import HfApi
|
| 10 |
+
|
| 11 |
+
random.seed(42)
|
| 12 |
+
TARGET_PER_CAT = 50 # 50 per category = 200 total
|
| 13 |
+
|
| 14 |
+
# Load all cycle data
|
| 15 |
+
all_examples = []
|
| 16 |
+
for d in ["cycle-100-output","cycle-100-v2","cycle-100-v3","cycle-100-v4",
|
| 17 |
+
"cycle-100-v5","cycle-100-v6","cycle-100-v7","cycle-100-v8",
|
| 18 |
+
"cycle-100-v9","cycle-100-v10","gap-filled","benchmark-targeted",
|
| 19 |
+
"augmented-output","safety-quality-fixes"]:
|
| 20 |
+
for f in sorted(glob.glob(f"{d}/*.jsonl")):
|
| 21 |
+
if "all-" in f or "push-" in f: continue
|
| 22 |
+
with open(f, encoding="utf-8") as fh:
|
| 23 |
+
try:
|
| 24 |
+
for line in fh:
|
| 25 |
+
line = line.strip()
|
| 26 |
+
if not line: continue
|
| 27 |
+
all_examples.append(json.loads(line))
|
| 28 |
+
except:
|
| 29 |
+
pass
|
| 30 |
+
|
| 31 |
+
print(f"Total loaded: {len(all_examples)}")
|
| 32 |
+
|
| 33 |
+
# Classify and categorize
|
| 34 |
+
by_cat = {"simple": [], "parallel": [], "irrelevance_tools": [], "irrelevance_no_tools": []}
|
| 35 |
+
|
| 36 |
+
for ex in all_examples:
|
| 37 |
+
msgs = ex.get("messages", [])
|
| 38 |
+
tools = ex.get("tools", [])
|
| 39 |
+
|
| 40 |
+
for i, m in enumerate(msgs):
|
| 41 |
+
if m.get("role") == "assistant":
|
| 42 |
+
gold_calls = []
|
| 43 |
+
for tc_raw in (m.get("tool_calls") or []):
|
| 44 |
+
if isinstance(tc_raw, str):
|
| 45 |
+
try: tc_raw = json.loads(tc_raw)
|
| 46 |
+
except: continue
|
| 47 |
+
if not isinstance(tc_raw, dict): continue
|
| 48 |
+
fn = tc_raw.get("function", {})
|
| 49 |
+
if isinstance(fn, str):
|
| 50 |
+
try: fn = json.loads(fn)
|
| 51 |
+
except: fn = {}
|
| 52 |
+
if not isinstance(fn, dict): continue
|
| 53 |
+
name = fn.get("name", "")
|
| 54 |
+
args = fn.get("arguments", "{}")
|
| 55 |
+
if isinstance(args, str):
|
| 56 |
+
try: args = json.loads(args)
|
| 57 |
+
except: args = {}
|
| 58 |
+
gold_calls.append({"name": name, "arguments": args})
|
| 59 |
+
|
| 60 |
+
nc = len(gold_calls)
|
| 61 |
+
if nc == 0 and tools: cat = "irrelevance_tools"
|
| 62 |
+
elif nc == 0 and not tools: cat = "irrelevance_no_tools"
|
| 63 |
+
elif nc == 1: cat = "simple"
|
| 64 |
+
else: cat = "parallel"
|
| 65 |
+
|
| 66 |
+
row = {
|
| 67 |
+
"messages": msgs[:i+1],
|
| 68 |
+
"tools": tools,
|
| 69 |
+
"gold_calls": gold_calls,
|
| 70 |
+
"category": cat,
|
| 71 |
+
"held_out_tool": False,
|
| 72 |
+
"multi_turn": any(m2.get("role") == "tool" for m2 in msgs[:i]),
|
| 73 |
+
"in_v1": False,
|
| 74 |
+
}
|
| 75 |
+
by_cat[cat].append(row)
|
| 76 |
+
break
|
| 77 |
+
|
| 78 |
+
for cat, rows in by_cat.items():
|
| 79 |
+
print(f" {cat:25s}: {len(rows)} available")
|
| 80 |
+
|
| 81 |
+
# Sample balanced set
|
| 82 |
+
bench_rows = []
|
| 83 |
+
for cat in ["simple", "parallel", "irrelevance_tools", "irrelevance_no_tools"]:
|
| 84 |
+
pool = by_cat.get(cat, [])
|
| 85 |
+
random.shuffle(pool)
|
| 86 |
+
selected = pool[:min(TARGET_PER_CAT, len(pool))]
|
| 87 |
+
bench_rows.extend(selected)
|
| 88 |
+
print(f" Sampled {cat}: {len(selected)}")
|
| 89 |
+
|
| 90 |
+
random.shuffle(bench_rows)
|
| 91 |
+
print(f"\nTotal benchmark rows: {len(bench_rows)}")
|
| 92 |
+
|
| 93 |
+
# Write output
|
| 94 |
+
OUT = Path("sakthai-cycle-bench")
|
| 95 |
+
OUT.mkdir(exist_ok=True)
|
| 96 |
+
|
| 97 |
+
bench_path = OUT / "data/test.jsonl"
|
| 98 |
+
with open(bench_path, "w", encoding="utf-8") as f:
|
| 99 |
+
for row in bench_rows:
|
| 100 |
+
f.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 101 |
+
|
| 102 |
+
# Summary
|
| 103 |
+
summary_path = OUT / "summary.json"
|
| 104 |
+
cats = collections.Counter(r["category"] for r in bench_rows)
|
| 105 |
+
with open(summary_path, "w") as f:
|
| 106 |
+
json.dump({"total": len(bench_rows), "categories": dict(cats),
|
| 107 |
+
"multi_turn": sum(1 for r in bench_rows if r["multi_turn"])}, f, indent=2)
|
| 108 |
+
|
| 109 |
+
# Push to HF Hub
|
| 110 |
+
api = HfApi()
|
| 111 |
+
repo = "Nanthasit/sakthai-cycle-bench"
|
| 112 |
+
api.create_repo(repo_id=repo, repo_type="dataset", exist_ok=True)
|
| 113 |
+
|
| 114 |
+
api.upload_file(path_or_fileobj=str(bench_path), path_in_repo="data/test.jsonl",
|
| 115 |
+
repo_id=repo, repo_type="dataset")
|
| 116 |
+
api.upload_file(path_or_fileobj=str(summary_path), path_in_repo="summary.json",
|
| 117 |
+
repo_id=repo, repo_type="dataset")
|
| 118 |
+
|
| 119 |
+
readme = f"""---
|
| 120 |
+
license: apache-2.0
|
| 121 |
+
tags: [sakthai, benchmark, tool-calling, function-calling]
|
| 122 |
+
---
|
| 123 |
+
# SakThai Cycle Benchmark
|
| 124 |
+
|
| 125 |
+
**{len(bench_rows)} balanced BFCL-style benchmark rows** derived from 10 cycle rounds.
|
| 126 |
+
|
| 127 |
+
| Category | Count |
|
| 128 |
+
|---|---|
|
| 129 |
+
| simple | {cats.get('simple',0)} |
|
| 130 |
+
| parallel | {cats.get('parallel',0)} |
|
| 131 |
+
| irrelevance_tools | {cats.get('irrelevance_tools',0)} |
|
| 132 |
+
| irrelevance_no_tools | {cats.get('irrelevance_no_tools',0)} |
|
| 133 |
+
| **Total** | **{len(bench_rows)}** |
|
| 134 |
+
|
| 135 |
+
Multi-turn: {sum(1 for r in bench_rows if r['multi_turn'])} rows
|
| 136 |
+
|
| 137 |
+
Use with eval_bench.py:
|
| 138 |
+
```
|
| 139 |
+
SAK_MODELS=Nanthasit/sakthai-context-1.5b-merged \\
|
| 140 |
+
SAK_BENCH=Nanthasit/sakthai-cycle-bench \\
|
| 141 |
+
uv run python eval_bench.py
|
| 142 |
+
```
|
| 143 |
+
"""
|
| 144 |
+
api.upload_file(path_or_fileobj=readme.encode(), path_in_repo="README.md",
|
| 145 |
+
repo_id=repo, repo_type="dataset")
|
| 146 |
+
|
| 147 |
+
print(f"\nPushed: https://huggingface.co/datasets/{repo}")
|
| 148 |
+
print(f"Run: SAK_MODELS=model_id SAK_BENCH={repo} uv run python eval_bench.py")
|