Datasets:
Download code/compare_counting_hard.py from Davidmg0815/spreizzaehler-daten: direct link, hf CLI and curl.
- Browser
- Download file 3.65 kB
-
https://huggingface.co/datasets/Davidmg0815/spreizzaehler-daten/resolve/main/code/compare_counting_hard.py
- Command line
-
hf download hf://datasets/Davidmg0815/spreizzaehler-daten/code/compare_counting_hard.py
-
curl -L -o compare_counting_hard.py https://huggingface.co/datasets/Davidmg0815/spreizzaehler-daten/resolve/main/code/compare_counting_hard.py
3.65 kB
| #!/usr/bin/env python3 | |
| """Schwerer Zaehl-Vergleich (Generalisierungs-Set: Sonderzeichen, Ueberlaenge, Code, andere Prompts). | |
| Dieselben 28 Aufgaben und Prompts wie beim Generalisierungstest unseres Modells, gestellt an QuiteQue-Modelle. | |
| """ | |
| import json | |
| import sys | |
| import threading | |
| import time | |
| from concurrent.futures import ThreadPoolExecutor | |
| sys.path.insert(0, "/mnt/models/graf_zahl") | |
| from compare_counting_quiteque import ALLOWED, ask, last_int # noqa: E402 | |
| PLATTE = "/home/david/Schreibtisch/Platte" | |
| GEN = f"{PLATTE}/models/graf_zahl/generalization_results.json" | |
| OUT = f"{PLATTE}/models/graf_zahl/compare_counting_hard_results.json" | |
| SUFFIX = " Antworte nur mit der Zahl." | |
| MODELS = [ | |
| ("50", "T79 Qwen3 4B Instruct (CPU)", 1), | |
| ("gemma-12b-chat", "Gemma 4 12B (lokal)", 2), | |
| ("120", "PropellerA Qwen3.8 27B (lokal)", 1), | |
| ("or-liquid/lfm-2.5-2.6b:free", "Liquid LFM 2.5 2.6B (free)", 2), | |
| ("or-google/gemma-4-31b-it:free", "Gemma 4 31B (free)", 2), | |
| ("or-nvidia/nemotron-3-nano-omni-30b-a3b-reasoning:free", "Nemotron 3 Nano 30B Reasoning (free)", 2), | |
| ("or-nex-agi/nex-n2.5-pro:free", "Nex-N2.5 Pro (free)", 2), | |
| ("or-nvidia/nemotron-3.5-lightning:free", "Nemotron 3.5 Lightning (free)", 2), | |
| ] | |
| def main(): | |
| assert all(ALLOWED(m[0]) for m in MODELS) | |
| ours = json.load(open(GEN, encoding="utf-8")) | |
| items = [(r["kategorie"], r["text"], len(r["text"]), r["prompt"] + SUFFIX, r["endzahl"]) for r in ours] | |
| cats = list(dict.fromkeys(i[0] for i in items)) | |
| print(f"{len(items)} Aufgaben, {len(MODELS)} Modelle", flush=True) | |
| results, lock = {}, threading.Lock() | |
| for mid, name, threads in MODELS: | |
| rows = [] | |
| def one(it): | |
| cat, s, n, prompt, _ = it | |
| content, err = ask(mid, prompt, None, max_tokens=6000) | |
| got = last_int(content) if not err else None | |
| return {"kategorie": cat, "text": s, "soll": n, "antwort": content[:300], "zahl": got, "richtig": got == n, "fehler": err} | |
| t0 = time.time() | |
| with ThreadPoolExecutor(threads) as ex: | |
| for r in ex.map(one, items): | |
| rows.append(r) | |
| with lock: | |
| results[mid] = {"name": name, "rows": rows} | |
| json.dump(results, open(OUT, "w", encoding="utf-8"), ensure_ascii=False) | |
| print(f"[{name}] fertig: {sum(r['richtig'] for r in rows)}/{len(rows)} richtig, {sum(1 for r in rows if r['fehler'])} Fehler, {time.time() - t0:.0f}s", flush=True) | |
| ours_rows = [{"kategorie": c, "richtig": e == n, "soll": n} for c, s, n, p, e in items] | |
| results["unser"] = {"name": "UNSER Hardcore-Modell ('Das sind N')", "rows": ours_rows} | |
| # unser Modell zusaetzlich mit Zahl aus dem Think-Block | |
| think = {"kategorie": None} | |
| ours_think = [{"kategorie": r["kategorie"], "richtig": r["sicherheitszahl"] == len(r["text"])} for r in ours] | |
| results["unser_think"] = {"name": "UNSER Modell (Zahl im Think-Block)", "rows": ours_think} | |
| json.dump(results, open(OUT, "w", encoding="utf-8"), ensure_ascii=False) | |
| print("\n===== AUSWERTUNG (richtig je Kategorie) =====") | |
| print(f"{'Modell':44} " + " ".join(f"{c[:10]:>11}" for c in cats) + f" {'Gesamt':>8}") | |
| for key in ["unser", "unser_think"] + [m[0] for m in MODELS]: | |
| rows = results[key]["rows"] | |
| per = [(sum(r["richtig"] for r in rows if r["kategorie"] == c), len([r for r in rows if r["kategorie"] == c])) for c in cats] | |
| print(f"{results[key]['name'][:44]:44} " + " ".join(f"{a:>7}/{b:<3}" for a, b in per) + f" {sum(a for a, _ in per):>4}/{len(rows)}") | |
| print(f"\nErgebnisse: {OUT}") | |
| if __name__ == "__main__": | |
| main() | |