YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Gemma-GLM v1.0 β Geometric Language Machine
The deterministic brain for any LLM. Zero trainable parameters.
A single-file LLM-GLM hybrid that combines probabilistic language model fluency with exact mathematical grounding from the Golay [24,12,8] code, Leech lattice Ξββ, and the Universal Binary Principle (UBP).
Quick Start
# Verify everything works
python3 gemma_glm.py --test
# Interactive REPL
python3 gemma_glm.py
# With a local LLM (Gemma, LLaMA, etc.)
python3 gemma_glm.py --api http://localhost:8080
No pip installs needed. Python β₯ 3.10, stdlib only.
What It Does
| Feature | How |
|---|---|
| Block hallucinations | CRG semantic graph (114 concepts) vetoes irrelevant tokens |
| Exact math | fractions.Fraction β muon ratio 0.029% error, Ξ±_s 0.27% error |
| Write & run Python | Sandboxed execution with AST analysis and quality scoring |
| Process images | 4Γ6 MOG patch grid β Golay snap β visual coherence (NRCI) |
| Grow its own knowledge | Dynamic CRG infers unknown words, flags as β‘speculative |
| Drop into any LLM | One-line LogitsProcessor for HuggingFace models |
| Self-assembling geometry | Every token gets a geometric profile from its prime factorization |
File Structure
gemma-glm/
βββ gemma_glm.py # Full system (1,866 lines) β start here
βββ ubp_unified_v5.py # UBP engine (3,447 lines) β Golay, Leech, physics
βββ value_geometry.py # ValueGeometry (1,477 lines) β integer geometry
βββ llm_glm/ # Modular library (same code, organized by topic)
β βββ __init__.py
β βββ vector_engine.py # 24-bit Golay substrate, SVD vocab, NRCI
β βββ resonance.py # Geometric resonance scoring
β βββ hard_veto.py # CRG-first constraint masking
β βββ vision.py # Visual NRCI, dual-modality resonance
β βββ real_vision.py # Real image processing (ViT/CLIP β Golay)
β βββ math_engine.py # Exact rational arithmetic
β βββ script_engine.py # Python code sandbox + AST analysis
β βββ dynamic_crg.py # Self-growing knowledge graph
β βββ hf_logits_processor.py # HuggingFace LogitsProcessor
β βββ kv_pruner.py # CRG-based attention cache pruning
β βββ speculative.py # GLM draft β LLM verify
β βββ pipeline.py # System 1/2 loop
β βββ vg_integration.py # ValueGeometry integration
βββ README.md # This file
βββ MOBILE_INSTALL.md # Phone/tablet installation guide
Usage
Interactive REPL
python3 gemma_glm.py
> /muon
m_ΞΌ/m_e = 206.7075 (target: 206.7683, err: 0.0294% [PREDICTIVE])
> /alpha_s
Ξ±_s = 0.117778 (target: 0.1181, err: 0.2723%)
> /profile photon
Token: photon
Grid: square
Ο (dim): 3
NRCI: 0.6470
Lattice: HW-14
> /veto boson kitchen protagonist
PASS boson pass
PASS kitchen pass
VETO protagonist CRG dist 7>6
> /code from fractions import Fraction
print(Fraction(1,3) + Fraction(1,6))
Output: 1/2
> what is the muon mass ratio
The muon/electron mass ratio is 206.7075
Command Line
python3 gemma_glm.py --profile photon # ValueGeometry profile
python3 gemma_glm.py --math "169 / 0.8176" # Exact math
python3 gemma_glm.py --code "print(42)" # Sandbox execution
python3 gemma_glm.py --pipeline "explain energy" # System 1/2 loop
python3 gemma_glm.py --draft 5 # Speculative draft
HuggingFace Model (one line)
from llm_glm.hf_logits_processor import create_glm_processor
processor = create_glm_processor(tokenizer=tokenizer, bias_strength=1.0)
outputs = model.generate(input_ids, logits_processor=[processor])
Python Sandbox
from llm_glm.script_engine import run_code, validate_code
r = run_code("from fractions import Fraction\nprint(Fraction(1,3))")
print(r.stdout) # "1/3"
v = validate_code(open("my_script.py").read())
print(v["verdict"]) # "EXCELLENT"
print(v["nrci_score"]) # 0.80
Exact Physics Math
from llm_glm.math_engine import MathEngine
math = MathEngine()
r = math.muon_ratio()
print(r.approx) # 206.7075
print(r.fingerprint["target_error_pct"]) # 0.0294
print(r.fingerprint["verdict"]) # "PREDICTIVE"
The 13 Sections of gemma_glm.py
| Β§ | Component | What It Does |
|---|---|---|
| 1 | UBP Substrate | Golay [24,12,8] with 2325-entry syndrome table, Leech Ξββ, exact constants |
| 2 | Vector Engine | 24-bit substrate, SVD vocabulary, IdeaZone centroid |
| 3 | CRG | 114-concept knowledge graph, self-growing, persists to disk |
| 4 | Math Engine | Exact rational arithmetic, UBP physics formulas |
| 5 | Script Engine | Python sandbox, AST analysis, NRCI quality scoring |
| 6 | Vision Pipeline | MOG patches, visual NRCI, dual-modality resonance |
| 7 | Resonance & Veto | Multi-signal scoring, CRG-first constraints |
| 8 | LogitsProcessor | Drop-in for HuggingFace models |
| 9 | Pipeline | System 1/2 loop (LLM proposes β GLM verifies) |
| 10 | Speculative | GLM draft β LLM verify (instant, no forward pass) |
| 11 | KV Pruning | CRG-based attention cache relevance |
| 12 | ValueGeometry | Self-assembling integer geometry from factorization |
| 13 | Agent | Interactive REPL with all commands |
Key Numbers
| Metric | Value |
|---|---|
| Self-test | 18/18 pass |
| Math accuracy | muon/e 0.029%, Ξ±_s 0.27%, Hβ 0.21% |
| Hallucination block | 100% (CRG distance > 6) |
| Physics pass | 100% (boson, electron, etc.) |
| Sandbox safety | 4/4 dangerous imports blocked |
| Vision NRCI gap | 0.0811 (crisp vs noisy) |
| CRG taxonomy | 114 static concepts |
| Pipeline latency | < 1ms |
| File size | ~48 KB (gemma_glm.py only) |
Mobile Installation
See MOBILE_INSTALL.md for Termux (Android), Pythonista (iOS), iSH, and more.
TL;DR: Copy gemma_glm.py to your phone. Run python3 gemma_glm.py. Done.
Connecting to a Local LLM
# llama.cpp
./server -m gemma-2b.gguf --port 8080
python3 gemma_glm.py --api http://localhost:8080/v1/completions
# Ollama
ollama run gemma:2b
python3 gemma_glm.py --api http://localhost:11434/api/generate
How It Works
You type β GLM processes β zone updated β CRG checks
β
βββββββββββββββββββββββββββββββ
β Is the word in the CRG? β
β Yes β check distance β
β No β infer + flag β‘spec β
ββββββββββββββββ¬βββββββββββββββ
β
βββββββββββββββββββββββββββββββ
β Veto: CRG dist > 6? β BLOCKβ
β Veto: d_H > 14? β BLOCK β
β Veto: NRCI < 0.58? β BLOCK β
ββββββββββββββββ¬βββββββββββββββ
β
βββββββββββββββββββββββββββββββ
β Resonance score candidate β
β proximity + NRCI + grid β
ββββββββββββββββ¬βββββββββββββββ
β
Output or LLM call (if --api)
The CRG grows each session. Unknown words get inferred from context
and flagged as β‘speculative until seen 3+ times. It persists to
~/.gemma_glm_crg.json.
Inference Providers NEW
This model isn't deployed by any Inference Provider. π Ask for provider support