DE-ToolCall-Bench: 78 Aufgaben, Tools, Auswertung, Ergebnisse Qwen2.5-0.5B & Qwen3-0.6B
a0496e4 verified Download evaluate.py from roskosmos19/DE-ToolCall-Bench: direct link, hf CLI and curl.
- Browser
- Download file 2.36 kB
-
https://huggingface.co/datasets/roskosmos19/DE-ToolCall-Bench/resolve/main/evaluate.py
- Command line
-
hf download hf://datasets/roskosmos19/DE-ToolCall-Bench/evaluate.py
-
curl -L -o evaluate.py https://huggingface.co/datasets/roskosmos19/DE-ToolCall-Bench/resolve/main/evaluate.py
2.36 kB
| """DE-ToolCall-Bench – Auswertung / evaluation script. | |
| Usage: python evaluate.py <hf-model-id> [results.json] | |
| Benötigt/needs: transformers, torch, huggingface_hub | |
| """ | |
| import json, sys, time, collections, torch | |
| from huggingface_hub import hf_hub_download | |
| from transformers import AutoTokenizer, AutoModelForCausalLM | |
| from score import parse_calls, score | |
| REPO = "roskosmos19/DE-ToolCall-Bench" | |
| SYSTEM = ("Du bist ein hilfreicher Assistent. Heute ist Montag, der 23.11.2026, es ist 09:00 Uhr. " | |
| "Nutze ein Werkzeug nur, wenn es nötig ist. Fehlen nötige Angaben, frage nach statt zu raten. Antworte auf Deutsch.") | |
| def main(model_id, out="results.json"): | |
| items = [json.loads(l) for l in open(hf_hub_download(REPO, "data/test.jsonl", repo_type="dataset"))] | |
| tools = json.load(open(hf_hub_download(REPO, "tools.json", repo_type="dataset"))) | |
| tok = AutoTokenizer.from_pretrained(model_id) | |
| model = AutoModelForCausalLM.from_pretrained(model_id, dtype=torch.float32).eval() | |
| res, t0 = [], time.time() | |
| for it in items: | |
| msgs = [{"role": "system", "content": SYSTEM}, {"role": "user", "content": it["query"]}] | |
| prompt = tok.apply_chat_template(msgs, tools=tools, add_generation_prompt=True, tokenize=False, | |
| enable_thinking=False) | |
| ids = tok(prompt, return_tensors="pt") | |
| with torch.no_grad(): | |
| o = model.generate(**ids, max_new_tokens=160, do_sample=False) | |
| txt = tok.decode(o[0][ids["input_ids"].shape[1]:], skip_special_tokens=False) | |
| exact, sel = score(json.loads(it["expected_calls"]), parse_calls(txt)) | |
| res.append({"id": it["id"], "category": it["category"], "exact": exact, "tool_selection": sel, "output": txt}) | |
| cat = collections.defaultdict(list) | |
| for r in res: cat[r["category"]].append(r["exact"]) | |
| summary = {"model": model_id, "n": len(res), | |
| "exact_match": sum(r["exact"] for r in res) / len(res), | |
| "tool_selection": sum(r["tool_selection"] for r in res) / len(res), | |
| "per_category": {k: sum(v) / len(v) for k, v in cat.items()}, | |
| "seconds": round(time.time() - t0)} | |
| json.dump({"summary": summary, "results": res}, open(out, "w"), ensure_ascii=False, indent=1) | |
| print(json.dumps(summary, indent=1)) | |
| if __name__ == "__main__": | |
| main(*sys.argv[1:]) | |