Download scripts/ter_trainer.py from gibihm/gotti-mirror: direct link, hf CLI and curl.
- Browser
- Download file 3.36 kB
-
https://huggingface.co/datasets/gibihm/gotti-mirror/resolve/main/scripts/ter_trainer.py
- Command line
-
hf download hf://datasets/gibihm/gotti-mirror/scripts/ter_trainer.py
-
curl -L -o ter_trainer.py https://huggingface.co/datasets/gibihm/gotti-mirror/resolve/main/scripts/ter_trainer.py
3.36 kB
| #!/usr/bin/env python3 | |
| # ter_trainer - GOTTI selbstlernender Fokus-Daemon (eigenständig) | |
| # =============================================================== | |
| # Lernt was nach einem harten Reset überlebenswichtig ist. | |
| # Mechanik (echt, nicht Deko): | |
| # - liest Kapsel-Fracht (cargo mit id/type/priority/payload) | |
| # - Relevanz-Score je Frachtstück = f(priority, typ, alter, trefferhistorie) | |
| # - EIGENLEREN: Gewichte pro (type,priority) via EMA; Treffer (wird im | |
| # nächsten Lauf wieder relevant) verstärkt Gewicht, sonst decay. | |
| # - FOKUS-Set = Top-N nach Score. Persistiert in fabrik_memory/state.json. | |
| # - Schreibt komprimierte .ter-Notiz (ter_lang) mit aktuellem Fokus. | |
| # State überlebt Reset -> lernt über Sessions hinweg. | |
| import json, os, time, hashlib, datetime, sys | |
| HERE = os.path.dirname(os.path.abspath(__file__)) | |
| MEM = os.path.join(HERE, "fabrik_memory") | |
| STATE = os.path.join(MEM, "state.json") | |
| MANIFEST = os.path.join(HERE, "zeitkapsel_manifest.json") | |
| TEROUT = os.path.join(HERE, "focus_log.ter") | |
| RECHEN = "/home/nextlevel/venvs/rechen/bin/python" | |
| sys.path.insert(0, HERE) | |
| import ter_lang | |
| PRI = {"high": 3.0, "normal": 1.5, "low": 0.5} | |
| TYPMULT = {"context": 1.4, "dataset": 1.2, "reminder": 1.3, | |
| "learning": 1.1, "link_hint": 0.9, "tertiary": 1.0, "skill_ref": 1.1} | |
| def load_state(): | |
| if os.path.exists(STATE): | |
| return json.load(open(STATE)) | |
| return {"weights": {}, "history": [], "runs": 0, "ema_decay": 0.92} | |
| def save_state(s): | |
| os.makedirs(MEM, exist_ok=True) | |
| json.dump(s, open(STATE, "w"), indent=1) | |
| def score(cargo, st): | |
| rows = [] | |
| for c in cargo: | |
| w_key = f"{c['type']}:{c['priority']}" | |
| w = st["weights"].get(w_key, 1.0) | |
| base = PRI.get(c["priority"], 1.0) * TYPMULT.get(c["type"], 1.0) | |
| sc = base * w | |
| rows.append((sc, c)) | |
| rows.sort(key=lambda r: r[0], reverse=True) | |
| return rows | |
| def learn(st, focus_ids, cargo): | |
| # EMA: Treffer (in Fokus) verstärken, Rest decay | |
| hit = set(focus_ids) | |
| for c in cargo: | |
| w_key = f"{c['type']}:{c['priority']}" | |
| old = st["weights"].get(w_key, 1.0) | |
| if c["id"] in hit: | |
| st["weights"][w_key] = min(5.0, old * 1.05 + 0.1) # verstärken | |
| else: | |
| st["weights"][w_key] = max(0.2, old * st["ema_decay"]) # decay | |
| st["history"].append({"t": datetime.date.today().isoformat(), | |
| "focus": focus_ids}) | |
| st["history"] = st["history"][-50:] | |
| st["runs"] += 1 | |
| def main(): | |
| st = load_state() | |
| cargo = json.load(open(MANIFEST)).get("cargo", []) | |
| ranked = score(cargo, st) | |
| TOPN = 6 | |
| focus = ranked[:TOPN] | |
| focus_ids = [c["id"] for _, c in focus] | |
| learn(st, focus_ids, cargo) | |
| save_state(st) | |
| # .ter Notiz schreiben (tertiär: Bedeutung kollabiert beim Lesen) | |
| entries = [] | |
| for i, (sc, c) in enumerate(focus): | |
| entries.append({"id": c["id"], "lvl": "T", | |
| "payload": f"{c['payload'][:90]} [score={sc:.2f}]", | |
| "trace": f"focus#{i+1}"}) | |
| ter = ter_lang.encode(entries) | |
| open(TEROUT, "w").write(ter) | |
| print(f"[ter_trainer] run#{st['runs']} | Fokus({TOPN}):") | |
| for sc, c in focus: | |
| print(f" {sc:5.2f} {c['id']:14} {c['priority']:6} {c['type']}") | |
| print(f"[ter_trainer] .ter -> {TEROUT}") | |
| if __name__ == "__main__": | |
| main() | |