v0.7.0: FNH gate de punição + árvore de pesos indexada (arestas duplas) + quebra-cabeça do Pensamento + NLP/NLG + decodificador especulativo + auto-ajuste SOM limitado + correções v070-1/2/3 — 73/73 gates, 84/84 cargo, provas r-28..r-32
4dbc907 verified Download scripts/64_suite_nlp_nlg.py from PowerMachine/khtst-rust: direct link, hf CLI and curl.
- Browser
- Download file 2.17 kB
-
https://huggingface.co/PowerMachine/khtst-rust/resolve/main/scripts/64_suite_nlp_nlg.py
- Command line
-
hf download hf://PowerMachine/khtst-rust/scripts/64_suite_nlp_nlg.py
-
curl -L -o 64_suite_nlp_nlg.py https://huggingface.co/PowerMachine/khtst-rust/resolve/main/scripts/64_suite_nlp_nlg.py
2.17 kB
| #!/usr/bin/env python3 | |
| """64_suite_nlp_nlg.py — v0.7.0: gates das unidades NLP/NLG + decodificador | |
| especulativo + auto-ajuste SOM limitado (r-31, r-29 §4). | |
| Gates: | |
| N1 nascimento neutro NLP (dif = 0 bit-a-bit) e NLG; | |
| N2 gate médio ≈ σ(−2) ≈ 0,119; | |
| N3 coerência bigramas discriminante (> 0,9 vs < 0,1); | |
| E1 especulativo: aceitação alta com logits concentrados; | |
| E2 speedup > 1 com ρ > c_d/(1+c_d); | |
| S1 SOM: tetos dos boosts respeitados + stop-learning dispara. | |
| """ | |
| import json, os, sys | |
| def main(): | |
| pasta = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| sys.path.insert(0, pasta) | |
| import khtst_rust as K | |
| rel = {"versao": "nlp-nlg-0.7.0", "gates": {}} | |
| d = K.demo_nlp_nlg() | |
| rel["demo"] = d | |
| for k, v in d["gates"].items(): | |
| rel["gates"]["n_" + k] = bool(v) | |
| # coerência extra com contexto REAL: decodifica um trecho do corpus | |
| bpe = K.Bpe.carregar(os.path.join(pasta, "dados", "bpe.json")) | |
| with open(os.path.join(pasta, "dados", "shard_validacao.jsonl")) as f: | |
| texto = json.loads(f.readline())["texto"] | |
| ids = bpe.codificar(texto)[:64] | |
| rel["dados_reais"] = {"tokens_amostra": len(ids)} | |
| # NLG: coerência do trecho real consigo mesmo (tabela EMA observada) | |
| # — usa o binding demo (a tabela vive no Rust); medimos a taxa de | |
| # bigramas repetidos no próprio texto como proxy de coerência alta | |
| bigs = set(zip(ids[:-1], ids[1:])) | |
| frac_rep = len(bigs) / max(1, len(ids) - 1) | |
| rel["gates"]["n_ctx_real_bigramas_unicos"] = 0.3 < frac_rep <= 1.0 | |
| # SOM limitado | |
| s = K.demo_autoajuste_som() | |
| rel["som"] = s | |
| for k, v in s["gates"].items(): | |
| rel["gates"]["s_" + k] = bool(v) | |
| n_ok = sum(1 for v in rel["gates"].values() if v) | |
| rel["veredito"] = f"{n_ok}/{len(rel['gates'])}" | |
| saida = os.path.join(pasta, "resultados", "suite_nlp_nlg_v070.json") | |
| with open(saida, "w") as f: | |
| json.dump(rel, f, indent=1, ensure_ascii=False) | |
| print(json.dumps(rel["gates"], indent=1)) | |
| print("VEREDITO NLP/NLG/SOM:", rel["veredito"]) | |
| assert n_ok == len(rel["gates"]), "gate NLP/NLG falhou" | |
| if __name__ == "__main__": | |
| main() | |