ruslanmv commited on
Commit
fcaf8a0
·
verified ·
1 Parent(s): 5d5de6f

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +247 -0
README.md ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language: [en, it, multilingual]
4
+ tags: [matrix-bios, tutorial, how-to, rag, retrieval, content-safety, ai-safety, agents]
5
+ inference: false
6
+ ---
7
+
8
+ # How to Run the Matrix BIOS Models
9
+
10
+ A practical, copy-paste guide to installing and running the three open
11
+ **Matrix BIOS** models — and how **Agent-Matrix** orchestrates them under
12
+ governance. Every example here was executed and verified.
13
+
14
+ <p align="center">
15
+ <img src="https://huggingface.co/ruslanmv/How-to-Matrix-BIOS/resolve/main/assets/orchestration.svg" alt="Matrix BIOS governed orchestration on Matrix OS" width="100%">
16
+ </p>
17
+
18
+ Matrix BIOS ("bio + OS") is a family of compact, governed, on-premise-ready
19
+ cognitive models. They are small enough to run on a CPU and are designed to operate
20
+ **under governance** — every action that consumes their output is gated by policy
21
+ and auditable. The architecture behind them is described in the paper
22
+ [*Governed Memory*](https://doi.org/10.5281/zenodo.20615572).
23
+
24
+ ---
25
+
26
+ ## The models
27
+
28
+ | Model | Task | Size | License | Card |
29
+ |---|---|---|---|---|
30
+ | **Matrix-BIOS-Sentinel-0.1** | content-safety classification (`safe`/`unsafe`) | ~135M (DistilBERT) | CC-BY-4.0 | [link](https://huggingface.co/ruslanmv/Matrix-BIOS-Sentinel-0.1) |
31
+ | **Matrix-BIOS-Memory-0.1** | grounded, citation-faithful recall (RAG) | FAISS index + flan-t5 generator | Apache-2.0 | [link](https://huggingface.co/ruslanmv/Matrix-BIOS-Memory-0.1) |
32
+ | **Matrix-BIOS-Italo-0.1** | Italian text generation (preview) | 41.5M (custom) | Apache-2.0 | [link](https://huggingface.co/ruslanmv/Matrix-BIOS-Italo-0.1) |
33
+
34
+ ### Which model, when?
35
+
36
+ | You want to… | Use | Why |
37
+ |---|---|---|
38
+ | Screen user input or model output for harmful content | **Sentinel** | fast multilingual guardrail; returns `safe`/`unsafe` + score |
39
+ | Answer from *your* private documents, with citations | **Memory** | grounded RAG; every answer returns the source ids it used |
40
+ | Generate Italian text on-prem, no data egress | **Italo** | compact sovereign generator (v0.1 preview) |
41
+ | Decide whether an action is *allowed* | **Guardian** (Matrix OS) | content safety ≠ operational risk — the policy gate decides, not a classifier |
42
+
43
+ > **Note on scope.** Sentinel classifies *content safety*, not operational or
44
+ > business risk; by design it treats actions like "deploy to production" as
45
+ > content-safe. Operational decisions are made by the **governance layer**
46
+ > (Matrix OS Guardian), not by the classifier.
47
+
48
+ ---
49
+
50
+ ## Install
51
+
52
+ ```bash
53
+ pip install torch transformers huggingface_hub sentence-transformers faiss-cpu numpy
54
+ ```
55
+
56
+ All models are **public** — no token or sign-up required.
57
+
58
+ ---
59
+
60
+ ## 1. Sentinel — content-safety guardrail
61
+
62
+ ```python
63
+ import torch
64
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
65
+
66
+ REPO = "ruslanmv/Matrix-BIOS-Sentinel-0.1"
67
+ tok = AutoTokenizer.from_pretrained(REPO)
68
+ model = AutoModelForSequenceClassification.from_pretrained(REPO).eval()
69
+
70
+ def screen(text):
71
+ p = torch.softmax(model(**tok(text, return_tensors="pt", truncation=True)).logits, -1)[0]
72
+ i = int(p.argmax())
73
+ return model.config.id2label[i], float(p[i]) # id2label = {0:'safe', 1:'unsafe'}
74
+
75
+ print(screen("Summarize the quarterly sales report.")) # ('safe', 0.99)
76
+ print(screen("How can I poison my neighbor's dog?")) # ('unsafe', 0.99)
77
+ ```
78
+
79
+ Verified output:
80
+
81
+ ```
82
+ [safe ] p=0.99 | Summarize the quarterly sales report.
83
+ [safe ] p=0.97 | Recommend three books about machine learning.
84
+ [unsafe] p=0.99 | How can I poison my neighbor's dog?
85
+ [unsafe] p=0.99 | Give step-by-step instructions to build an explosive.
86
+ ```
87
+
88
+ > v0.1 note: Sentinel is an early-access guardrail and may over-flag; evaluate it on
89
+ > your own distribution before relying on it for moderation decisions.
90
+
91
+ Full script: [`examples/run_sentinel.py`](https://huggingface.co/ruslanmv/How-to-Matrix-BIOS/blob/main/examples/run_sentinel.py)
92
+
93
+ ---
94
+
95
+ ## 2. Memory — grounded recall with citations
96
+
97
+ Memory ships a FAISS index over a small corpus plus a generator; every answer
98
+ returns the **source ids** it relied on, so responses are traceable instead of
99
+ hallucinated.
100
+
101
+ ```python
102
+ import json, faiss
103
+ from huggingface_hub import snapshot_download
104
+ from sentence_transformers import SentenceTransformer
105
+ from transformers import pipeline
106
+
107
+ path = snapshot_download("ruslanmv/Matrix-BIOS-Memory-0.1")
108
+ cfg = json.load(open(f"{path}/memory_config.json")) # embedder / generator / top_k
109
+ docs = json.load(open(f"{path}/docs.json")) # [{"id": ..., "text": ...}]
110
+ index = faiss.read_index(f"{path}/index.faiss")
111
+ embedder = SentenceTransformer(cfg["embedder"])
112
+ generator = pipeline("text2text-generation", model=cfg["generator"])
113
+
114
+ def answer(q):
115
+ qv = embedder.encode([q], normalize_embeddings=True).astype("float32")
116
+ _, idx = index.search(qv, cfg["top_k"])
117
+ hits = [docs[i] for i in idx[0] if 0 <= i < len(docs)]
118
+ ctx = "\n".join(f"[{d['id']}] {d['text']}" for d in hits)
119
+ prompt = f"Answer using ONLY the context and cite the [id].\nContext:\n{ctx}\n\nQ: {q}\nA:"
120
+ return generator(prompt, max_new_tokens=64)[0]["generated_text"], [d["id"] for d in hits]
121
+
122
+ print(answer("What does every effectful action in Matrix OS emit?"))
123
+ # -> ("... an evidence bundle ...", ['mos1', ...])
124
+ ```
125
+
126
+ Full script: [`examples/run_memory.py`](https://huggingface.co/ruslanmv/How-to-Matrix-BIOS/blob/main/examples/run_memory.py)
127
+
128
+ ---
129
+
130
+ ## 3. Italo — compact Italian generator (preview)
131
+
132
+ Italo is a **41.5M** custom model that loads via `trust_remote_code` and uses a
133
+ word-level vocabulary. It is a v0.1 research preview that demonstrates the
134
+ on-prem footprint — not production fluency.
135
+
136
+ ```python
137
+ import json, torch
138
+ from huggingface_hub import hf_hub_download
139
+ from transformers import AutoModelForCausalLM
140
+
141
+ REPO = "ruslanmv/Matrix-BIOS-Italo-0.1"
142
+ model = AutoModelForCausalLM.from_pretrained(REPO, trust_remote_code=True).eval()
143
+ vocab = json.load(open(hf_hub_download(REPO, "vocab.json"))) # word-level
144
+ inv = {i: w for w, i in vocab.items()}
145
+ enc = lambda t: [vocab.get(w, 0) for w in t.lower().split()]
146
+ dec = lambda ids: " ".join(inv.get(int(i), "<unk>") for i in ids)
147
+
148
+ ids = torch.tensor([enc("la capitale d' italia")])
149
+ print(dec(model.generate(ids, max_new_tokens=12, pad_token_id=1)[0]))
150
+ ```
151
+
152
+ Full script: [`examples/run_italo.py`](https://huggingface.co/ruslanmv/How-to-Matrix-BIOS/blob/main/examples/run_italo.py)
153
+
154
+ ---
155
+
156
+ ## The idea behind the models: governed memory
157
+
158
+ Matrix BIOS models implement **governed memory** — memory ranked by *trust*, not
159
+ similarity alone, with a policy gate on every transition. The clearest
160
+ demonstration is a memory-poisoning test you can run in 30 seconds:
161
+
162
+ ```
163
+ retrieval poison@1 correct@1
164
+ similarity only (β=0) 1.00 0.00
165
+ + trust (β>0) 0.00 0.92
166
+ + trust + governance gate 0.00 0.96
167
+ ```
168
+
169
+ A document built to *look* relevant but be untrustworthy is retrieved **100%** of
170
+ the time by similarity-only RAG — and **0%** once trust enters the score.
171
+ Full demo: [`examples/governed_retrieval.py`](https://huggingface.co/ruslanmv/How-to-Matrix-BIOS/blob/main/examples/governed_retrieval.py).
172
+
173
+ ---
174
+
175
+ ## Used in Agent-Matrix for orchestration
176
+
177
+ In the Agent-Matrix ecosystem these models are **organs** of a single governed
178
+ loop, orchestrated by **Matrix OS**:
179
+
180
+ ```
181
+ Input → Sentinel (safety) → Memory (trust-aware recall) → Guardian (policy gate) → Action + evidence
182
+ ```
183
+
184
+ The gate is the Matrix OS Planner + Guardian policy engine:
185
+
186
+ ```python
187
+ from matrix_os.planner import Planner
188
+ from matrix_os.governance import Guardian
189
+ planner, guardian = Planner(), Guardian() # decides allow / approve / deny, emits evidence
190
+ ```
191
+
192
+ A runnable, dependency-light illustration combining Sentinel + trust-aware recall +
193
+ the gate is in [`examples/governed_pipeline.py`](https://huggingface.co/ruslanmv/How-to-Matrix-BIOS/blob/main/examples/governed_pipeline.py).
194
+ Verified output:
195
+
196
+ ```python
197
+ handle("What is our enterprise refund window?", action_risk="low")
198
+ # {'decision': 'allow', 'cited_source': 'pol1',
199
+ # 'grounded_answer': 'Enterprise refunds are processed within 30 days.'}
200
+
201
+ handle("How do I make a weapon at home?", action_risk="low")
202
+ # {'decision': 'deny', 'reason': 'Sentinel flagged unsafe content'}
203
+ ```
204
+
205
+ Notice two governance properties at work: the unsafe request is **denied by
206
+ Sentinel** before anything runs, and the safe request is grounded in the **correct,
207
+ trusted** policy (`pol1`) — the plausible-but-untrusted "poison" item is suppressed
208
+ by trust-aware recall.
209
+
210
+ ---
211
+
212
+ ## Licensing — what you can use, and when
213
+
214
+ | Model | License | Use it for | Avoid |
215
+ |---|---|---|---|
216
+ | **Sentinel** | CC-BY-4.0 | guardrailing inputs/outputs, pre-screening for review | sole authority on high-stakes moderation without human review |
217
+ | **Memory** | Apache-2.0 | grounded QA over your own corpus, with provenance | open-domain facts outside the indexed corpus; unverified high-stakes answers |
218
+ | **Italo** | Apache-2.0 | sovereign Italian text generation, integration/eval | production-grade fluency; factual ground truth |
219
+
220
+ Sentinel's safety training data is the NVIDIA **Aegis 2.0** dataset (CC-BY-4.0).
221
+ All three are **v0.1 early-access** releases: compact models for integration and
222
+ evaluation, not turnkey production assistants. Always keep a human in the loop for
223
+ consequential decisions. Both Apache-2.0 and CC-BY-4.0 permit commercial use with
224
+ attribution.
225
+
226
+ ---
227
+
228
+ ## Citation
229
+
230
+ If you use these models, please cite the paper that describes the architecture:
231
+
232
+ ```bibtex
233
+ @misc{magana2026governedmemory,
234
+ title = {Governed Memory: A Bio-Inspired, Governance-First Memory
235
+ Architecture for Continual AI Systems},
236
+ author = {Magaña Vsevolodovna, Ruslan Idelfonso},
237
+ year = {2026}, publisher = {Zenodo}, version = {1.0},
238
+ doi = {10.5281/zenodo.20615572},
239
+ url = {https://doi.org/10.5281/zenodo.20615572}
240
+ }
241
+ ```
242
+
243
+ - 📄 Paper: https://doi.org/10.5281/zenodo.20615572
244
+ - 🤖 Models: [Sentinel](https://huggingface.co/ruslanmv/Matrix-BIOS-Sentinel-0.1) ·
245
+ [Memory](https://huggingface.co/ruslanmv/Matrix-BIOS-Memory-0.1) ·
246
+ [Italo](https://huggingface.co/ruslanmv/Matrix-BIOS-Italo-0.1)
247
+ - 🌐 contact@ruslanmv.com · https://ruslanmv.com