Skip to content

Automation foundation model for tiny devices: 2-bit, 8-29 MB, tool calls, ASR, structured extraction and embeddings on phones, wearables, smart homes, robots, cars and microcontrollers.

trim tools

HenryNdubuakuab9da91f4148
diff --git a/scripts/synthesize_tools_data.py b/scripts/synthesize_tools_data.py
index 97974fa..78caaaa 100644
--- a/scripts/synthesize_tools_data.py
+++ b/scripts/synthesize_tools_data.py
@@ -52,7 +52,7 @@ e-commerce, finance, healthcare, travel, IoT, social media, education, DevOps, l
HR, and more. Do NOT default to simple personal-assistant tasks.
Rules:
-1. Invent 1-5 tools as JSON. Each tool MUST have: name, description, parameters \
+1. Invent 0-3 tools as JSON. Each tool MUST have: name, description, parameters \
(dict of param_name -> {type, description, required}). Use realistic parameter types \
including string, number, boolean, array, object. Include nested objects or arrays \
where appropriate.
diff --git a/src/data.py b/src/data.py
index 402cc97..b9aa2fe 100644
--- a/src/data.py
+++ b/src/data.py
@@ -358,7 +358,7 @@ def train_tokenizer(vocab_size=8192, max_samples=None, force=False):
eos_id=EOS_ID,
bos_id=BOS_ID,
unk_id=UNK_ID,
- user_defined_symbols=["<tool_call>", "<tools>", "<defer>"],
+ user_defined_symbols=["<tool_call>", "<tools>"],
byte_fallback=True,
normalization_rule_name="identity",
num_threads=min(20, max(1, (os.cpu_count() or 1) // 4)),
@@ -413,11 +413,6 @@ def load_tool_calls(split="train", max_samples=None, return_global_indices=False
ds = ds.select(global_indices.tolist())
- # Normalize <defer> / empty answers to []
- ds = ds.map(lambda ex: {
- "answers": "[]" if ex["answers"].strip() in ("", "<defer>") else ex["answers"]
- })
-
if max_samples:
limit = min(max_samples, len(ds))
ds = ds.select(range(limit))
@@ -518,8 +513,6 @@ def prepare_tool_call_pairs(ds, tokenizer, max_enc_len=DEFAULT_MAX_ENC_LEN, max_
return s
ans_texts = [_compact(a) for a in ans_texts]
- # Normalize any remaining <defer> or empty answers to []
- ans_texts = ["[]" if a.strip() in ("", "<defer>") else a for a in ans_texts]
tools_texts = [_compact(t) for t in tools_texts]
tool_counts = np.array([_count_tool_calls(a) for a in ans_texts], dtype=np.int32)
diff --git a/src/train.py b/src/train.py
index 5ca306f..c7563ca 100644
--- a/src/train.py
+++ b/src/train.py
@@ -882,7 +882,7 @@ def train(args):
_pc_keys = ("n", "exact", "name_tp", "name_fp", "name_fn",
"call_tp", "call_fp", "call_fn", "parse_err")
- per_count = {t: {k: 0 for k in _pc_keys} for t in range(6)}
+ per_count = {t: {k: 0 for k in _pc_keys} for t in range(4)}
def _call_key(c):
if not isinstance(c, dict): return None
@@ -891,7 +891,7 @@ def train(args):
for ex, pred_text in zip(tc_eval_pairs, tc_preds):
try:
tool_defs = _json_mod.loads(ex["tools"])
- num_tools = min(len(tool_defs), 5)
+ num_tools = min(len(tool_defs), 3)
except (ValueError, TypeError):
tool_defs = []
num_tools = 0
@@ -1036,11 +1036,11 @@ def train(args):
print(f" Call F1 {tc_metrics['call_f1']:>10.1%}")
print(f" Exact match {tc_metrics['exact_match']:>10.1%}")
# Per-tool-count breakdown table
- has_any_pc = any(per_count[t]["n"] > 0 for t in range(6))
+ has_any_pc = any(per_count[t]["n"] > 0 for t in range(4))
if has_any_pc:
print(f" ─── Tool-Call Accuracy by #Tools ───")
print(f" {'#tools':>6} {'n':>4} {'name_f1':>8} {'nTP':>4} {'nFP':>4} {'nFN':>4} {'call_f1':>8} {'cTP':>4} {'cFP':>4} {'cFN':>4} {'exact':>6} {'parse':>6}")
- for t in range(6):
+ for t in range(4):
d = per_count[t]
if d["n"] == 0:
continue
@@ -1099,7 +1099,7 @@ def train(args):
log_dict["epoch/tc_args_acc"] = tc_metrics["args_acc"]
log_dict["epoch/tc_call_f1"] = tc_metrics["call_f1"]
- for t in range(6):
+ for t in range(4):
d = per_count[t]
if d["n"] == 0:
continue