Text Classification
syfox
decision-engine
decision-making
decision-model
structured-prediction
system-one
si-substrate
intent-classification
routing
abstention
uncertainty-quantification
selective-prediction
hebbian
energy-based-model
associative-memory
no-transformer
no-neural-network
no-pattern-matching
moderation
spam-detection
multilingual
Eval Results (legacy)
Upload folder using huggingface_hub
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +2 -34
- .gitignore +4 -0
- Dockerfile +25 -0
- LICENSE +24 -0
- PUSHING.md +21 -0
- README.md +139 -0
- datasets/DATASETS.md +62 -0
- datasets/MANIFEST.json +252 -0
- datasets/cal_bengali.jsonl +0 -0
- datasets/cal_cyrillic.jsonl +0 -0
- datasets/cal_devanagari.jsonl +0 -0
- datasets/cal_latin.jsonl +0 -0
- datasets/eval/agnews_hidden.jsonl +0 -0
- datasets/eval/bank77_hidden.jsonl +0 -0
- datasets/eval/bench_hidden_summary.json +134 -0
- datasets/eval/boolq_hidden.jsonl +0 -0
- datasets/eval/clinc_hidden.jsonl +0 -0
- datasets/eval/dbpedia_hidden.jsonl +0 -0
- datasets/eval/dump_pass1.jsonl +0 -0
- datasets/eval/emotion_hidden.jsonl +0 -0
- datasets/eval/enron_hidden.jsonl +0 -0
- datasets/eval/game_hidden.jsonl +0 -0
- datasets/eval/guard_hidden.jsonl +0 -0
- datasets/eval/hate_hidden.jsonl +0 -0
- datasets/eval/polarity_hidden.jsonl +0 -0
- datasets/eval/sms_hidden.jsonl +0 -0
- datasets/eval/tickets_bn_hidden.jsonl +0 -0
- datasets/eval/tickets_en_hidden.jsonl +0 -0
- datasets/eval/tickets_hi_hidden.jsonl +0 -0
- datasets/eval/tickets_ru_hidden.jsonl +0 -0
- datasets/probes.jsonl +0 -0
- datasets/router_criteria.json +25 -0
- datasets/schemas.json +761 -0
- docs/ARCHITECTURE.md +431 -0
- docs/EVALUATION.md +133 -0
- docs/PROBING.md +94 -0
- docs/ZEROSHOT.md +224 -0
- engine/Makefile +335 -0
- engine/core/bench.hpp +1245 -0
- engine/core/derive.hpp +498 -0
- engine/core/firewall.hpp +82 -0
- engine/core/gate.hpp +205 -0
- engine/core/json.hpp +247 -0
- engine/core/ngram.hpp +118 -0
- engine/core/normalize.hpp +462 -0
- engine/core/recall.hpp +102 -0
- engine/core/script.hpp +237 -0
- engine/core/si_substrate.hpp +837 -0
- engine/core/syfox.hpp +919 -0
- engine/src/syfox_cli.cpp +1198 -0
.gitattributes
CHANGED
|
@@ -1,35 +1,3 @@
|
|
| 1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
-
*.
|
| 5 |
-
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
| 1 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
model/*/substrate.bin filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
model/giant-latin/substrate.bin filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.pyc
|
| 3 |
+
build/
|
| 4 |
+
hf_cache/
|
Dockerfile
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SyFox giant model — HuggingFace Spaces (Docker SDK)
|
| 2 |
+
# Builds the SI-substrate engine from source, then serves the v3 HTTP API
|
| 3 |
+
# on the port Spaces expects (7860). No transformer, no NN: decisions come
|
| 4 |
+
# from the C++ SI substrate (energy injection -> settle -> readout).
|
| 5 |
+
FROM python:3.11-slim AS enginebuild
|
| 6 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 7 |
+
build-essential g++ make && rm -rf /var/lib/apt/lists/*
|
| 8 |
+
WORKDIR /src
|
| 9 |
+
COPY engine/ /src/
|
| 10 |
+
RUN make build/libsyfox_core.so && strip build/libsyfox_core.so
|
| 11 |
+
|
| 12 |
+
FROM python:3.11-slim
|
| 13 |
+
RUN pip install --no-cache-dir fastapi uvicorn
|
| 14 |
+
WORKDIR /app
|
| 15 |
+
COPY --from=enginebuild /src/build/libsyfox_core.so /app/build/libsyfox_core.so
|
| 16 |
+
COPY server/ /app/server/
|
| 17 |
+
COPY inference.py /app/inference.py
|
| 18 |
+
COPY model/ /app/model/
|
| 19 |
+
COPY datasets/ /app/datasets/
|
| 20 |
+
COPY docs/ /app/docs/
|
| 21 |
+
ENV PYTHONUNBUFFERED=1
|
| 22 |
+
EXPOSE 7860
|
| 23 |
+
# script routing: /app/model/giant -> /app/model/giant-latin, giant-bengali, ...
|
| 24 |
+
CMD ["python", "server/app.py", "--model", "model/giant", "--lang", "auto", \
|
| 25 |
+
"--energy-norm", "--host", "0.0.0.0", "--port", "7860"]
|
LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2026 Mr-DS-ML-85
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
| 22 |
+
|
| 23 |
+
Dataset licenses are listed in datasets/DATASETS.md and remain those of the
|
| 24 |
+
original publishers.
|
PUSHING.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Pushing to HuggingFace
|
| 2 |
+
|
| 3 |
+
The latin substrate (`model/giant-latin/substrate.bin`, 112 MB) exceeds
|
| 4 |
+
HuggingFace's 100 MB non-LFS limit. `.gitattributes` already marks
|
| 5 |
+
`*.bin` as LFS — you only need git-lfs installed locally and the blob
|
| 6 |
+
re-staged as an LFS object:
|
| 7 |
+
|
| 8 |
+
```bash
|
| 9 |
+
git lfs install # once per machine
|
| 10 |
+
git rm --cached model/giant-latin/substrate.bin
|
| 11 |
+
git add model/giant-latin/substrate.bin # now stored as an LFS pointer
|
| 12 |
+
git commit --amend --no-edit
|
| 13 |
+
git remote add origin https://huggingface.co/<your-user>/syfox-hf
|
| 14 |
+
git push -u origin main
|
| 15 |
+
```
|
| 16 |
+
|
| 17 |
+
The three small substrates (bengali/devanagari/cyrillic, ~0.5-0.6 MB) are
|
| 18 |
+
under the same `*.bin` rule and will ride along as LFS objects too.
|
| 19 |
+
|
| 20 |
+
If you clone this repo after the LFS push, run `git lfs pull` to fetch the
|
| 21 |
+
binaries.
|
README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
- bn
|
| 6 |
+
- hi
|
| 7 |
+
- ru
|
| 8 |
+
tags:
|
| 9 |
+
- decision-engine
|
| 10 |
+
- system-one
|
| 11 |
+
- si-substrate
|
| 12 |
+
- intent-classification
|
| 13 |
+
- routing
|
| 14 |
+
- moderation
|
| 15 |
+
- spam-detection
|
| 16 |
+
- hebbian
|
| 17 |
+
- no-transformer
|
| 18 |
+
- no-neural-network
|
| 19 |
+
metrics:
|
| 20 |
+
- accuracy
|
| 21 |
+
- ece
|
| 22 |
+
library_name: syfox
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
# SyFox Giant — a broad System-One decision engine (SI substrate, no NN)
|
| 26 |
+
|
| 27 |
+
One giant SyFox fabric family covering **16 decision domains** (customer
|
| 28 |
+
support, banking intents, spam, emotions, moderation, news topics, product
|
| 29 |
+
sentiment, entity typing, boolean comprehension, game commands, guardrails)
|
| 30 |
+
plus per-script substrates for Bengali / Devanagari / Cyrillic with automatic
|
| 31 |
+
script routing. **No transformer, no neural network, no pattern matching**:
|
| 32 |
+
every decision comes from a C++ SI substrate — energy injection →
|
| 33 |
+
dissipative settle → resonance readout → honest silence. The lanes ARE the
|
| 34 |
+
knowledge; every one is inspectable in `model/*/substrate.bin`.
|
| 35 |
+
|
| 36 |
+
Built from 76,142 real/synthetic-verified training rows across 16 domains,
|
| 37 |
+
trained with the three failure-mode fixes learned from the model-xl RCA:
|
| 38 |
+
empty per-row instructions, globally-unique opaque anchors (278), and
|
| 39 |
+
round-robin domain interleaving. Full measured evaluation:
|
| 40 |
+
[docs/EVALUATION.md](docs/EVALUATION.md).
|
| 41 |
+
|
| 42 |
+
## Headline measured numbers (hidden splits, scored once)
|
| 43 |
+
|
| 44 |
+
| domain | class acc | router | end-to-end |
|
| 45 |
+
|---|---:|---:|---:|
|
| 46 |
+
| tickets_en | 0.904 | 0.831 | 0.761 |
|
| 47 |
+
| sms spam | 0.752 | 0.233 | 0.222 |
|
| 48 |
+
| enron email spam | 0.752 | 0.394 | 0.323 |
|
| 49 |
+
| hate/offensive | 0.653 | 0.381 | 0.277 |
|
| 50 |
+
| ag_news topics | 0.604 | 0.320 | 0.206 |
|
| 51 |
+
| amazon polarity | 0.571 | 0.339 | 0.189 |
|
| 52 |
+
| dbpedia entities | 0.475 | 0.403 | 0.204 |
|
| 53 |
+
| boolq (boolean) | 0.531 | 0.097 | 0.059 |
|
| 54 |
+
| bank77 (77-way) | 0.023 | 0.931 | 0.022 |
|
| 55 |
+
| tickets_bn (bengali substrate) | 0.943 | 1.000 | 0.943 |
|
| 56 |
+
| tickets_hi (devanagari substrate) | 0.920 | 1.000 | 0.920 |
|
| 57 |
+
| tickets_ru (cyrillic substrate) | 0.959 | 1.000 | 0.959 |
|
| 58 |
+
|
| 59 |
+
Honest notes: the single 16-way router is the end-to-end bottleneck for
|
| 60 |
+
same-script domains — blind routing alone measures **0.400** on hidden
|
| 61 |
+
(23,528 rows) and the table's router column is the *informed* condition
|
| 62 |
+
(router + the true domain's class question asked together); naming the
|
| 63 |
+
domain in the API gives the class numbers. bank77's 77-way readout collapses
|
| 64 |
+
in a shared fabric (dedicated-fabric reference: 0.081); boolq stays near
|
| 65 |
+
majority — boolean passage comprehension is a measured limit of bag-of-words
|
| 66 |
+
SI physics. Latency ≈ 6-11 ms/row on the 43k-node latin fabric.
|
| 67 |
+
|
| 68 |
+
## Files
|
| 69 |
+
|
| 70 |
+
```
|
| 71 |
+
engine/ C++ SI substrate core (core/*.hpp, src/*.cpp) — builds with make
|
| 72 |
+
server/ FastAPI HTTP bridge (v3 API, CLI-equal flags)
|
| 73 |
+
inference.py thin python wrapper (auto script routing)
|
| 74 |
+
model/ giant-{latin,bengali,devanagari,cyrillic}/substrate.bin (+meta, calibration)
|
| 75 |
+
datasets/ eval hidden splits, probes, schemas, MANIFEST (SHA-256), DATASETS.md
|
| 76 |
+
docs/ EVALUATION.md, ARCHITECTURE.md, PROBING.md, ZEROSHOT.md
|
| 77 |
+
examples/ JSON payloads + curl + python usage
|
| 78 |
+
Dockerfile HuggingFace Spaces (builds engine, serves on 7860)
|
| 79 |
+
```
|
| 80 |
+
|
| 81 |
+
## Usage (python)
|
| 82 |
+
|
| 83 |
+
```python
|
| 84 |
+
from inference import SyFox
|
| 85 |
+
m = SyFox() # loads model/giant-<script> per detected script
|
| 86 |
+
r = m.decide("I was charged twice on my last invoice, please refund.")
|
| 87 |
+
print(r["answers"]["domain"]) # router: choice + probabilities + confidence
|
| 88 |
+
|
| 89 |
+
# ask a named domain's question directly (skips the router bottleneck):
|
| 90 |
+
r = m.decide("I was charged twice on my last invoice, please refund.",
|
| 91 |
+
domain="bank77")
|
| 92 |
+
print(r["answers"]["intent"]) # 77-way choice with probabilities
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
## Usage (HTTP, what the Space runs)
|
| 96 |
+
|
| 97 |
+
```bash
|
| 98 |
+
curl -X POST http://localhost:7860/v1/systemone -H 'Content-Type: application/json' -d '{
|
| 99 |
+
"state": "Congratulations! You won a £1000 prize. Call now to claim!",
|
| 100 |
+
"questions": {"domain": {"type": "choice", "instructions": "",
|
| 101 |
+
"criteria": {"rt00": "support billing sales technical", "rt05": "text messages spam",
|
| 102 |
+
"...": "see datasets/schemas.json"}}},
|
| 103 |
+
"options": {"energy_norm": true, "defer_margin": 0.05}
|
| 104 |
+
}'
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
The server also exposes `/v1/health`, `/v1/models`, `/v1/deferrals`
|
| 108 |
+
(active-learning mirror) and per-call options `energy_norm`,
|
| 109 |
+
`salience_gating`, `miller_window`, `ngrams`, `defer_margin`, `evidence`.
|
| 110 |
+
|
| 111 |
+
## Docker (HuggingFace Spaces)
|
| 112 |
+
|
| 113 |
+
The included Dockerfile builds the engine from source and serves the v3 API
|
| 114 |
+
on port 7860.
|
| 115 |
+
|
| 116 |
+
## Training recipe (reproduce or extend)
|
| 117 |
+
|
| 118 |
+
See docs/EVALUATION.md §Reproduce. Corpus + tooling live in the main SyFox
|
| 119 |
+
repo (`tools/hf_fetch.py`, `tools/giant_prepare.py`, `tools/giant_bench.py`,
|
| 120 |
+
`tools/router_sweep.py`). Constraint discipline: hidden splits are
|
| 121 |
+
firewall-enforced (never taught, never calibrated on); all model/wording
|
| 122 |
+
selection happened on cal; the core physics was never modified.
|
| 123 |
+
|
| 124 |
+
## Limitations
|
| 125 |
+
|
| 126 |
+
- Single-router e2e is bottlenecked by 16-way choice in one fabric (measured;
|
| 127 |
+
wording sweep shows it is the readout mechanism, not the wording).
|
| 128 |
+
- 77-way banking intents need a dedicated fabric (or arbitration) at this
|
| 129 |
+
scale.
|
| 130 |
+
- Boolean passage comprehension is near-majority — the substrate reads
|
| 131 |
+
lexical fields, not logic.
|
| 132 |
+
- Zero-shot composition (constraints, topology) is NOT solved by scale —
|
| 133 |
+
see docs/ZEROSHOT.md for the measured two-dimension separation.
|
| 134 |
+
|
| 135 |
+
## License & credit
|
| 136 |
+
|
| 137 |
+
MIT © 2026 Mr-DS-ML-85. Core mechanics ported from the author's
|
| 138 |
+
Synthetic-Intelligence research substrate. Dataset licenses: see
|
| 139 |
+
datasets/DATASETS.md.
|
datasets/DATASETS.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Datasets — sources, splits, licenses
|
| 2 |
+
|
| 3 |
+
Every state string in this repo is verbatim dataset text. The only edits are
|
| 4 |
+
truncation (long fields capped) and label remapping to opaque anchors.
|
| 5 |
+
`MANIFEST.json` carries per-file SHA-256 and per-domain row counts; the
|
| 6 |
+
preparation recipe (and the three failure-mode fixes it bakes in) is in
|
| 7 |
+
`MANIFEST.json -> recipe`.
|
| 8 |
+
|
| 9 |
+
## Included corpora (16 domains)
|
| 10 |
+
|
| 11 |
+
| domain | source | train | cal | hidden | notes |
|
| 12 |
+
|---|---|---:|---:|---:|---|
|
| 13 |
+
| tickets_en | repo synthetic support corpus (data/big, SHA-256 manifest) | 8,400 | 1,800 | 1,800 | choice, 3 departments |
|
| 14 |
+
| tickets_bn/hi/ru | repo synthetic multilingual support corpus | 2,520-2,522 | 539-540 | 539-540 | bengali/devanagari/cyrillic substrates |
|
| 15 |
+
| game | repo synthetic game-command corpus | 5,600 | 1,200 | 1,200 | choice, 3 actions |
|
| 16 |
+
| guard | repo synthetic guardrail corpus | 5,600 | 1,200 | 1,200 | noul (irreversible, off_task) + choice (scope); original schema kept verbatim |
|
| 17 |
+
| bank77 | [PolyAI banking77](https://github.com/PolyAI-LDN/task-specific-dialogues) official splits | 9,000 | 1,003 | 3,080 | 77 intents, official test = hidden |
|
| 18 |
+
| sms | [UCI SMS Spam Collection](https://archive.ics.uci.edu/dataset/228/sms+spam+collection) | 3,900 | 836 | 838 | free-for-research corpus |
|
| 19 |
+
| clinc | [clinc/clinc_oos](https://huggingface.co/datasets/clinc/clinc_oos) (plus config) | 10,000 | 3,000 | 4,500 | 151 intents incl. out-of-scope |
|
| 20 |
+
| enron | [SetFit/enron_spam](https://huggingface.co/datasets/SetFit/enron_spam) | 6,000 | 758 | 1,113 | cal/hidden carved from official test, disjoint |
|
| 21 |
+
| emotion | [dair-ai/emotion](https://huggingface.co/datasets/dair-ai/emotion) | 6,000 | 700 | 2,000 | 6 emotions |
|
| 22 |
+
| hate | [tdavidson/hate_speech_offensive](https://huggingface.co/datasets/tdavidson/hate_speech_offensive) | 4,078 | 400 | 1,500 | official train only -> stratified carve (seed 77); offensive class capped at 2,500 in train, natural distribution in eval |
|
| 23 |
+
| agnews | [fancyzhx/ag_news](https://huggingface.co/datasets/fancyzhx/ag_news) | 6,000 | 400 | 2,000 | 4 topics; cal carved from train |
|
| 24 |
+
| polarity | [fancyzhx/amazon_polarity](https://huggingface.co/datasets/fancyzhx/amazon_polarity) | 6,000 | 400 | 2,000 | 2 classes; cal carved from train |
|
| 25 |
+
| dbpedia | [fancyzhx/dbpedia_14](https://huggingface.co/datasets/fancyzhx/dbpedia_14) | 6,000 | 400 | 2,000 | 14 entity classes |
|
| 26 |
+
| boolq | [google/boolq](https://huggingface.co/datasets/google/boolq) | 6,000 | 500 | 1,500 | question+passage, boolean choice; cal+hidden carved from official validation |
|
| 27 |
+
|
| 28 |
+
Total: 76,142 train rows (152,284 lessons per epoch; the shipped model was
|
| 29 |
+
trained ONE interleaved pass — see docs/EVALUATION.md §Honest reading for
|
| 30 |
+
the consolidation analysis).
|
| 31 |
+
|
| 32 |
+
## Split discipline
|
| 33 |
+
|
| 34 |
+
- Hidden files carry `_hidden` in their names; the M1 firewall refuses them
|
| 35 |
+
for `learn` and `calibrate` (hidden rows never teach and never set
|
| 36 |
+
calibration scalars).
|
| 37 |
+
- cal and hidden are disjoint per domain (enforced in `tools/giant_prepare.py`);
|
| 38 |
+
cal feeds per-script temperature/Platt fitting only.
|
| 39 |
+
- Model/flag selection stays on cal; hidden is scored once for the report.
|
| 40 |
+
|
| 41 |
+
## File format (eval + cal)
|
| 42 |
+
|
| 43 |
+
The shipped `eval/*_hidden.jsonl` and `cal_*.jsonl` rows are SCHEMA-FREE:
|
| 44 |
+
`{"state", "domain", "labels"}` (guard/noul rows also carry their
|
| 45 |
+
`questions` inline, since noul instructions are the probe carrier). The
|
| 46 |
+
question objects (router + class criteria) are rebuilt from
|
| 47 |
+
`schemas.json` — see `build_questions()` in the main repo's
|
| 48 |
+
`tools/giant_bench.py`. This keeps the repo small; the full-schema corpus
|
| 49 |
+
regenerates via `tools/giant_prepare.py` in the main SyFox repo.
|
| 50 |
+
|
| 51 |
+
## Licenses
|
| 52 |
+
|
| 53 |
+
- SyFox engine: MIT (see LICENSE).
|
| 54 |
+
- bank77: released by PolyAI for research (check the repository for the
|
| 55 |
+
current license text).
|
| 56 |
+
- UCI SMS Spam Collection: free for research with attribution.
|
| 57 |
+
- HuggingFace datasets (clinc_oos, enron_spam, emotion, hate_speech_offensive,
|
| 58 |
+
ag_news, amazon_polarity, dbpedia_14, boolq): each retains its original
|
| 59 |
+
publisher license — consult the dataset page before redistributing or
|
| 60 |
+
commercial use.
|
| 61 |
+
- The repo synthetic corpora are original generated data (MIT, same as the
|
| 62 |
+
engine).
|
datasets/MANIFEST.json
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"seed": 77,
|
| 3 |
+
"recipe": {
|
| 4 |
+
"instructions": "empty on every row (Failure-2 fix)",
|
| 5 |
+
"anchors": "globally-unique opaque per-class anchors (Failure-3 fix)",
|
| 6 |
+
"train_order": "round-robin domain interleave (Failure-1 fix)",
|
| 7 |
+
"epochs": 3,
|
| 8 |
+
"criteria": "existing domains verbatim (keys remapped); new HF domains mined top-20 from train only"
|
| 9 |
+
},
|
| 10 |
+
"sources": {
|
| 11 |
+
"big": "data/big/* synthetic corpora (SHA-256 MANIFEST.json)",
|
| 12 |
+
"bank77": "PolyAI banking77 official splits",
|
| 13 |
+
"sms": "UCI SMS Spam Collection",
|
| 14 |
+
"hf": [
|
| 15 |
+
"clinc/clinc_oos",
|
| 16 |
+
"SetFit/enron_spam",
|
| 17 |
+
"dair-ai/emotion",
|
| 18 |
+
"tdavidson/hate_speech_offensive",
|
| 19 |
+
"fancyzhx/ag_news",
|
| 20 |
+
"fancyzhx/amazon_polarity",
|
| 21 |
+
"fancyzhx/dbpedia_14",
|
| 22 |
+
"google/boolq"
|
| 23 |
+
]
|
| 24 |
+
},
|
| 25 |
+
"domains": [
|
| 26 |
+
{
|
| 27 |
+
"domain": "agnews",
|
| 28 |
+
"source": "hf",
|
| 29 |
+
"train": 6000,
|
| 30 |
+
"cal": 400,
|
| 31 |
+
"hidden": 2000,
|
| 32 |
+
"classes": 4
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"domain": "bank77",
|
| 36 |
+
"source": "bank77",
|
| 37 |
+
"train": 9000,
|
| 38 |
+
"cal": 1003,
|
| 39 |
+
"hidden": 3080,
|
| 40 |
+
"classes": 77
|
| 41 |
+
},
|
| 42 |
+
{
|
| 43 |
+
"domain": "boolq",
|
| 44 |
+
"source": "hf",
|
| 45 |
+
"train": 6000,
|
| 46 |
+
"cal": 500,
|
| 47 |
+
"hidden": 1500,
|
| 48 |
+
"classes": 2
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"domain": "clinc",
|
| 52 |
+
"source": "hf",
|
| 53 |
+
"train": 10000,
|
| 54 |
+
"cal": 3000,
|
| 55 |
+
"hidden": 4500,
|
| 56 |
+
"classes": 151
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"domain": "dbpedia",
|
| 60 |
+
"source": "hf",
|
| 61 |
+
"train": 6000,
|
| 62 |
+
"cal": 400,
|
| 63 |
+
"hidden": 2000,
|
| 64 |
+
"classes": 14
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
"domain": "emotion",
|
| 68 |
+
"source": "hf",
|
| 69 |
+
"train": 6000,
|
| 70 |
+
"cal": 700,
|
| 71 |
+
"hidden": 2000,
|
| 72 |
+
"classes": 6
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"domain": "enron",
|
| 76 |
+
"source": "hf",
|
| 77 |
+
"train": 6000,
|
| 78 |
+
"cal": 758,
|
| 79 |
+
"hidden": 1113,
|
| 80 |
+
"classes": 2
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"domain": "game",
|
| 84 |
+
"source": "big",
|
| 85 |
+
"train": 5600,
|
| 86 |
+
"cal": 1200,
|
| 87 |
+
"hidden": 1200,
|
| 88 |
+
"classes": 3
|
| 89 |
+
},
|
| 90 |
+
{
|
| 91 |
+
"domain": "guard",
|
| 92 |
+
"source": "big",
|
| 93 |
+
"schema": "noul_multi",
|
| 94 |
+
"train": 5600,
|
| 95 |
+
"cal": 1200,
|
| 96 |
+
"hidden": 1200,
|
| 97 |
+
"classes": 2
|
| 98 |
+
},
|
| 99 |
+
{
|
| 100 |
+
"domain": "hate",
|
| 101 |
+
"source": "hf",
|
| 102 |
+
"train": 4078,
|
| 103 |
+
"cal": 400,
|
| 104 |
+
"hidden": 1500,
|
| 105 |
+
"classes": 3
|
| 106 |
+
},
|
| 107 |
+
{
|
| 108 |
+
"domain": "polarity",
|
| 109 |
+
"source": "hf",
|
| 110 |
+
"train": 6000,
|
| 111 |
+
"cal": 400,
|
| 112 |
+
"hidden": 2000,
|
| 113 |
+
"classes": 2
|
| 114 |
+
},
|
| 115 |
+
{
|
| 116 |
+
"domain": "sms",
|
| 117 |
+
"source": "sms",
|
| 118 |
+
"train": 3900,
|
| 119 |
+
"cal": 836,
|
| 120 |
+
"hidden": 838,
|
| 121 |
+
"classes": 2
|
| 122 |
+
},
|
| 123 |
+
{
|
| 124 |
+
"domain": "tickets_bn",
|
| 125 |
+
"source": "big",
|
| 126 |
+
"train": 2520,
|
| 127 |
+
"cal": 540,
|
| 128 |
+
"hidden": 540,
|
| 129 |
+
"classes": 3
|
| 130 |
+
},
|
| 131 |
+
{
|
| 132 |
+
"domain": "tickets_en",
|
| 133 |
+
"source": "big",
|
| 134 |
+
"train": 8400,
|
| 135 |
+
"cal": 1800,
|
| 136 |
+
"hidden": 1800,
|
| 137 |
+
"classes": 3
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"domain": "tickets_hi",
|
| 141 |
+
"source": "big",
|
| 142 |
+
"train": 2522,
|
| 143 |
+
"cal": 539,
|
| 144 |
+
"hidden": 539,
|
| 145 |
+
"classes": 3
|
| 146 |
+
},
|
| 147 |
+
{
|
| 148 |
+
"domain": "tickets_ru",
|
| 149 |
+
"source": "big",
|
| 150 |
+
"train": 2522,
|
| 151 |
+
"cal": 539,
|
| 152 |
+
"hidden": 539,
|
| 153 |
+
"classes": 3
|
| 154 |
+
}
|
| 155 |
+
],
|
| 156 |
+
"train_rows": 90142,
|
| 157 |
+
"lessons_per_epoch": 180284,
|
| 158 |
+
"files": {
|
| 159 |
+
"agnews_hidden.jsonl": {
|
| 160 |
+
"bytes": 4490261,
|
| 161 |
+
"sha256": "9f739195bd4878fe0d25beaac852249ad723f7bf31c82da8a3c4bcb0006ab40f"
|
| 162 |
+
},
|
| 163 |
+
"bank77_hidden.jsonl": {
|
| 164 |
+
"bytes": 62681822,
|
| 165 |
+
"sha256": "2dbee3513d6a8ee1248fd1d4f1c81c059d24bfa77883699881b0770344e660a9"
|
| 166 |
+
},
|
| 167 |
+
"boolq_hidden.jsonl": {
|
| 168 |
+
"bytes": 2373267,
|
| 169 |
+
"sha256": "b75ae17110d58161391a34ff689130a866d408c028130dfa6864f10e95ebb294"
|
| 170 |
+
},
|
| 171 |
+
"cal_bengali.jsonl": {
|
| 172 |
+
"bytes": 792247,
|
| 173 |
+
"sha256": "a8e10e6d45f8b505e076f69eb5d2d44ef8924ac31e11b46deadaae6ab894c401"
|
| 174 |
+
},
|
| 175 |
+
"cal_cyrillic.jsonl": {
|
| 176 |
+
"bytes": 765001,
|
| 177 |
+
"sha256": "1c877a91a1240fd8e13fd38b2ba38730a094dd4fdc696f8021a166bf2202fb3d"
|
| 178 |
+
},
|
| 179 |
+
"cal_devanagari.jsonl": {
|
| 180 |
+
"bytes": 788664,
|
| 181 |
+
"sha256": "5cf6d54114209ef6e0a25afc863ed913acb7e411a26fafe1de43aeaba2c5a02c"
|
| 182 |
+
},
|
| 183 |
+
"cal_latin.jsonl": {
|
| 184 |
+
"bytes": 146749472,
|
| 185 |
+
"sha256": "144816b7615f58305316afe71a3bb4cc1e7c0c635ac191852f80dc1e8158bf26"
|
| 186 |
+
},
|
| 187 |
+
"clinc_hidden.jsonl": {
|
| 188 |
+
"bytes": 165870637,
|
| 189 |
+
"sha256": "660298142007d00443d7be7f79dffefd30b83b4317b8f579e20d3961b1360e89"
|
| 190 |
+
},
|
| 191 |
+
"dbpedia_hidden.jsonl": {
|
| 192 |
+
"bytes": 10275566,
|
| 193 |
+
"sha256": "fa350aa3812015f3425eb6f789f9e4880391e532dbfeec3a19f623966a03a412"
|
| 194 |
+
},
|
| 195 |
+
"emotion_hidden.jsonl": {
|
| 196 |
+
"bytes": 5309173,
|
| 197 |
+
"sha256": "e3fa2524d8f2fbe2d1dc0ac2217c7d20a0b911be4d4fdd93b1a6b6154f4af3f0"
|
| 198 |
+
},
|
| 199 |
+
"enron_hidden.jsonl": {
|
| 200 |
+
"bytes": 2189607,
|
| 201 |
+
"sha256": "121870e06d32c8f9c764263e1e06a31d6aaada7c1106299d337227fdb7468596"
|
| 202 |
+
},
|
| 203 |
+
"game_hidden.jsonl": {
|
| 204 |
+
"bytes": 1639567,
|
| 205 |
+
"sha256": "9f0216434e2846f8c81447987f898a8e8fc8b1094a0f8264901fe076171a8a5c"
|
| 206 |
+
},
|
| 207 |
+
"guard_hidden.jsonl": {
|
| 208 |
+
"bytes": 1932469,
|
| 209 |
+
"sha256": "60b36942383f1fa5fc27e029d0549b0f820b0664d077505801e91aa2b919d715"
|
| 210 |
+
},
|
| 211 |
+
"hate_hidden.jsonl": {
|
| 212 |
+
"bytes": 2680637,
|
| 213 |
+
"sha256": "2bd68f7e06d6752885e212fb2bd94cb5075f56d87ef3c9dea5781718547eade7"
|
| 214 |
+
},
|
| 215 |
+
"polarity_hidden.jsonl": {
|
| 216 |
+
"bytes": 3934787,
|
| 217 |
+
"sha256": "7e8b07a7b7d6c7cfdeef38ef68dc01b9c8403af238b230a15627611dcabdaa4a"
|
| 218 |
+
},
|
| 219 |
+
"probes.jsonl": {
|
| 220 |
+
"bytes": 275469,
|
| 221 |
+
"sha256": "3bfea503edce2ab7e7d48c7803f2c0d8c54d387e2f6a4279ccf9d4f77e9b7b8c"
|
| 222 |
+
},
|
| 223 |
+
"sms_hidden.jsonl": {
|
| 224 |
+
"bytes": 1133250,
|
| 225 |
+
"sha256": "3ec668f86b4a00fdf4b9dd951d9a958e2246a3841ca74342906dee93aedce1f9"
|
| 226 |
+
},
|
| 227 |
+
"tickets_bn_hidden.jsonl": {
|
| 228 |
+
"bytes": 791305,
|
| 229 |
+
"sha256": "ed33e7b579e0907eb76569a9cec23c1a90b4db5d52eadbabe7ec32bf89ba7cb0"
|
| 230 |
+
},
|
| 231 |
+
"tickets_en_hidden.jsonl": {
|
| 232 |
+
"bytes": 2451264,
|
| 233 |
+
"sha256": "4b59830b4805d2d028cbf96af0894dc2dcd834f4f776c72aa3eb9b7c7d716d7c"
|
| 234 |
+
},
|
| 235 |
+
"tickets_hi_hidden.jsonl": {
|
| 236 |
+
"bytes": 786621,
|
| 237 |
+
"sha256": "5df8b1ee2c0b2b1ef402a6eb78fa9b0a7b41abb699c525a381ff8ec4d31e9d77"
|
| 238 |
+
},
|
| 239 |
+
"tickets_ru_hidden.jsonl": {
|
| 240 |
+
"bytes": 762351,
|
| 241 |
+
"sha256": "a7e759bd734665d6468b9d3b2950192e2c3bdabe21c4ed34433650296192abc6"
|
| 242 |
+
},
|
| 243 |
+
"train.jsonl": {
|
| 244 |
+
"bytes": 696826848,
|
| 245 |
+
"sha256": "a9e24b1cbc48b7cd51130792df1ea42f4db1fd4b36de2d48522ef25f744795bd"
|
| 246 |
+
},
|
| 247 |
+
"schemas.json": {
|
| 248 |
+
"bytes": 77208,
|
| 249 |
+
"sha256": "4569b69fddf44db4f83a901c486a3e9680b806726dcb839861ea9c9ecebb7bd3"
|
| 250 |
+
}
|
| 251 |
+
}
|
| 252 |
+
}
|
datasets/cal_bengali.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/cal_cyrillic.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/cal_devanagari.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/cal_latin.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/eval/agnews_hidden.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/eval/bank77_hidden.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/eval/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": 13.8,
|
| 10 |
+
"ms_per_row": 7.65,
|
| 11 |
+
"qkey": "department",
|
| 12 |
+
"note": ""
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"domain": "bank77",
|
| 16 |
+
"n": 3080,
|
| 17 |
+
"router_acc": 0.9314935064935065,
|
| 18 |
+
"class_acc": 0.023376623376623377,
|
| 19 |
+
"e2e_acc": 0.02207792207792208,
|
| 20 |
+
"deferred": 0,
|
| 21 |
+
"secs": 32.3,
|
| 22 |
+
"ms_per_row": 10.47,
|
| 23 |
+
"qkey": "intent",
|
| 24 |
+
"note": ""
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"domain": "sms",
|
| 28 |
+
"n": 838,
|
| 29 |
+
"router_acc": 0.23269689737470167,
|
| 30 |
+
"class_acc": 0.7523923444976076,
|
| 31 |
+
"e2e_acc": 0.22195704057279236,
|
| 32 |
+
"deferred": 2,
|
| 33 |
+
"secs": 5.4,
|
| 34 |
+
"ms_per_row": 6.42,
|
| 35 |
+
"qkey": "intent",
|
| 36 |
+
"note": ""
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"domain": "clinc",
|
| 40 |
+
"n": 4500,
|
| 41 |
+
"router_acc": 0.3342222222222222,
|
| 42 |
+
"class_acc": 0.30933333333333335,
|
| 43 |
+
"e2e_acc": 0.1228888888888889,
|
| 44 |
+
"deferred": 0,
|
| 45 |
+
"secs": 49.6,
|
| 46 |
+
"ms_per_row": 11.02,
|
| 47 |
+
"qkey": "intent",
|
| 48 |
+
"note": ""
|
| 49 |
+
},
|
| 50 |
+
{
|
| 51 |
+
"domain": "enron",
|
| 52 |
+
"n": 1110,
|
| 53 |
+
"router_acc": 0.39369369369369367,
|
| 54 |
+
"class_acc": 0.7522522522522522,
|
| 55 |
+
"e2e_acc": 0.3225225225225225,
|
| 56 |
+
"deferred": 0,
|
| 57 |
+
"secs": 7.5,
|
| 58 |
+
"ms_per_row": 6.79,
|
| 59 |
+
"qkey": "spam",
|
| 60 |
+
"note": ""
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"domain": "emotion",
|
| 64 |
+
"n": 2000,
|
| 65 |
+
"router_acc": 0.155,
|
| 66 |
+
"class_acc": 0.2495,
|
| 67 |
+
"e2e_acc": 0.073,
|
| 68 |
+
"deferred": 0,
|
| 69 |
+
"secs": 13.5,
|
| 70 |
+
"ms_per_row": 6.76,
|
| 71 |
+
"qkey": "emotion",
|
| 72 |
+
"note": ""
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"domain": "hate",
|
| 76 |
+
"n": 1500,
|
| 77 |
+
"router_acc": 0.38133333333333336,
|
| 78 |
+
"class_acc": 0.6526666666666666,
|
| 79 |
+
"e2e_acc": 0.2773333333333333,
|
| 80 |
+
"deferred": 0,
|
| 81 |
+
"secs": 9.8,
|
| 82 |
+
"ms_per_row": 6.52,
|
| 83 |
+
"qkey": "speech",
|
| 84 |
+
"note": ""
|
| 85 |
+
},
|
| 86 |
+
{
|
| 87 |
+
"domain": "agnews",
|
| 88 |
+
"n": 2000,
|
| 89 |
+
"router_acc": 0.3195,
|
| 90 |
+
"class_acc": 0.604,
|
| 91 |
+
"e2e_acc": 0.206,
|
| 92 |
+
"deferred": 0,
|
| 93 |
+
"secs": 14.0,
|
| 94 |
+
"ms_per_row": 7.02,
|
| 95 |
+
"qkey": "topic",
|
| 96 |
+
"note": ""
|
| 97 |
+
},
|
| 98 |
+
{
|
| 99 |
+
"domain": "polarity",
|
| 100 |
+
"n": 2000,
|
| 101 |
+
"router_acc": 0.339,
|
| 102 |
+
"class_acc": 0.5705,
|
| 103 |
+
"e2e_acc": 0.189,
|
| 104 |
+
"deferred": 0,
|
| 105 |
+
"secs": 13.0,
|
| 106 |
+
"ms_per_row": 6.52,
|
| 107 |
+
"qkey": "sentiment",
|
| 108 |
+
"note": ""
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"domain": "dbpedia",
|
| 112 |
+
"n": 2000,
|
| 113 |
+
"router_acc": 0.4025,
|
| 114 |
+
"class_acc": 0.4755,
|
| 115 |
+
"e2e_acc": 0.2045,
|
| 116 |
+
"deferred": 0,
|
| 117 |
+
"secs": 15.1,
|
| 118 |
+
"ms_per_row": 7.55,
|
| 119 |
+
"qkey": "entity",
|
| 120 |
+
"note": ""
|
| 121 |
+
},
|
| 122 |
+
{
|
| 123 |
+
"domain": "boolq",
|
| 124 |
+
"n": 1500,
|
| 125 |
+
"router_acc": 0.09733333333333333,
|
| 126 |
+
"class_acc": 0.5313333333333333,
|
| 127 |
+
"e2e_acc": 0.058666666666666666,
|
| 128 |
+
"deferred": 0,
|
| 129 |
+
"secs": 9.3,
|
| 130 |
+
"ms_per_row": 6.18,
|
| 131 |
+
"qkey": "truth",
|
| 132 |
+
"note": ""
|
| 133 |
+
}
|
| 134 |
+
]
|
datasets/eval/boolq_hidden.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/eval/clinc_hidden.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/eval/dbpedia_hidden.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/eval/dump_pass1.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/eval/emotion_hidden.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/eval/enron_hidden.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/eval/game_hidden.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/eval/guard_hidden.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/eval/hate_hidden.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/eval/polarity_hidden.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/eval/sms_hidden.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/eval/tickets_bn_hidden.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/eval/tickets_en_hidden.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/eval/tickets_hi_hidden.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/eval/tickets_ru_hidden.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/probes.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
datasets/router_criteria.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"winner_level": 0,
|
| 3 |
+
"cal_acc": [
|
| 4 |
+
0.42646153846153845,
|
| 5 |
+
0.1636923076923077,
|
| 6 |
+
0.07876923076923077,
|
| 7 |
+
0.208
|
| 8 |
+
],
|
| 9 |
+
"criteria": {
|
| 10 |
+
"rt00": "news headlines sports",
|
| 11 |
+
"rt01": "banking cards payments",
|
| 12 |
+
"rt02": "boolean question passage",
|
| 13 |
+
"rt03": "assistant requests weather",
|
| 14 |
+
"rt04": "encyclopedia entities topics",
|
| 15 |
+
"rt05": "feelings emotions reactions",
|
| 16 |
+
"rt06": "email inbox messages",
|
| 17 |
+
"rt07": "game commands actions",
|
| 18 |
+
"rt08": "safety destructive irreversible",
|
| 19 |
+
"rt09": "social offensive posts",
|
| 20 |
+
"rt10": "product reviews opinions",
|
| 21 |
+
"rt11": "text messages spam",
|
| 22 |
+
"rt13": "support billing sales technical"
|
| 23 |
+
},
|
| 24 |
+
"note": "selected on cal subsample only; hidden untouched"
|
| 25 |
+
}
|
datasets/schemas.json
ADDED
|
@@ -0,0 +1,761 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"domains": {
|
| 3 |
+
"agnews": {
|
| 4 |
+
"qkey": "topic",
|
| 5 |
+
"source": "hf",
|
| 6 |
+
"classes": {
|
| 7 |
+
"ag00": "world",
|
| 8 |
+
"ag01": "sports",
|
| 9 |
+
"ag02": "business",
|
| 10 |
+
"ag03": "scitech"
|
| 11 |
+
},
|
| 12 |
+
"criteria": {
|
| 13 |
+
"ag02": "aspx, aspx ticker, com fullquote, fullquote, fullquote aspx, fullquote gt, investor reuters, quickinfo, quickinfo fullquote, reuters com, stocks quickinfo, target stocks, www investor, n target, inflation, futures, mortgage, interest rates, cbs mw, dow jones",
|
| 14 |
+
"ag03": "desktop, browser, processor, spacecraft, face verdana, font, font face, lt font, ms sans, msn, sans, verdana, verdana ms, 2 color, 666666, 666666 gt, arial, arial helvetica, color 666666, helvetica",
|
| 15 |
+
"ag01": "sports network, nba, quarterback, champions league, soccer, tennis, boston red, masters, finals, touchdowns, cardinals, championship series, playoff, the champions, trophy, champions, cup, angels, athens reuters, beat the",
|
| 16 |
+
"ag00": "palestinian, baghdad, hostage, gaza, darfur, militants, sudan, afghan, arafat, abu, islamic, yasser, blair, were killed, north korea, hostages, insurgents, kidnapped, palestinians, suicide"
|
| 17 |
+
},
|
| 18 |
+
"router_anchor": "rt00"
|
| 19 |
+
},
|
| 20 |
+
"bank77": {
|
| 21 |
+
"qkey": "intent",
|
| 22 |
+
"source": "bank77",
|
| 23 |
+
"classes": {
|
| 24 |
+
"c00": "Refund_not_showing_up",
|
| 25 |
+
"c01": "activate_my_card",
|
| 26 |
+
"c02": "age_limit",
|
| 27 |
+
"c03": "apple_pay_or_google_pay",
|
| 28 |
+
"c04": "atm_support",
|
| 29 |
+
"c05": "automatic_top_up",
|
| 30 |
+
"c06": "balance_not_updated_after_bank_transfer",
|
| 31 |
+
"c07": "balance_not_updated_after_cheque_or_cash_deposit",
|
| 32 |
+
"c08": "beneficiary_not_allowed",
|
| 33 |
+
"c09": "cancel_transfer",
|
| 34 |
+
"c10": "card_about_to_expire",
|
| 35 |
+
"c11": "card_acceptance",
|
| 36 |
+
"c12": "card_arrival",
|
| 37 |
+
"c13": "card_delivery_estimate",
|
| 38 |
+
"c14": "card_linking",
|
| 39 |
+
"c15": "card_not_working",
|
| 40 |
+
"c16": "card_payment_fee_charged",
|
| 41 |
+
"c17": "card_payment_not_recognised",
|
| 42 |
+
"c18": "card_payment_wrong_exchange_rate",
|
| 43 |
+
"c19": "card_swallowed",
|
| 44 |
+
"c20": "cash_withdrawal_charge",
|
| 45 |
+
"c21": "cash_withdrawal_not_recognised",
|
| 46 |
+
"c22": "change_pin",
|
| 47 |
+
"c23": "compromised_card",
|
| 48 |
+
"c24": "contactless_not_working",
|
| 49 |
+
"c25": "country_support",
|
| 50 |
+
"c26": "declined_card_payment",
|
| 51 |
+
"c27": "declined_cash_withdrawal",
|
| 52 |
+
"c28": "declined_transfer",
|
| 53 |
+
"c29": "direct_debit_payment_not_recognised",
|
| 54 |
+
"c30": "disposable_card_limits",
|
| 55 |
+
"c31": "edit_personal_details",
|
| 56 |
+
"c32": "exchange_charge",
|
| 57 |
+
"c33": "exchange_rate",
|
| 58 |
+
"c34": "exchange_via_app",
|
| 59 |
+
"c35": "extra_charge_on_statement",
|
| 60 |
+
"c36": "failed_transfer",
|
| 61 |
+
"c37": "fiat_currency_support",
|
| 62 |
+
"c38": "get_disposable_virtual_card",
|
| 63 |
+
"c39": "get_physical_card",
|
| 64 |
+
"c40": "getting_spare_card",
|
| 65 |
+
"c41": "getting_virtual_card",
|
| 66 |
+
"c42": "lost_or_stolen_card",
|
| 67 |
+
"c43": "lost_or_stolen_phone",
|
| 68 |
+
"c44": "order_physical_card",
|
| 69 |
+
"c45": "passcode_forgotten",
|
| 70 |
+
"c46": "pending_card_payment",
|
| 71 |
+
"c47": "pending_cash_withdrawal",
|
| 72 |
+
"c48": "pending_top_up",
|
| 73 |
+
"c49": "pending_transfer",
|
| 74 |
+
"c50": "pin_blocked",
|
| 75 |
+
"c51": "receiving_money",
|
| 76 |
+
"c52": "request_refund",
|
| 77 |
+
"c53": "reverted_card_payment?",
|
| 78 |
+
"c54": "supported_cards_and_currencies",
|
| 79 |
+
"c55": "terminate_account",
|
| 80 |
+
"c56": "top_up_by_bank_transfer_charge",
|
| 81 |
+
"c57": "top_up_by_card_charge",
|
| 82 |
+
"c58": "top_up_by_cash_or_cheque",
|
| 83 |
+
"c59": "top_up_failed",
|
| 84 |
+
"c60": "top_up_limits",
|
| 85 |
+
"c61": "top_up_reverted",
|
| 86 |
+
"c62": "topping_up_by_card",
|
| 87 |
+
"c63": "transaction_charged_twice",
|
| 88 |
+
"c64": "transfer_fee_charged",
|
| 89 |
+
"c65": "transfer_into_account",
|
| 90 |
+
"c66": "transfer_not_received_by_recipient",
|
| 91 |
+
"c67": "transfer_timing",
|
| 92 |
+
"c68": "unable_to_verify_identity",
|
| 93 |
+
"c69": "verify_my_identity",
|
| 94 |
+
"c70": "verify_source_of_funds",
|
| 95 |
+
"c71": "verify_top_up",
|
| 96 |
+
"c72": "virtual_card_not_working",
|
| 97 |
+
"c73": "visa_or_mastercard",
|
| 98 |
+
"c74": "why_verify_identity",
|
| 99 |
+
"c75": "wrong_amount_of_cash_received",
|
| 100 |
+
"c76": "wrong_exchange_rate_for_cash_withdrawal"
|
| 101 |
+
},
|
| 102 |
+
"criteria": {
|
| 103 |
+
"c00": "refund in, refund is, my refund, contacted the, keep checking, refund has, requested a, i contacted, refund i, refund isn't, refund me, seller for, merchant a, refund a, refund showing, refund yet, statements but, refund from, refund but, be getting",
|
| 104 |
+
"c01": "activating, activate my, activating my, activation, activate it, activated, card activated, to activate, card activation, the activation, be activated, for activating, activate, me activate, start using, with activating, activate card, activation of, few seconds, seconds",
|
| 105 |
+
"c02": "children, how old, age limit, be to, kids, my children, old do, my kids, child, i open, my child, an age, the age, minimum, minimum age, what age, age, age can, for children, opening",
|
| 106 |
+
"c03": "google pay, apple pay, watch, apple watch, my apple, apple, google, my google, pay top, in apple, with google, express in, with apple, watch to, pay why, play, google play, pay is, an apple, does google",
|
| 107 |
+
"c04": "which atms, atms accept, atms can, closest, the closest, atms that, closest atm, atms take, can withdraw, of atms, what atms, what atm, that accept, atm's, mastercard atm, take this, atms, accept this, at which, the atms",
|
| 108 |
+
"c05": "auto, auto top, the auto, an auto, i auto, low, money automatically, up automatically, for auto, intervals, up feature, automatically, automatic top, automatically top, be traveling, up option, automatically while, certain intervals, in certain, low on",
|
| 109 |
+
"c06": "uk account, a uk, from france, my uk, international transfers, france two, take longer, uk bank, france a, reflect my, transfers usually, updated to, france, alright, couple hours, and nothing, have transferred, sure everything, you i, made one",
|
| 110 |
+
"c07": "deposited a, cheque but, i deposited, cheque deposit, check yesterday, deposit showing, deposited cash, deposited this, or cash, the cheque, after depositing, cheque yesterday, deposit i, deposited some, deposited, already sent, and cash, and im, check deposit, deposit but",
|
| 111 |
+
"c08": "a beneficiary, my beneficiary, beneficiary, not possible, beneficiary not, some crypto, transferring to, a beneficiery, beneficiary is, beneficiery, couldn't transfer, getting error, isn't possible, purchase some, tried transferring, not allowed, error message, i doing, i've done, wasn't allowed",
|
| 112 |
+
"c09": "wrong account, tomorrow, by tomorrow, to revert, a typo, typo, to reverse, me cancel, typo please, accidently, correct i, i accidently, it correct, it needs, just realized, mistake please, mistake when, pay it, realized, stop a",
|
| 113 |
+
"c10": "expire, expires, to expire, about to, card expires, in china, expired, expiration, expiring, expiration date, is expiring, it expires, will expire, is about, expire soon, expired card, expires soon, the expiration, an expired, card mine",
|
| 114 |
+
"c11": "businesses, businesses that, to where, card accepted, accepts, will accept, be accepted, limits to, accept this, i pay, pay with, accept my, places, where i, anywhere, this card, card will, can use, accepted, will be",
|
| 115 |
+
"c12": "tracking, tracking number, you sent, a tracking, to track, card you, number for, track my, was issued, been delivered, mail yet, ordered it, recieve, recieve my, the expected, the tracking, track, track the, card hasn't, i track",
|
| 116 |
+
"c13": "delivered on, delivery to, it delivered, deliver to, certain date, is delivery, specific date, to deliver, delivery time, to come, deliver, a specific, expect my, the delivery, delivery, delivered, be delivered, specific, get here, long is",
|
| 117 |
+
"c14": "reactivate, to link, link, found it, i reactivate, jacket, link it, my jacket, reactivate my, to reactivate, link the, link a, reactivate it, i link, had lost, but found, found my, i previously, in app, jacket pocket",
|
| 118 |
+
"c15": "working anymore, restaurant today, any transactions, card doesn't, broke, is broken, my physical, declined at, what's wrong, card won't, working at, broken, won't my, anymore, card work, won't work, why won't, card isn't, restaurant, a restaurant",
|
| 119 |
+
"c16": "for payments, for card, for paying, when paying, paid with, warned, warned about, when you, on some, paying by, these fees, transactions but, wasn't warned, when buying, with card, didn't know, paying with, fee added, noticed an, paying",
|
| 120 |
+
"c17": "of payments, card shown, couple payments, the name, make myself, maybe someone, shown in, that name, are a, been coming, days can, days that, myself what's, really didn't, seen that, some payments, unknown payment, has access, payments with, card there",
|
| 121 |
+
"c18": "last saturday, russian, official, official interbank, the official, ruble, russian ruble, uk pounds, charged the, using is, rate on, payment last, purchase was, rate that, really bad, rubles, saturday i, this can't, saturday, interbank",
|
| 122 |
+
"c19": "swallowed, card out, atm swallowed, atm took, atm ate, swallowed my, ate my, card back, ate, give my, machine didn't, took my, not give, return my, atm machine, kept, do now, card got, stuck, by the",
|
| 123 |
+
"c20": "for withdrawing, withdrawals i, atm fees, for atm, withdrawing money, always thought, charging for, fee with, i always, withdrawal fee, been free, cash withdrawals, was free, withdrawing, atm cash, recent atm, withdrawing cash, groceries, taking out, today after",
|
| 124 |
+
"c21": "500, a 500, 500 cash, copy, copy of, a copy, for 500, odd remote, remote, this withdrawal, a some, as someone, didn't withdraw, remote town, see cash, someone just, this cash, withdrawal help, withdrawal in, withdrawal on",
|
| 125 |
+
"c22": "cash machines, can change, pin can, pin without, me change, pin on, saw my, someone saw, new pin, pin at, vacation in, spain, bank to, change my, be changed, change it, in spain, pin and, machines, i change",
|
| 126 |
+
"c23": "card details, else is, are transactions, knowledge, make these, my knowledge, be using, my permission, transactions that, permission, these transactions, might be, card without, is using, hacked, someone used, someone may, without my, if someone, that someone",
|
| 127 |
+
"c24": "contactless, my contactless, contactless payments, a contactless, the contactless, i try, try, again, fix, it's not, not working, to work, payments, today, working, work, to use, new card, it's, at",
|
| 128 |
+
"c25": "what countries, i live, countries you, countries are, countries do, the countries, operate, you operate, live in, eu can, operate in, which countries, uk can, living, living in, located in, outside of, you available, countries, live",
|
| 129 |
+
"c26": "a shop, shop, card declined, keep trying, kept getting, out today, couldn't pay, declined this, forward, forward to, looking forward, sad, sad what's, to paying, today looking, payment didn't, been declined, tried several, card did, thought everything",
|
| 130 |
+
"c27": "hill, notting, notting hill, atm wouldn't, atm card, different atms, hill atm, the notting, two different, actually working, atm keeps, card actually, fine so, in notting, morning on, suddenly got, tried two, with withdraws, withdrawal cash, withdraws",
|
| 131 |
+
"c28": "decline message, transfer declined, a declined, again today, but same, declined transfer, online yesterday, recipient details, 'declined', states 'declined', transfers it's, well so, a decline, my transfers, checked all, transfer was, transfers keep, are getting, tried again, you keep",
|
| 132 |
+
"c29": "debit payment, direct debit, a direct, debit that, debit transaction, direct, to dispute, debit charge, debit i, debit in, debit, dispute a, didn't set, not used, of months, still dispute, dispute, a dispute, authorized, day please",
|
| 133 |
+
"c30": "of disposable, many disposable, one disposable, cards per, many transactions, several disposable, on disposable, restrictions for, cards every, every day, maximum number, transaction limit, transactions can, per, of transactions, the restrictions, per day, make several, disposable cards, cards i",
|
| 134 |
+
"c31": "edit, my address, personal details, edit my, married, i edit, address, got married, modify, modify my, my personal, moved and, new address, to edit, married and, to modify, change details, changed and, details in, i modify",
|
| 135 |
+
"c32": "for exchanging, discount, a discount, exchange fee, exchanging foreign, for currency, discounts, exchanging currency, currencies frequently, any discounts, discount for, frequent currency, discounts for, exchange fees, exchange foreign, currency exchanges, foreign currencies, exchanging, a lot, lot",
|
| 136 |
+
"c33": "rates are, what exchange, what your, exchange rates, determine, rate will, decide, find your, from where, me your, rates calculated, rates determined, what foreign, you determine, your exchange, rates, calculated, the foreign, how are, foreign exchange",
|
| 137 |
+
"c34": "aud, and gbp, usd and, for gbp, to gbp, exchange usd, usd to, app allow, between usd, to aud, usd, aud for, currencies using, currencies with, from usd, gbp to, i convert, usd for, aud how, exchange aud",
|
| 138 |
+
"c35": "1 charge, extra 1, a 1, extra pound, 1 fee, a pound, the 1, 1, 1 extra, one pound, charged 1, 1 on, appears as, pound charge, purchased anything, for 1, of 1, pound, 1l, additional pound",
|
| 139 |
+
"c36": "mortgage, a flat, mortgage payment, flat and, 5 times, my mortgage, transfer failed, keep failing, mortgage to, tried 5, buying a, error can, error i'm, failed transfer, flat but, initial, initial mortgage, to friends, transfer fail, 5",
|
| 140 |
+
"c37": "fiat, fiat currencies, multiple currencies, and exchange, holding and, which fiat, what fiat, for holding, hold money, to hold, flat currencies, to eur, holding, i hold, eur, and holding, in multiple, exchange and, the fiat, which flat",
|
| 141 |
+
"c38": "these disposable, cards work, how disposable, virtual disposable, create a, disposable virtual, a disposable, cards for, as well, disposable, virtual cards, the disposable, virtual, virtual card, disposable cards, create, well, disposable card, card for, card as",
|
| 142 |
+
"c39": "pin yet, locate my, pin sent, pin where, separately, card pin, a pin, pin anywhere, i locate, pin for, the pin, locate, pin is, find my, located, when do, pin, pin number, about the, anywhere",
|
| 143 |
+
"c40": "second card, more cards, for sending, out more, get another, more physical, sending out, another card, additional cards, spare, a spare, extra cards, member, send out, family member, few more, get more, give a, one card, spare card",
|
| 144 |
+
"c41": "those virtual, a virtual, card yet, of those, the virtual, my virtual, virtual card, virtual, those, virtual cards, about getting, get one, to order, getting a, receive a, order a, go about, find the, card how, order",
|
| 145 |
+
"c42": "a stolen, is stolen, stolen card, report, been stolen, been lost, is missing, stolen, someone stole, card has, stolen what, was stolen, stole my, i lost, lost my, stole, card what, lost, can't find, missing",
|
| 146 |
+
"c43": "phone was, phone is, phone what, mugged, the hotel, my phone, phone at, stolen yesterday, phone, app what, got mugged, mugged yesterday, someone from, stop someone, took everything, hotel, accessing, accessing my, from accessing, from using",
|
| 147 |
+
"c44": "cards delivered, a real, real, real card, a physical, an actual, order my, actual card, delivered to, physical card, actual, request a, physical, are cards, the cards, my own, physical cards, i order, own, like a",
|
| 148 |
+
"c45": "password, my password, passcode, my passcode, the passcode, forgotten, forgotten my, remember my, reset the, can't remember, forgot the, app passcode, can't log, my pass, pass code, passcode is, passcode won't, password is, to reset, get into",
|
| 149 |
+
"c46": "payment still, just showing, through at, payment pending, payment will, purchases from, since a, some point, days already, payment gone, show pending, status for, that hasn't, pending payment, be going, from pending, morning still, it actually, payment a, my purchases",
|
| 150 |
+
"c47": "withdrawal still, pending cash, transaction still, machine declined, withdrawal be, centre, city centre, progress can, this still, to still, withdrawal show, withdrawal shows, in progress, still shows, withdrawal to, still be, account says, the city, pending in, withdrawal is",
|
| 151 |
+
"c48": "new customer, half, half an, time today, your top, hour already, just shows, over an, up pending, an hour, customer and, instant, up gone, up hasn't, hour, up went, tried topping, i'm a, up be, fix it",
|
| 152 |
+
"c49": "transfer pending, eu transfers, money immediately, 2018, ago sent, do eu, immediately online, eu transfer, finally worked, for sure, it's 2018, right for, sure transfer, they're right, transfer still, pending transfer, seller says, finally, pending when, seller hasn't",
|
| 153 |
+
"c50": "unblock, unblock my, to unblock, i unblock, me unblock, unblocked, is blocked, pin tries, blocked can, pin wrong, unblock it, pin too, wrong pin, exceeded, pin unblocked, too many, blocked, blocked what, got blocked, have exceeded",
|
| 154 |
+
"c51": "salary, my salary, in gbp, salary is, employer, my employer, salary in, configure, gbp do, to configure, am paid, friend send, paid in, pay me, receive transfers, me money, friend to, transfer my, another currency, receive money",
|
| 155 |
+
"c52": "changed my, item refunded, to return, just bought, item yet, mind and, on something, refund back, refund policy, the product, back please, bought recently, decided, full refund, i return, item for, just cancel, my package, not paying, payment since",
|
| 156 |
+
"c53": "or two, payment reverted, money didn't, week or, didn't come, has reverted, it's back, made was, received one, something about, came back, was returned, already received, been returned, is reverted, payment been, payment came, i've already, problem i, two weeks",
|
| 157 |
+
"c54": "and currencies, are accepted, express to, currencies and, us credit, and cards, funds into, accept to, other credit, payment methods, what payment, which cards, what cards, which currencies, cards and, of cards, accept for, add funds, currencies you, methods are",
|
| 158 |
+
"c55": "delete my, to delete, close my, delete, to close, not happy, terminate, i close, i delete, not satisfied, satisfied, satisfied with, terminate my, dissatisfied, to terminate, close, account immediately, delete account, delete this, please delete",
|
| 159 |
+
"c56": "a sepa, sepa transfer, for receiving, by transfer, receiving money, swift transfer, a swift, receiving a, swift, sepa, are swift, fees associated, for sepa, transfer cost, swift transfers, much would, sepa transfers, receiving, associated, associated with",
|
| 160 |
+
"c57": "international card, european bank, us card, european card, up charges, up us, a european, us cards, my international, fees if, an international, for us, any charges, bank card, with an, european, any fees, for european, using an, debit or",
|
| 161 |
+
"c58": "with cash, use cash, find top, by cash, cheque to, cash to, by cheque, a cheque, a check, deposit a, cheques, option to, send a, i deposit, to deposit, cheque, up using, check to, account with, with a",
|
| 162 |
+
"c59": "up failed, alternatives, declined for, problem or, today urgently, urgently but, work i, any alternatives, app rejected, or let, this or, up fail, please resolve, up didn't, card keeps, declined can, has failed, resolve this, it a, was able",
|
| 163 |
+
"c60": "up limits, any top, any amount, many top, on top, unlimited, up limit, much i, can top, how often, max, of top, the max, the most, limit for, the limit, do top, limit to, a limit, maximum",
|
| 164 |
+
"c61": "crypto top, saw it, there and, up recently, you offered, cancellation, disappeared from, gone i, had topped, has disappeared, it's disappeared, thought you, up get, disappeared i, disappeared what's, glitch, it's gone, offered crypto, up cancellation, up showing",
|
| 165 |
+
"c62": "other people, else top, my friends, be topped, money disappeared, friends, my wallet, wallet, by my, money using, my credit, people, by card, up by, up using, credit card, disappeared, credit, topped, topped up",
|
| 166 |
+
"c63": "charged twice, twice for, twice, double charged, same transaction, times for, duplicate charge, please remove, remove one, clearly, duplicated, two times, duplicate charges, duplicate payment, one transaction, restaurant visit, second time, store earlier, transactions and, was double",
|
| 167 |
+
"c64": "receiver, transfer fee, the receiver, transfer more, make up, thought transfers, transfers were, a receiver, fee while, lesser, manage, payments for, place abroad, to manage, for transferring, abroad for, amount what, be rewarded, fair, my place",
|
| 168 |
+
"c65": "another bank, account into, about transferring, at another, this one, from another, one account, account at, move money, other bank, via bank, my other, this bank, money into, from one, funds from, explain how, bank account, bank transfer, bank transfers",
|
| 169 |
+
"c66": "money transaction, landlord, before yesterday, day before, and she, i've checked, sent some, transfer within, needs it, new landlord, right one, arrive yet, done a, friend who, my landlord, one i've, completion, correct can, country it, country transfer",
|
| 170 |
+
"c67": "from europe, transfer something, china how, us transfer, an urgent, europe how, europe to, urgent transfer, from china, europe take, reach my, europe, estimated, to reach, approximately, the estimated, us take, wait time, something from, something to",
|
| 171 |
+
"c68": "proving, 10 minutes, are clear, economic, economic area, from us, images, images are, minutes to, photos, proving my, readable, switzerland, 18 years, app doesn't, european economic, glare, or older, your images, a resident",
|
| 172 |
+
"c69": "identity checks, documents do, what documents, documentation, of id, forms, forms of, id do, what documentation, what forms, for identity, checks, documents, need for, needed for, you require, the identity, i prove, is needed, for verification",
|
| 173 |
+
"c70": "source of, my source, the source, funds come, source, funds came, see where, my available, money came, where funds, available cash, available money, comes from, money comes, my fund, source for, tell where, of funds, my funds, available funds",
|
| 174 |
+
"c71": "verification code, up verification, verify top, verifying the, up card, authenticate, code anywhere, i authenticate, up need, verifying top, code for, verify the, the verification, verify a, code, a verification, do we, we need, verification process, the top",
|
| 175 |
+
"c72": "got rejected, my disposable, cannot get, my virtual, card won't, won't work, was rejected, the virtual, virtual card, rejected, virtual, disposable virtual, to work, card to, i cannot, cannot, won't, work, disposable, get my",
|
| 176 |
+
"c73": "a visa, visa and, and mastercard, visa card, visa, both a, get both, mastercard and, mastercard from, and visa, between visa, both visa, choose between, visa or, or mastercard, get visa, i prefer, mastercard can, use visa, both mastercard",
|
| 177 |
+
"c74": "about me, passed yet, account although, identity details, is identity, many questions, much information, need so, not passed, so many, verification hasn't, verification has, account before, asking, questions, questions about, though my, passed, so much, information about",
|
| 178 |
+
"c75": "gave me, 20, it gave, gave, only got, 100 but, atm didn't, 30 pounds, only gave, 100, 10 pounds, atm gave, got 20, request cash, me 10, atm just, charged though, it only, just gave, 20 when",
|
| 179 |
+
"c76": "currency at, home currency, for foreign, bit concerned, cash abroad, withdraw here, and bit, currency while, here without, known, was abroad, was different, withdraw without, my home, any additional, holiday and, without any, additional cost, rate when, home"
|
| 180 |
+
},
|
| 181 |
+
"router_anchor": "rt01"
|
| 182 |
+
},
|
| 183 |
+
"boolq": {
|
| 184 |
+
"qkey": "truth",
|
| 185 |
+
"source": "hf",
|
| 186 |
+
"classes": {
|
| 187 |
+
"bo00": "false",
|
| 188 |
+
"bo01": "true"
|
| 189 |
+
},
|
| 190 |
+
"criteria": {
|
| 191 |
+
"bo01": "too much, dad, different fathers, have twins, has anyone, a person, anyone won, in india, send, two different, used for, your own, a baby, avengers, award, hair, play xbox, types, there such, a thing",
|
| 192 |
+
"bo00": "in california, states of, mass, state in, an ivy, and sister, language the, league school, a regular, brother and, dominican, dominican republic, goals count, paper, tax on, terms, to i, 50 states, a throw, address on"
|
| 193 |
+
},
|
| 194 |
+
"router_anchor": "rt02"
|
| 195 |
+
},
|
| 196 |
+
"clinc": {
|
| 197 |
+
"qkey": "intent",
|
| 198 |
+
"source": "hf",
|
| 199 |
+
"classes": {
|
| 200 |
+
"cl000": "restaurant_reviews",
|
| 201 |
+
"cl001": "nutrition_info",
|
| 202 |
+
"cl002": "smart_home",
|
| 203 |
+
"cl003": "rollover_401k",
|
| 204 |
+
"cl004": "pto_request_status",
|
| 205 |
+
"cl005": "how_busy",
|
| 206 |
+
"cl006": "application_status",
|
| 207 |
+
"cl007": "recipe",
|
| 208 |
+
"cl008": "calendar_update",
|
| 209 |
+
"cl009": "play_music",
|
| 210 |
+
"cl010": "yes",
|
| 211 |
+
"cl011": "direct_deposit",
|
| 212 |
+
"cl012": "credit_limit_change",
|
| 213 |
+
"cl013": "user_name",
|
| 214 |
+
"cl014": "gas",
|
| 215 |
+
"cl015": "pay_bill",
|
| 216 |
+
"cl016": "ingredients_list",
|
| 217 |
+
"cl017": "lost_luggage",
|
| 218 |
+
"cl018": "goodbye",
|
| 219 |
+
"cl019": "what_can_i_ask_you",
|
| 220 |
+
"cl020": "book_hotel",
|
| 221 |
+
"cl021": "are_you_a_bot",
|
| 222 |
+
"cl022": "next_song",
|
| 223 |
+
"cl023": "change_speed",
|
| 224 |
+
"cl024": "report_lost_card",
|
| 225 |
+
"cl025": "plug_type",
|
| 226 |
+
"cl026": "maybe",
|
| 227 |
+
"cl027": "w2",
|
| 228 |
+
"cl028": "oil_change_when",
|
| 229 |
+
"cl029": "thank_you",
|
| 230 |
+
"cl030": "shopping_list_update",
|
| 231 |
+
"cl031": "pto_balance",
|
| 232 |
+
"cl032": "order_checks",
|
| 233 |
+
"cl033": "travel_alert",
|
| 234 |
+
"cl034": "fun_fact",
|
| 235 |
+
"cl035": "repeat",
|
| 236 |
+
"cl036": "sync_device",
|
| 237 |
+
"cl037": "schedule_maintenance",
|
| 238 |
+
"cl038": "apr",
|
| 239 |
+
"cl039": "transfer",
|
| 240 |
+
"cl040": "ingredient_substitution",
|
| 241 |
+
"cl041": "calories",
|
| 242 |
+
"cl042": "current_location",
|
| 243 |
+
"cl043": "international_fees",
|
| 244 |
+
"cl044": "calculator",
|
| 245 |
+
"cl045": "definition",
|
| 246 |
+
"cl046": "whisper_mode",
|
| 247 |
+
"cl047": "next_holiday",
|
| 248 |
+
"cl048": "update_playlist",
|
| 249 |
+
"cl049": "mpg",
|
| 250 |
+
"cl050": "min_payment",
|
| 251 |
+
"cl051": "change_user_name",
|
| 252 |
+
"cl052": "restaurant_suggestion",
|
| 253 |
+
"cl053": "travel_notification",
|
| 254 |
+
"cl054": "cancel",
|
| 255 |
+
"cl055": "pto_used",
|
| 256 |
+
"cl056": "travel_suggestion",
|
| 257 |
+
"cl057": "what_are_your_hobbies",
|
| 258 |
+
"cl058": "change_volume",
|
| 259 |
+
"cl059": "order",
|
| 260 |
+
"cl060": "jump_start",
|
| 261 |
+
"cl061": "schedule_meeting",
|
| 262 |
+
"cl062": "meeting_schedule",
|
| 263 |
+
"cl063": "account_blocked",
|
| 264 |
+
"cl064": "freeze_account",
|
| 265 |
+
"cl065": "what_song",
|
| 266 |
+
"cl066": "meaning_of_life",
|
| 267 |
+
"cl067": "restaurant_reservation",
|
| 268 |
+
"cl068": "traffic",
|
| 269 |
+
"cl069": "make_call",
|
| 270 |
+
"cl070": "text",
|
| 271 |
+
"cl071": "bill_balance",
|
| 272 |
+
"cl072": "improve_credit_score",
|
| 273 |
+
"cl073": "change_language",
|
| 274 |
+
"cl074": "oil_change_how",
|
| 275 |
+
"cl075": "no",
|
| 276 |
+
"cl076": "measurement_conversion",
|
| 277 |
+
"cl077": "timer",
|
| 278 |
+
"cl078": "flip_coin",
|
| 279 |
+
"cl079": "do_you_have_pets",
|
| 280 |
+
"cl080": "balance",
|
| 281 |
+
"cl081": "tell_joke",
|
| 282 |
+
"cl082": "last_maintenance",
|
| 283 |
+
"cl083": "exchange_rate",
|
| 284 |
+
"cl084": "uber",
|
| 285 |
+
"cl085": "time",
|
| 286 |
+
"cl086": "car_rental",
|
| 287 |
+
"cl087": "credit_limit",
|
| 288 |
+
"cl088": "oos",
|
| 289 |
+
"cl089": "shopping_list",
|
| 290 |
+
"cl090": "expiration_date",
|
| 291 |
+
"cl091": "routing",
|
| 292 |
+
"cl092": "meal_suggestion",
|
| 293 |
+
"cl093": "tire_change",
|
| 294 |
+
"cl094": "todo_list",
|
| 295 |
+
"cl095": "card_declined",
|
| 296 |
+
"cl096": "weather",
|
| 297 |
+
"cl097": "rewards_balance",
|
| 298 |
+
"cl098": "change_accent",
|
| 299 |
+
"cl099": "vaccines",
|
| 300 |
+
"cl100": "reminder_update",
|
| 301 |
+
"cl101": "food_last",
|
| 302 |
+
"cl102": "change_ai_name",
|
| 303 |
+
"cl103": "bill_due",
|
| 304 |
+
"cl104": "who_do_you_work_for",
|
| 305 |
+
"cl105": "share_location",
|
| 306 |
+
"cl106": "international_visa",
|
| 307 |
+
"cl107": "redeem_rewards",
|
| 308 |
+
"cl108": "calendar",
|
| 309 |
+
"cl109": "translate",
|
| 310 |
+
"cl110": "carry_on",
|
| 311 |
+
"cl111": "book_flight",
|
| 312 |
+
"cl112": "insurance_change",
|
| 313 |
+
"cl113": "todo_list_update",
|
| 314 |
+
"cl114": "timezone",
|
| 315 |
+
"cl115": "cancel_reservation",
|
| 316 |
+
"cl116": "transactions",
|
| 317 |
+
"cl117": "credit_score",
|
| 318 |
+
"cl118": "interest_rate",
|
| 319 |
+
"cl119": "report_fraud",
|
| 320 |
+
"cl120": "spending_history",
|
| 321 |
+
"cl121": "directions",
|
| 322 |
+
"cl122": "spelling",
|
| 323 |
+
"cl123": "insurance",
|
| 324 |
+
"cl124": "what_is_your_name",
|
| 325 |
+
"cl125": "reminder",
|
| 326 |
+
"cl126": "where_are_you_from",
|
| 327 |
+
"cl127": "distance",
|
| 328 |
+
"cl128": "payday",
|
| 329 |
+
"cl129": "gas_type",
|
| 330 |
+
"cl130": "flight_status",
|
| 331 |
+
"cl131": "find_phone",
|
| 332 |
+
"cl132": "greeting",
|
| 333 |
+
"cl133": "alarm",
|
| 334 |
+
"cl134": "order_status",
|
| 335 |
+
"cl135": "confirm_reservation",
|
| 336 |
+
"cl136": "cook_time",
|
| 337 |
+
"cl137": "damaged_card",
|
| 338 |
+
"cl138": "reset_settings",
|
| 339 |
+
"cl139": "pin_change",
|
| 340 |
+
"cl140": "accept_reservations",
|
| 341 |
+
"cl141": "replacement_card_duration",
|
| 342 |
+
"cl142": "new_card",
|
| 343 |
+
"cl143": "roll_dice",
|
| 344 |
+
"cl144": "income",
|
| 345 |
+
"cl145": "taxes",
|
| 346 |
+
"cl146": "date",
|
| 347 |
+
"cl147": "who_made_you",
|
| 348 |
+
"cl148": "pto_request",
|
| 349 |
+
"cl149": "tire_pressure",
|
| 350 |
+
"cl150": "how_old_are_you"
|
| 351 |
+
},
|
| 352 |
+
"criteria": {
|
| 353 |
+
"cl109": "hello in, i were, say hello, goodbye in, translate, translate hello, into russian, russian for, you translate, they say, 'i, french for, into french, say 'i, say thank, spanish for, were english, i say, am a, for goodbye",
|
| 354 |
+
"cl039": "dollars from, from one, ten dollars, to checking, checking to, savings to, to another, to savings, 100 dollars, a to, dollars between, from checking, from savings, money from, please transfer, 5 from, between accounts, money to, transfer 5, transfer from",
|
| 355 |
+
"cl077": "a timer, timer, minute, minute timer, timer for, 5 minutes, 10 minute, two minutes, 10 minutes, 15 minutes, seconds, timer set, the timer, 5 minute, a five, a one, five minute, for 15, let's get, set timer",
|
| 356 |
+
"cl045": "definition, definition of, the definition, ataraxy, affiliate, ajar, flange, qat, zesty, altruism, discretionary, flange means, look it, of affiliate, of ajar, of alternative, of altruism, rescind, mean, means",
|
| 357 |
+
"cl066": "of life, the point, in life, life have, life is, purpose, a meaning, does life, life please, life's, life's meaning, this life, life, is life, life means, meaning in, my life, our purpose, purpose of, the purpose",
|
| 358 |
+
"cl112": "new insurance, insurance policy, new united, united healthcare, adjust my, alter my, an hmo, deductible, different insurance, find new, hmo, insurance plans, insurance please, insurance to, life insurance, new car, obtain new, ppo, policy, insurance plan",
|
| 359 |
+
"cl131": "phone is, cellphone, my cellphone, i left, left my, lost phone, my mobile, help finding, find it, iphone, lost can, misplaced my, my iphone, please locate, seen my, where my, finding my, misplaced, mobile, out where",
|
| 360 |
+
"cl033": "alerts, travel alerts, any travel, alerts for, travel alert, alerts i, aware of, be aware, alert for, any alerts, for kenya, aware, about any, alerts in, for china, for north, how safe, issued, safe is, should know",
|
| 361 |
+
"cl148": "a pto, pto request, from dates, march 6, a vacation, pto from, request from, submit a, february 7, i request, request vacation, to june, to request, 2 25, 22 to, and 8, dates jan, jan, june 8th, pto for",
|
| 362 |
+
"cl072": "improve, improve my, to improve, build, hurt my, keep my, build my, score from, to build, going down, account will, credit from, decrease my, i improve, opening, opening a, score better, will decrease, hurt, build credit",
|
| 363 |
+
"cl034": "fact about, trivia, fun fact, a fun, trivia about, fun facts, an interesting, some trivia, fact, interesting about, interesting fact, something interesting, interesting, about elephants, about mt, elephants, everest, mt, mt everest, neat",
|
| 364 |
+
"cl073": "language, the language, your language, language to, responses, your responses, language setting, start talking, to spanish, in english, language for, please respond, respond in, setting to, alter your, change language, french please, in mandarin, language english, language set",
|
| 365 |
+
"cl128": "next paycheck, payday, next payday, last paycheck, get paid, paid last, was paid, a paycheck, another paycheck, date did, got paid, last paid, paid next, paycheck arrive, paycheck be, paycheck due, paycheck is, paycheck will, paid, date do",
|
| 366 |
+
"cl141": "replacement card, my replacement, replace a, replacement, card be, card mailed, stolen credit, a replacement, be before, card arrive, card arrives, card take, one was, stolen one, takes for, until you, new card, come in, arrives, card to",
|
| 367 |
+
"cl085": "current time, time in, standard, standard timezone, the eastern, cst, eastern timezone, it right, time right, timezone what, time is, california, in cst, in istanbul, istanbul, it exactly, it now, pacific, it in, eastern",
|
| 368 |
+
"cl006": "card application, processed, my application, been processed, application has, application i, through yet, application, applied, applied for, card app, i applied, processed yet, my app, what status, app, application been, application go, application so, been any",
|
| 369 |
+
"cl130": "dl123, flight dl123, my flight, land, board, landing, boarding, flight is, scheduled to, to board, flight scheduled, my delta, of flight, to land, be landing, flight land, flight will, frontier flight, my frontier, will land",
|
| 370 |
+
"cl078": "coin, flip, a coin, flip a, tails, coin flip, heads, coin i, call tails, coin and, heads or, or tails, please flip, and flip, flip that, that coin, to flip, coin for, i choose, it lands",
|
| 371 |
+
"cl051": "can call, just call, me mary, by brad, calling me, frank, me al, me carrie, me sam, me stevie, my friends, my name's, name's, stevie, call me, brad, address me, friends call, something else, go by",
|
| 372 |
+
"cl126": "of origin, origin, where were, you from, you live, what place, where you, your home, your place, area were, birthplace, come from, country of, hail, location did, what area, what country, you hail, you're made, your birthplace",
|
| 373 |
+
"cl030": "and add, bananas, list if, add bread, cherrios, if not, add milk, carrots off, list cause, carrots, add carrots, add cherrios, add soda, add that, add them, bananas on, cause i'm, cherrios to, do shopping, fries from",
|
| 374 |
+
"cl019": "ask you, questions, subjects, of questions, familiar, familiar with, you about, subjects are, what subjects, you familiar, i ask, of subjects, can ask, questions do, subjects do, what questions, things can, areas, areas you, ask of",
|
| 375 |
+
"cl026": "either, could be, it could, be either, a clue, both, either one, about it, about that, either of, i'm unsure, im not, knowledge, no knowledge, really don't, sure which, unsure, would work, clue, maybe",
|
| 376 |
+
"cl074": "car's oil, of oil, oil in, oil do, car oil, oil and, a car's, change a, learn how, oil for, own oil, passat, type i, change oil, the oil, and what, changing oil, for changing, kind do, me instructions",
|
| 377 |
+
"cl067": "table for, 2 at, name kevin, robin under, lobster at, 3 at, pm today, 30 please, 8 at, bird for, three at, a table, at johnnys, bar for, for four, garden under, jason, johnnys, name dave, tuesday at",
|
| 378 |
+
"cl080": "account balance, enough money, bank balance, enough in, bank accounts, american account, current bank, in all, money is, of american, account for, balance at, balance for, bank savings, checking balance, in checking, my accounts, my balance, skis, money in",
|
| 379 |
+
"cl135": "confirm my, and confirm, to confirm, try and, for josh, have reservations, confirm, you confirm, confirm that, 2 20, for kevin, to try, 3 pm, confirm i, confirmed, for john, grill for, reservation on, robin at, s for",
|
| 380 |
+
"cl064": "freeze my, stop on, block my, you freeze, a stop, a block, account immediately, please freeze, to freeze, block on, away please, block put, immediatly, immediatly block, to block, turn off, put a, freeze, block, account right",
|
| 381 |
+
"cl003": "rollover, rollover my, new job, to rollover, 401k, my 401k, 401k rollover, rolled over, job and, roll over, rolling over, 401k rolled, 401k please, 401k to, a 401k, assistance figuring, job but, transferring, transferring my, transfer my",
|
| 382 |
+
"cl147": "who made, made you, programmed you, creator, responsible, responsible for, who programmed, design, inventor, which company, your design, company is, created you, creator of, inventor of, is responsible, made the, manufactured, manufactured you, programmer",
|
| 383 |
+
"cl127": "bus ride, to red, harbor, harbor airport, robin in, sky, sky harbor, the sky, commute, i reach, in phoenix, mcdonald's, mcdonald's in, outback in, park in, reach doctors, reach my, reach the, the commute, the park",
|
| 384 |
+
"cl013": "name saved, saved as, by what, saved under, guess, know me, names you, save, save my, what names, you save, my name, you refer, names, say my, name do, name is, saved, name you, name that",
|
| 385 |
+
"cl114": "what timezone, timezone is, the timezone, timezone for, which timezone, france's, france's timezone, zone in, chicago is, in miami, italy is, reno what, timezone chicago, timezone would, time zone, zone, timezone, reno, is in, central timezone",
|
| 386 |
+
"cl022": "next song, this playlist, next one, song and, skip this, forward, next track, skip, go forward, next tune, play next, song now, and play, forward to, jump to, move to, next number, one on, one song, playing the",
|
| 387 |
+
"cl116": "recent transaction, my transactions, recent transactions, made on, the transactions, last ten, my transaction, card last, five transactions, i've made, last five, last transaction, made last, me transactions, of transaction, recent purchases, that were, transaction for, transaction history, transactions for",
|
| 388 |
+
"cl052": "restaurants, good places, that serve, serve sushi, restaurants in, kentucky that, good restaurant, good thai, place for, thai restaurants, good place, serve, an indian, barbecue, chinese restaurants, eat tonight, for italian, indian restaurant, list off, restaurants are",
|
| 389 |
+
"cl097": "rewards balance, rewards card, rewards points, many rewards, reward balance, reward points, many points, card's rewards, current reward, marriot, marriot rewards, my starbucks, points did, many reward, my marriot, point total, reward amount, reward point, starbucks rewards, total on",
|
| 390 |
+
"cl015": "paying my, bill from, help paying, me pay, bill with, insurance bill, my checkings, pay this, student loan, this bill, bill now, pay my, paying, car bill, must pay, my student, pay a, rent bill, student, pay the",
|
| 391 |
+
"cl120": "spent on, on food, lately, lot on, been spending, spending a, on shoes, i spent, food recently, money have, spent, food last, money did, on groceries, much have, clothes, eating out, out lately, shoes lately, shoes recently",
|
| 392 |
+
"cl004": "off request, approved yet, my day, my request, request been, approval, request has, request is, approval of, been signed, been updated, my supervisor, request approved, request looking, request please, supervisor, the approval, updated, vacation been, vacation was",
|
| 393 |
+
"cl117": "score please, credit rating, rating, score is, current credit, credit score, score, provide me, i locate, out what, my credit, i see, me of, provide, want my, see my, up my, the number, credit, me my",
|
| 394 |
+
"cl142": "apply, apply for, to apply, america travel, rewards credit, sign, sign up, travel rewards, a discover, applying, applying for, a barclay's, an amex, an application, to sign, i apply, a bank, an american, new credit, a mastercard",
|
| 395 |
+
"cl017": "my luggage, ab123, flight ab123, ab123 out, luggage, lost luggage, was on, luggage is, airlines flight, luggage has, luggage i, luggage was, ab123 from, america airlines, find lost, flight america, in o'hare, is missing, my bags, of houston",
|
| 396 |
+
"cl035": "it again, say it, repeat what, didn't hear, you said, more time, one more, that please, please repeat, repeat that, repeat, repeat yourself, said again, said can, the question, to repeat, you repeat, catch that, missed that, missed what",
|
| 397 |
+
"cl049": "mpg, highway, per gallon, the highway, miles per, the mpg, mileage, mpg does, mpg for, cars mpg, fuel economy, gallon does, gas mileage, mpg of, mpg on, car do, car's mpg, mpg in, the cars, this cars",
|
| 398 |
+
"cl028": "next oil, oil again, change due, oil changes, oil get, when would, often should, how often, often, should change, changed next, before changing, oil change, my oil, oil changed, frame, get changed, time frame, an oil, oil",
|
| 399 |
+
"cl010": "yes that, is true, yes that's, that's right, yeah, yep, yes you, absolutely, affirmative, that's correct, yeah that's, yep that's, yes, true, is correct, a yes, be true, is right, is yes, my response",
|
| 400 |
+
"cl056": "there to, attractions, attractions in, fun tourist, gatlinburg, in gatlinburg, in portland, see in, sites, tourist things, activities in, fun to, some suggestions, some tourist, tourist sites, activities to, anything fun, best place, do tourists, does kentucky",
|
| 401 |
+
"cl123": "my health, health benefits, health plan, benefits, health, insurance benefits, what benefits, plan i'm, what health, enrolled, enrolled in, benefits are, benefits do, benefits does, plan do, the insurance, benefits i, care plan, health care, i enrolled",
|
| 402 |
+
"cl113": "add cleaning, laundry to, mopping, of chores, the dishes, washing, add clean, add laundry, add paint, all items, bathroom to, clear out, dishes off, dishes on, everything from, laundry from, off everything, recycling, the plants, the todo",
|
| 403 |
+
"cl125": "reminders, reminder list, my reminder, of reminders, my reminders, i wanted, the reminder, the reminders, reminders is, reminders list, repeat my, what reminders, a light, bulb, bulb is, floor, have set, light bulb, list back, mop the",
|
| 404 |
+
"cl023": "speech, speed, faster, slower, your speech, speed of, speed up, the speed, slow down, slowly, speak a, slower please, too fast, you slow, your speaking, faster please, more slowly, please speed, speak faster, talk faster",
|
| 405 |
+
"cl149": "pressure, tire pressure, air in, the air, air pressure, my tire, car's tire, current tire, pressure in, the tire, tire, level in, low the, much air, on pressure, pressure of, pressure please, the pressure, air, air level",
|
| 406 |
+
"cl075": "no that, is false, that isn't, that's not, false, is wrong, not right, not true, definitely false, incorrect, is definitely, isn't the, no don't, not that, definitely, isn't, be false, that s, don't do, say no",
|
| 407 |
+
"cl038": "apr, card's apr, the apr, my apr, apr on, apr for, card apr, apr is, credit card's, apr if, apr of, apr please, good apr, this credit, good is, card's, my card's, annual, how good, you could",
|
| 408 |
+
"cl001": "nutritional, the nutritional, nutrition, the nutrition, healthy, nutritional info, nutrition facts, facts for, how healthy, chicken nuggets, nuggets, nutrition info, nutritional information, healthy is, info for, for grapes, nutritional content, facts of, french fries, grilled",
|
| 409 |
+
"cl108": "friday the, 2nd on, any events, next sunday, 30th birthday, appointments, calendar looks, calendar next, anything on, march 2nd, is currently, 17th of, showing on, of march, schedule for, currently on, have scheduled, scheduled on, 23, have going",
|
| 410 |
+
"cl084": "uber, an uber, uber to, uber for, people to, call an, passengers, are going, uber that, 5 people, passengers to, pool, to union, to wendys, uber please, uber pool, union station, wendys, movies, the movies",
|
| 411 |
+
"cl044": "root of, square root, the square, divided, math, root, divided by, is 4, math problem, 18 percent, 2 2, 3 plus, 30 off, 78 times, 85, a math, is 1, is 10, is 3, is 78",
|
| 412 |
+
"cl146": "today's date, days from, date be, tomorrow's, tomorrow's date, 100 days, current date, date today, date tomorrow, days what, is today, calender, in 100, is tomorrow, it today, the week, tomorrow is, date is, is today's, today's",
|
| 413 |
+
"cl110": "carry, carry on, carry ons, ons, restrictions, the carry, many carry, on restrictions, restrictions for, flight with, for carry, airlines to, for delta, ons can, for united, i carry, can take, on policy, ons i, does delta",
|
| 414 |
+
"cl055": "days off, i taken, i've taken, taken off, days i've, off i, this point, i've used, of days, off so, days have, already used, my days, off work, sick, used at, have used, been used, days did, days so",
|
| 415 |
+
"cl037": "engine light, check engine, car maintenance, light is, someone to, an appointment, engine, schedule somewhere, some car, somewhere get, car because, need someone, on and, place where, schedule car, schedule to, look at, tires checked, maintenance, a tire",
|
| 416 |
+
"cl053": "bank know, inform my, to inform, soon and, bank that, know i, alert my, rome from, be travelling, brazil from, february 1, from february, july 1st, june 1st, notify my, i'm travelling, bank i'm, bank needs, im going, that i'll",
|
| 417 |
+
"cl036": "disconnect, disconnect from, connect to, unsync, link, connection, unsync my, desync, link with, new phone, pair this, please connect, sync, this with, to disconnect, you connect, phone please, phone now, and connect, and disconnect",
|
| 418 |
+
"cl029": "i appreciate, your help, appreciate your, you for, good job, grateful, you so, your answer, am thankful, appreciate that, appreciated, are so, grateful for, help thank, i'm grateful, is appreciated, lot for, so much, thankful, thankful for",
|
| 419 |
+
"cl143": "dice, roll a, sided dice, you roll, the dice, roll the, a dice, sided die, 6 sided, 10 sided, and roll, roll dice, roll, sided, a die, a pair, dice for, dice please, dice roll, please roll",
|
| 420 |
+
"cl101": "fridge since, fridge, the fridge, freezer, the freezer, since monday, pizza in, been in, had pizza, monday so, so is, eggs in, i've had, before it, can leave, eat chicken, for before, go bad, since last, chicken that",
|
| 421 |
+
"cl136": "cook a, cook the, i cook, the brownies, steak for, a frozen, an egg, bake the, boil, cook chicken, cook steak, cooking time, egg, long must, microwave a, noodles for, prep, preparation, preparation time, preparing",
|
| 422 |
+
"cl100": "cat her, flea, flea medicine, her flea, medicine, the cat, to remind, reminder to, a reminder, tommorow, doctors appointment, forget to, me later, pay taxes, reminded, reminded to, reminder please, this in, work out, reminder for",
|
| 423 |
+
"cl024": "as lost, as stolen, it as, reported, be reported, discover credit, is stolen, lost discover, lost please, reported as, stolen please, card as, card needs, it reported, lost visa, mastercard and, me report, my stolen, please report, report my",
|
| 424 |
+
"cl040": "substitute, i substitute, salt, baking, baking soda, to swap, acceptable, acceptable to, for baking, for milk, it acceptable, milk for, salt for, sour cream, sub, sugar for, swap salt, yogurt, swap, i swap",
|
| 425 |
+
"cl069": "dial, christie's, please dial, call to, phone call, bella, dial christie's, must call, robby, a call, a phone, call someone, sarah, phone number, please call, steven, call the, call a, call, to call",
|
| 426 |
+
"cl133": "alarm, and another, alarm for, 6am, another for, an alarm, alarm set, for 6am, my alarm, the alarm, set alarm, alarm at, for 9, new alarm, wake, 6 am, 9 am, 9 tomorrow, for 11, wake me",
|
| 427 |
+
"cl094": "what tasks, tasks, do today, is cleaning, list have, list read, read out, tasks on, the tasks, let's go, of tasks, read back, tasks to, my todo, do list, todo, todo list, my to, accomplish, cleaning the",
|
| 428 |
+
"cl098": "accent, male voice, the male, female, female voice, male british, male, your accent, a male, british one, the female, accent to, a british, british male, use male, british, british accent, to female, different accent, to male",
|
| 429 |
+
"cl027": "w2, w 2, my w, a w2, my w2, w, 2 form, form that, forms, w2 form, a w, form i, my wages, shows my, wages, forms given, w2 forms, and where, form from, forms to",
|
| 430 |
+
"cl103": "bill due, is due, bill by, find when, at t, my at, insurance due, due date, the due, bill is, t bill, a bill, mortgage payment, my xfinity, xfinity, day do, due, car payment, before my, the electric",
|
| 431 |
+
"cl041": "calories in, calories, calorie, the calorie, of calories, many calories, calorie content, calorie count, cookie, the calories, a cookie, cheetos, calories are, caloric, calories does, calories would, chocolate ice, contain, muffins, of chocolate",
|
| 432 |
+
"cl137": "damaged, in half, damaged and, bent, cracked, is damaged, can't use, card because, card fell, card split, chewed, does not, fell, melted, my dog, scratched, split in, accidentally, bent my, broken card",
|
| 433 |
+
"cl000": "the reviews, the ratings, reviews for, ratings for, good are, reviews like, at yakamoto, the sushi, yakamoto, are people, at tgi, donuts, donuts at, people like, steakhouse have, tgi, the donuts, ratings, bear, black bear",
|
| 434 |
+
"cl091": "routing, routing number, the routing, my routing, america routing, chase checking, number for, for chase, number from, ai what, for bank, number, my first, national, fargo account, citibank, find the, fargo, wells, wells fargo",
|
| 435 |
+
"cl079": "pets, of pets, a cat, cat or, pets you, you own, your pets, cats or, or dog, or dogs, pets do, animals, dog person, any pet, the pets, animal, animals do, have pets, a dog, a pet",
|
| 436 |
+
"cl061": "a meeting, rooms, meeting room, meeting rooms, available between, rooms available, there meeting, with tom, and lisa, carrie and, for 6pm, meeting for, room available, rooms are, rooms between, the office, tom for, with carrie, 00am, am are",
|
| 437 |
+
"cl129": "of fuel, car need, what gas, gas should, car uses, fuel does, the type, to fill, use premium, car currently, car up, fill this, fuel my, fuel should, fuel type, gas this, i fill, matter, of gasoline, premium gas",
|
| 438 |
+
"cl025": "plug, converter, plug converter, socket, a plug, socket converter, a socket, plug type, plugs, converter if, converter when, of plug, i visit, converter in, barcelona, converter for, of plugs, what plug, a converter, in barcelona",
|
| 439 |
+
"cl093": "replaced them, new tires, i replaced, tires changed, tires if, last replaced, replaced, tires next, replace them, them on, 21 17, next if, replaced my, should replace, tires i, 2017, do tires, four years, it time, need changing",
|
| 440 |
+
"cl083": "yen, exchange rate, the exchange, dollars can, exchange for, euros, rate between, rubles, us dollars, many dollars, exchange, pesos, usd, and rubles, in yen, yen and, currency, currency conversion, the currency, 6 yens",
|
| 441 |
+
"cl047": "next holiday, our next, free day, holiday, next free, next scheduled, a holiday, extent, extent until, holiday is, off is, scheduled holiday, what extent, next day, closest holiday, comming, comming up, day please, have off, holiday next",
|
| 442 |
+
"cl058": "volume, the volume, increase your, 4 please, volume level, speaker volume, volume to, your volume, decrease volume, level to, the sound, voice box, to 4, and increase, lower volume, lower your, my volume, raise volume, the speaker, volume at",
|
| 443 |
+
"cl104": "work for, you work, working for, your boss, employed, you working, employed by, someone else, who would, i your, u work, you employed, another person, are working, boss is, else do, entity, person you, there another, your employer",
|
| 444 |
+
"cl087": "spending limit, high is, my spending, limit i, credit on, current limit, limit is, the visa, how high, much can, max, my limit, limit for, the max, visa card's, limit on, the limit, limit, credit limit, spending",
|
| 445 |
+
"cl005": "busy, how busy, busy is, seated, seated at, wait at, around 5, is kaya, kaya, a wait, be busy, be seated, busy at, busy will, the cheese, this restaurant, the wait, before being, being seated, business",
|
| 446 |
+
"cl140": "take reservations, they take, does reservations, make reservations, redrobin, accept reservations, do reservations, francisco take, takes reservations, zeus, acero, are reservations, at redrobin, if zeus, michael's, reservations in, reservations, accept, francisco, king",
|
| 447 |
+
"cl134": "package, my package, my order, online order, track my, been delivered, my online, order has, shipped, arrived yet, delivery order, my delivery, package is, been shipped, delivered please, i ordered, order arrived, order be, order from, order i",
|
| 448 |
+
"cl139": "pin, my pin, pin number, 1234, the pin, pin on, pin to, to 1234, account pin, be 1234, pin for, new pin, pin is, on account, 1234 on, abc, abc bank, account ending, amex pin, ending",
|
| 449 |
+
"cl018": "was nice, chatting, adios, ai goodbye, chat, chat with, chatting with, conversation, conversation with, for talking, glad we, pleasant, to chat, was great, was pleasant, you around, nice to, it was, bye, glad",
|
| 450 |
+
"cl063": "why is, locked out, account has, confused, why am, confused about, i locked, is blocked, blocked, locked, account being, been blocked, been placed, blocked but, hold placed, own account, the block, very confused, was a, why can't",
|
| 451 |
+
"cl065": "song is, what song, is playing, title, title of, are listening, song this, the title, this is, which song, song playing, that we, hearing, listening at, on speaker, playing song, song i'm, song's, song's name, this song's",
|
| 452 |
+
"cl043": "transaction fees, for using, fees for, fees, international transaction, be charged, any transaction, charged if, associated, associated with, fees associated, charged, transaction fee, card in, fee, a fee, charged extra, fee using, get charged, have international",
|
| 453 |
+
"cl082": "the shop, car was, been since, car last, last have, last oil, long has, had my, serviced, last changed, last looked, shop, a tune, car checked, change occurred, get looked, had an, in shop, last get, last had",
|
| 454 |
+
"cl062": "meetings, any meetings, meetings today, meetings with, what meetings, meetings do, today between, have today, meeting schedule, meetings for, my meetings, schedule today, and one, have meetings, many meetings, meetings are, meetings scheduled, with roger, and 4, for any",
|
| 455 |
+
"cl016": "what ingredients, ingredients, ingredients are, ingredients do, ingredients in, broccoli, broccoli cheddar, buy to, cheddar soup, chicken noodle, gumbo, in pizza, noodle casserole, the ingredients, for broccoli, ingredients for, ingredients go, ingredients i, make pancakes, pizza are",
|
| 456 |
+
"cl119": "fraudulent, a fraudulent, fraudulent activity, fraudulent transaction, fraud, report fraudulent, transaction from, activity, fraud on, activity on, charges on, suspicious, an unauthorized, charge from, fraudulent charges, from wal, made an, may have, someone made, this charge",
|
| 457 |
+
"cl076": "centimeters, ounces, you convert, inches, meters, feet, tablespoons, inches to, kilos, tablespoons and, teaspoons, to centimeters, 2 inches, between tablespoons, grams, inches into, many cups, millimeters, ounces in, and teaspoons",
|
| 458 |
+
"cl002": "lights, fan, door, fan on, the fan, the lights, 350, furnace, the door, to 350, doors, lights on, my furnace, on please, oven to, ac, ac set, car started, dim, dim the",
|
| 459 |
+
"cl020": "a hotel, hotel in, hotel, hotel room, to stay, people from, room in, a room, until 3, 10 people, 11 to, cali, hotels, in cali, in manhattan, manhattan, with good, 2 through, april 8, booked in",
|
| 460 |
+
"cl042": "map, the map, location on, am on, a map, map please, where am, about finding, coordinates of, current gps, i located, my present, what street, location right, located, location please, the gps, current location, where i'm, my location",
|
| 461 |
+
"cl096": "forecast, rain, the weather, weather, costa mesa, forecast for, mesa, chance, high temperature, sparks, the forecast, weather forecast, weather in, weather like, chance of, conditions, current weather, for seattle, in sparks, it rain",
|
| 462 |
+
"cl145": "state taxes, my state, in taxes, federal taxes, my federal, much will, federal tax, in federal, of tax, tax return, taxes amount, pay in, bill going, for state, in income, in tax, income tax, income taxes, tax do, taxes be",
|
| 463 |
+
"cl050": "minimum payment, the minimum, minimum, can pay, bill's minimum, minimum i, the bill's, bill minimum, least, smallest, the smallest, lowest, lowest amount, minimum amount, power bill, smallest amount, the least, the lowest, payment for, bill's",
|
| 464 |
+
"cl046": "whisper, mode, whisper mode, to whisper, whisper voice, the whisper, use whisper, mode now, whispering, a whisper, activate, begin using, into whisper, mode please, mode to, of whisper, on whisper, please switch, using whisper, voice setting",
|
| 465 |
+
"cl054": "cancel that, abort, command, are doing, current task, halt, last command, ai stop, anymore please, current action, current process, last request, never mind, quit, shut up, stop your, your current, your present, you stop, please stop",
|
| 466 |
+
"cl106": "international visa, visa to, travel visa, visa for, an international, cancun, tourist visa, canada next, does travelling, islands, next month, require an, soon do, to cancun, vacation to, visa needed, a visa, require a, to visit, to canada",
|
| 467 |
+
"cl099": "vaccinations, shots, vaccines, any shots, specific shots, to africa, get any, shots before, shots i, a vaccination, any specific, get before, shots do, shots to, south africa, vaccination, what shots, are required, are vaccinations, before going",
|
| 468 |
+
"cl031": "pto days, days do, days are, days left, accrued, are left, i accrued, left for, remaining pto, vacation do, days i, many vacation, have remaining, off do, saved up, still have, remaining, have left, vacation days, have saved",
|
| 469 |
+
"cl121": "nearest, the nearest, closest starbucks, nearest gas, of liberty, statue, statue of, foot, liberty by, me directions, olympia, on foot, station to, the statue, to olympia, gas station, closest to, closest walmart, nearest bank, olympia by",
|
| 470 |
+
"cl122": "spell, to spell, you spell, spelling, spelled, spelling of, happiness, superficial, mississippi, right way, spell mississippi, spell out, spell superficial, the spelling, a's, a's can, antipathy, find in, i spell, in happiness",
|
| 471 |
+
"cl132": "are things, you doing, hi there, is everything, ai doing, doing okay, how have, things going, treating, treating you, what's up, whats up, you feel, you this, hi, how are, good to, okay, feel, well",
|
| 472 |
+
"cl138": "factory settings, original settings, to factory, your factory, default, reset to, revert, settings please, the original, settings, to default, reset, default settings, reset your, revert to, settings now, the factory, original, my factory, reset the",
|
| 473 |
+
"cl124": "a name, like me, name should, you by, being called, introduce, introduce yourself, like your, want me, name i, i refer, be referred, get your, particular, referred, referred to, they call, call you, should call, you prefer",
|
| 474 |
+
"cl011": "direct deposit, up direct, a direct, deposit for, deposit, directly, setting up, direct, deposit my, to direct, deposit to, direct deposited, directly deposited, for setting, paycheck to, deposited, about setting, deposited directly, deposited in, depost",
|
| 475 |
+
"cl118": "interest rate, the interest, interest, my interest, what interest, current interest, rate on, america cd, cd, cd account, i figure, rate am, getting from, interest on, intetest, intetest rate, my intetest, rate i, rate will, rate for",
|
| 476 |
+
"cl012": "1000, i increase, a higher, higher, to 1000, limit to, 000, higher limit, increase my, i raise, one thousand, thousand dollars, limit be, limit changed, to 500, you increase, thousand, increased to, to one, increased",
|
| 477 |
+
"cl057": "hobbies, enjoy, you enjoy, your hobbies, free time, hobbies do, your free, of hobbies, what hobbies, any hobbies, spare time, in your, activities do, enjoy doing, of activities, your spare, at free, doing in, have hobbies, hobbies are",
|
| 478 |
+
"cl111": "roundtrip, returning, for under, dallas to, and returning, returning on, roundtrip flight, flight from, a roundtrip, from dallas, flight out, march 10, flights from, from nyc, nyc to, roundtrip flights, to atlanta, under 500, 2019 and, 3rd for",
|
| 479 |
+
"cl089": "whats on, list out, go shopping, list consist, put milk, what all, tomato, consist, consist of, items are, peanut, peanut butter, shopping list, my shopping, shopping, the shopping, put on, list for, what's on, things on",
|
| 480 |
+
"cl070": "text, a text, send a, text message, text to, tell him, message to, tell her, message, text my, you text, her i, i'll talk, sal, text and, him, a message, be home, chris and, he",
|
| 481 |
+
"cl071": "my bills, water and, electricity, and electricity, dte, bills this, comcast bill, my comcast, my dte, my utilities, verizon, and gas, bill payments, bill this, dte bill, electricity bill, much my, my verizon, of all, the amounts",
|
| 482 |
+
"cl105": "share my, location with, coordinates with, and craig, craig, noel, and jerry, ben and, craig where, gps location, jerry, let the, needs my, tell bill, the wife, trey, with home, with mom, with noel, my gps",
|
| 483 |
+
"cl107": "card points, redeem, cash in, redeem my, to redeem, i cash, i redeem, to cash, points to, in rewards, can redeem, gift, gift card, redemption, reward for, rewards i, utilize, utilize my, cash, am ready",
|
| 484 |
+
"cl009": "that goes, don't make, goes like, it bad, jude don't, like hey, music by, some music, music, maroon, maroon 5, my maroon, my shower, play me, shower playlist, 5 playlist, baby shark, doo, doo doo, elvis",
|
| 485 |
+
"cl008": "calendar on, clear my, add farm, event from, farm, farm trip, staff, staff meeting, add staff, anniversary dinner, appointment i, calendar that, carla, dentist appointment, doctor's, doctor's appointment, event in, fishing, fishing from, for soccer",
|
| 486 |
+
"cl021": "a real, real person, a bot, bot, human, a computer, real, an ai, human or, a human, ai or, you an, person or, or an, computer, a live, human being, i talking, or are, you real",
|
| 487 |
+
"cl014": "gas tank, enough fuel, gas level, gas to, enough gas, fuel to, tank, current gas, fuel level, gas in, get gas, my tank, much gas, current fuel, fuel tank, level at, level is, more gas, much fuel, tank at",
|
| 488 |
+
"cl090": "expires, card expires, card expire, what month, expiration date, card's expiration, month that, expiring, expiry, month will, the expiry, expiration, the expiration, to expire, be until, card expiring, card going, card reach, expiration month, expire soon",
|
| 489 |
+
"cl048": "my playlist, add this, broken by, add what, by evanescence, evanescence, favorite playlist, my favorite, my jazz, my rb, my rock, new playlist, put this, rb, rb playlist, song in, what i'm, add god's, adding, beatles to",
|
| 490 |
+
"cl115": "cancel my, reservation i, the reservation, dinner reservation, don't need, i cancel, at umami, cancel it, carl at, chris at, for chris, umami, with carl, at zepher, cancel tonight's, canceled, i created, joe and, outback for, reservation anymore",
|
| 491 |
+
"cl081": "joke, a joke, joke about, jokes, funny about, funny, good joke, something funny, about food, funny jokes, good jokes, tell a, about lawyers, any jokes, funniest, funny joke, jokes about, jokes do, laugh, lawyers",
|
| 492 |
+
"cl102": "calling you, ai name, name to, betty, felix, to update, update you, start calling, name for, new name, set your, change your, calling, your name, the ai, you as, to start, as my, you name, now on",
|
| 493 |
+
"cl150": "age, your age, how old, long have, many years, old you, your birthday, old are, alive, been alive, been around, old is, old, were born, you been, ai how, are how, al, your birth, years",
|
| 494 |
+
"cl086": "rental, rent a, a rental, rental car, car rental, to rent, car for, car from, i rent, a ford, can rent, ford, rental in, 12 to, a bmw, aiken, between january, bmw, bmw suv, car out",
|
| 495 |
+
"cl060": "battery, jump start, to jump, car battery, dead, dead car, is dead, jump, battery is, a dead, jump a, dead what, i jump, you jump, a battery, died, jump starting, my battery, my dead, start my",
|
| 496 |
+
"cl092": "a meal, meal from, meal, meal suggestion, italian meal, suggestion for, suggestion, a suggestion, mexican meal, cuisine, dinner suggestions, from italy, make for, a mexican, a thai, a vietnamese, about making, any suggestions, burma, burma to",
|
| 497 |
+
"cl007": "blackberry, blackberry pie, chow, chow mein, make sushi, mein, good recipe, make beef, recipe for, a blackberry, a chow, chicken pot, for beef, for making, lasagna recipe, make apple, make blackberry, make chow, mein recipe, pot pie",
|
| 498 |
+
"cl144": "salary, my salary, earn from, i making, salary is, yearly, my income, income, my pay, my job, at work, i earn, pay period, earn, from work, period, much am, my total, i earned, this week",
|
| 499 |
+
"cl059": "so will, order everything, buy me, underpants, you buy, lysol, underpants for, want everything, order me, and order, be ordered, buy everything, buy something, cat food, flour so, for everything, get everything, have everything, list ordered, lysol could",
|
| 500 |
+
"cl068": "the traffic, traffic, traffic like, route, traffic on, route to, traffic typically, typically, the route, typically like, like on, 3 30, 30 on, any traffic, in tempe, is traffic, tempe, traffic bad, traffic in, traffic is",
|
| 501 |
+
"cl032": "checks, checkbooks, more checkbooks, more checks, checks for, new checks, checkbooks for, checkbooks mailed, for more, order new, of checks, usbank, checkbooks to, checks please, my usbank, order more, i order, bank checking, checkbooks by, checks since",
|
| 502 |
+
"cl095": "declined, was declined, declined at, got declined, card declined, declined yesterday, card not, at walmart, card yesterday, get accepted, not get, a mug, buying, declined my, i tried, mug, tried, card was, why was, accepted",
|
| 503 |
+
"cl088": "formula, formula for, mushroom, semitic, stock, the formula, war, languages, game, percentage of, the most, to learn, who was, learn, win, area, percentage, live, market, open"
|
| 504 |
+
},
|
| 505 |
+
"router_anchor": "rt03"
|
| 506 |
+
},
|
| 507 |
+
"dbpedia": {
|
| 508 |
+
"qkey": "entity",
|
| 509 |
+
"source": "hf",
|
| 510 |
+
"classes": {
|
| 511 |
+
"db00": "company",
|
| 512 |
+
"db01": "educational_institution",
|
| 513 |
+
"db02": "plant",
|
| 514 |
+
"db03": "album",
|
| 515 |
+
"db04": "film",
|
| 516 |
+
"db05": "written_work",
|
| 517 |
+
"db06": "artist",
|
| 518 |
+
"db07": "athlete",
|
| 519 |
+
"db08": "office_holder",
|
| 520 |
+
"db09": "mean_of_transportation",
|
| 521 |
+
"db10": "building",
|
| 522 |
+
"db11": "natural_place",
|
| 523 |
+
"db12": "village",
|
| 524 |
+
"db13": "animal"
|
| 525 |
+
},
|
| 526 |
+
"criteria": {
|
| 527 |
+
"db00": "manufacturer of, headquartered, headquartered in, a subsidiary, company headquartered, is headquartered, a company, manufactures, plc, solutions, the company, company based, businesses, company founded, company has, label based, ltd is, privately held, provider, records is",
|
| 528 |
+
"db01": "secondary school, college is, school located, students from, co educational, university is, the school's, school has, coeducational, public high, grades 9, day school, mascot, academy is, mascot is, school with, college located, colors are, sixth form, schools in",
|
| 529 |
+
"db06": "songwriter and, american musician, record producer, composer and, guitarist and, painter, and songwriter, a writer, actress she, and record, illustrator, italian painter, novelist and, painter and, and singer, musician best, artist best, has performed, has written, musician he",
|
| 530 |
+
"db07": "footballer, footballer who, plays for, olympics, currently plays, summer olympics, football player, hockey, who currently, plays as, ice hockey, american football, defender, professional footballer, competed in, midfielder, played college, professional ice, american professional, college football",
|
| 531 |
+
"db08": "of representatives, republican, politician and, politician who, politician, american politician, a republican, republican member, representatives, was appointed, politician he, democratic member, democratic party, a democratic, legislative assembly, representatives from, politician from, senator from, politician in, assembly",
|
| 532 |
+
"db09": "uss, laid down, hms, royal navy, destroyer, down on, vessel, class destroyer, the ship, states navy, navy during, navy in, shipbuilding, biplane, engined, prototype, by mrs, class submarine, diesel, in command",
|
| 533 |
+
"db10": "a historic, church is, historic house, house was, building located, revival style, national register, of historic, register of, historic places, 2 story, style it, the museum, historic home, parish church, register, home located, museum is, national historic, places on",
|
| 534 |
+
"db11": "tributary, tributary of, a tributary, river is, a river, a mountain, it flows, river of, mountain range, flows, in romania, and flows, km long, valea, a lake, lake is, mile long, the valea, crater, flows through",
|
| 535 |
+
"db12": "census, population was, 2006 census, census its, iran at, its population, rural district, persian also, gmina, also romanized, romanized, romanized as, voivodeship in, administrative district, a village, of gmina, lies approximately, central poland, village has, village in",
|
| 536 |
+
"db13": "moth, a moth, moth of, gastropod, marine gastropod, snail, gastropod mollusk, mollusk in, of sea, snail a, a marine, sea snail, the wingspan, wingspan is, moth in, moths, of moth, arctiidae, feed, arctiidae family",
|
| 537 |
+
"db02": "of flowering, flowering plant, of plant, flowering plants, plants in, flowering, shrub, of orchid, fabaceae, grows in, herb, legume, plant in, asteraceae, daisy family, family known, leaves are, the daisy, erect, common names",
|
| 538 |
+
"db03": "album by, the album, an album, this album, full length, live album, album of, compilation album, second album, band's, the band's, album was, album from, an ep, billboard, length album, ep by, a compilation, album in, songs from",
|
| 539 |
+
"db04": "film directed, drama film, and starring, comedy film, it stars, film written, film festival, directed by, documentary film, film starring, lead roles, film was, and directed, film about, film it, directed, thriller film, was directed, film is, international film",
|
| 540 |
+
"db05": "peer reviewed, book by, novel in, is published, a peer, fiction novel, book was, first novel, illustrated by, series written, manga series, academic journal, daily newspaper, newspaper published, a science, reviewed academic, scientific journal, journal published, peer, reviewed"
|
| 541 |
+
},
|
| 542 |
+
"router_anchor": "rt04"
|
| 543 |
+
},
|
| 544 |
+
"emotion": {
|
| 545 |
+
"qkey": "emotion",
|
| 546 |
+
"source": "hf",
|
| 547 |
+
"classes": {
|
| 548 |
+
"em00": "sadness",
|
| 549 |
+
"em01": "joy",
|
| 550 |
+
"em02": "love",
|
| 551 |
+
"em03": "anger",
|
| 552 |
+
"em04": "fear",
|
| 553 |
+
"em05": "surprise"
|
| 554 |
+
},
|
| 555 |
+
"criteria": {
|
| 556 |
+
"em00": "disheartened, homesick, listless, inadequate, feel guilty, unfortunate, rotten, unimportant, doomed, disillusioned, disturbed, feel humiliated, gloomy, unloved, abused, deprived, idiotic, messy, weepy, submissive",
|
| 557 |
+
"em03": "resentful, offended, dangerous, wronged, bitchy, distracted, feel irritated, hostile, envious, feel offended, grouchy, feel frustrated, pissed off, feel resentful, be bothered, feel rushed, feeling pissed, obnoxious, greedy, cranky",
|
| 558 |
+
"em05": "dazed, impressed, dazed and, amazed, feel amazed, stunned, feel curious, amazed at, feel funny, feel surprised, feeling dazed, surprised by, very impressed, curious, curious about, not impressed, shocked, impressed with, feel shocked, feeling curious",
|
| 559 |
+
"em01": "festive, honored, friendly, reassured, sincere, superior, worthwhile, vital, innocent, optimistic, resolved, appreciative, clever, ecstatic, smug, virtuous, contented, honored to, energetic, glamorous",
|
| 560 |
+
"em04": "shaken, apprehensive, paranoid, pressured, distressed, feel threatened, shaky, suspicious, feel pressured, reluctant to, distraught, pressured to, skeptical, terrified, apprehensive about, vulnerable, feel anxious, feel hesitant, feel scared, uncertain about",
|
| 561 |
+
"em02": "nostalgic, loyal, fond, horny, sympathetic, tender, compassionate, fond of, longing for, a longing, loyal to, treasured, supportive, caring about, feel sympathetic, not caring, supportive of, gentle, feeling nostalgic, nostalgic and"
|
| 562 |
+
},
|
| 563 |
+
"router_anchor": "rt05"
|
| 564 |
+
},
|
| 565 |
+
"enron": {
|
| 566 |
+
"qkey": "spam",
|
| 567 |
+
"source": "hf",
|
| 568 |
+
"classes": {
|
| 569 |
+
"en00": "ham",
|
| 570 |
+
"en01": "spam"
|
| 571 |
+
},
|
| 572 |
+
"criteria": {
|
| 573 |
+
"en01": "viagra, xp, sex, meds, brand, oo, cialis, current price, windows xp, medications, drugs, photoshop, corel, medication, graphics, php, adobe photoshop, macromedia, sir, mortgage",
|
| 574 |
+
"en00": "enron, vince, hou ect, forwarded by, ect ect, cc subject, kaminski, subject re, ect cc, enron com, ect on, vince j, j kaminski, enron enron, portland, scheduling, daren, schedules, start date, corp enron"
|
| 575 |
+
},
|
| 576 |
+
"router_anchor": "rt06"
|
| 577 |
+
},
|
| 578 |
+
"game": {
|
| 579 |
+
"qkey": "action",
|
| 580 |
+
"source": "big",
|
| 581 |
+
"classes": {
|
| 582 |
+
"ga00": "dig_in",
|
| 583 |
+
"ga01": "fight",
|
| 584 |
+
"ga02": "flee"
|
| 585 |
+
},
|
| 586 |
+
"criteria": {
|
| 587 |
+
"ga02": "run away escape avoid danger retreat safe",
|
| 588 |
+
"ga01": "attack combat weapon sword strike",
|
| 589 |
+
"ga00": "hide wait build shelter fortify safe"
|
| 590 |
+
},
|
| 591 |
+
"router_anchor": "rt07"
|
| 592 |
+
},
|
| 593 |
+
"guard": {
|
| 594 |
+
"qkey": "irreversible",
|
| 595 |
+
"source": "big",
|
| 596 |
+
"type": "noul_multi",
|
| 597 |
+
"classes": {},
|
| 598 |
+
"criteria": {},
|
| 599 |
+
"router_anchor": "rt08",
|
| 600 |
+
"template_questions": {
|
| 601 |
+
"irreversible": {
|
| 602 |
+
"type": "noul",
|
| 603 |
+
"instructions": "the command is irreversible or destructive"
|
| 604 |
+
},
|
| 605 |
+
"off_task": {
|
| 606 |
+
"type": "noul",
|
| 607 |
+
"instructions": "the command is off task and unrelated to the goal"
|
| 608 |
+
},
|
| 609 |
+
"scope": {
|
| 610 |
+
"type": "choice",
|
| 611 |
+
"instructions": "what does the command touch",
|
| 612 |
+
"criteria": {
|
| 613 |
+
"none": "no changes at all",
|
| 614 |
+
"read": "only reads lists shows",
|
| 615 |
+
"write": "modifies project files or data",
|
| 616 |
+
"global": "system wide destructive or irreversible"
|
| 617 |
+
}
|
| 618 |
+
}
|
| 619 |
+
}
|
| 620 |
+
},
|
| 621 |
+
"hate": {
|
| 622 |
+
"qkey": "speech",
|
| 623 |
+
"source": "hf",
|
| 624 |
+
"classes": {
|
| 625 |
+
"ha00": "hate",
|
| 626 |
+
"ha01": "offensive",
|
| 627 |
+
"ha02": "neither"
|
| 628 |
+
},
|
| 629 |
+
"criteria": {
|
| 630 |
+
"ha01": "bad bitches, loyal, bad bitch, bitch in, that shit, the bitches, 9996, hoes ain't, the bitch, a bitch, basic, bitch http, to fuck, 9995, 9996 65039, gon, you hoes, your bitch, a hoe, these bitches",
|
| 631 |
+
"ha02": "yankees, brownies, the yankees, flappy, flappy bird, jeter, redskins, oreos, apes, early bird, 9733, brownie, derek, derek jeter, jihadi, massage, sole, soles, trash talk, baker",
|
| 632 |
+
"ha00": "of white, is full, the faggots, the us, feminist, ight, jew, marylene58, spic, the south, ultimate faggot, white trash, afc, ag, all die, among, aren't you, ass monkey, at genos, black panthers"
|
| 633 |
+
},
|
| 634 |
+
"router_anchor": "rt09"
|
| 635 |
+
},
|
| 636 |
+
"polarity": {
|
| 637 |
+
"qkey": "sentiment",
|
| 638 |
+
"source": "hf",
|
| 639 |
+
"classes": {
|
| 640 |
+
"po00": "negative",
|
| 641 |
+
"po01": "positive"
|
| 642 |
+
},
|
| 643 |
+
"criteria": {
|
| 644 |
+
"po01": "a must, can't wait, wonderfully, loves it, have for, would highly, helped me, highly recommend, excellent book, a world, grew up, it's also, like about, that make, to share, very informative, must read, 21, another great, are wonderful",
|
| 645 |
+
"po00": "refund, a waste, your money, a refund, contacted, so bad, stopped working, doesn't work, waste of, contact, very disappointing, i contacted, of junk, a disappointment, waste your, poorly written, in addition, is terrible, unfortunately the, disappointing"
|
| 646 |
+
},
|
| 647 |
+
"router_anchor": "rt10"
|
| 648 |
+
},
|
| 649 |
+
"sms": {
|
| 650 |
+
"qkey": "intent",
|
| 651 |
+
"source": "sms",
|
| 652 |
+
"classes": {
|
| 653 |
+
"sm00": "ham",
|
| 654 |
+
"sm01": "spam"
|
| 655 |
+
},
|
| 656 |
+
"criteria": {
|
| 657 |
+
"sm00": "lt, gt, lt gt, i'll, lor, he, da, later, did, much, oh, where",
|
| 658 |
+
"sm01": "claim, prize, 150p, won, your mobile, cs, 18, tone, to claim, 500, co uk, guaranteed"
|
| 659 |
+
},
|
| 660 |
+
"router_anchor": "rt11"
|
| 661 |
+
},
|
| 662 |
+
"tickets_bn": {
|
| 663 |
+
"qkey": "department",
|
| 664 |
+
"source": "big",
|
| 665 |
+
"classes": {
|
| 666 |
+
"tb00": "billing",
|
| 667 |
+
"tb01": "sales",
|
| 668 |
+
"tb02": "technical"
|
| 669 |
+
},
|
| 670 |
+
"criteria": {
|
| 671 |
+
"tb00": "payment or subscription issues",
|
| 672 |
+
"tb02": "bugs or integration problems",
|
| 673 |
+
"tb01": "pricing or account questions"
|
| 674 |
+
},
|
| 675 |
+
"router_anchor": "rt12"
|
| 676 |
+
},
|
| 677 |
+
"tickets_en": {
|
| 678 |
+
"qkey": "department",
|
| 679 |
+
"source": "big",
|
| 680 |
+
"classes": {
|
| 681 |
+
"te00": "billing",
|
| 682 |
+
"te01": "sales",
|
| 683 |
+
"te02": "technical"
|
| 684 |
+
},
|
| 685 |
+
"criteria": {
|
| 686 |
+
"te00": "payment or subscription issues",
|
| 687 |
+
"te02": "bugs or integration problems",
|
| 688 |
+
"te01": "pricing or account questions"
|
| 689 |
+
},
|
| 690 |
+
"router_anchor": "rt13"
|
| 691 |
+
},
|
| 692 |
+
"tickets_hi": {
|
| 693 |
+
"qkey": "department",
|
| 694 |
+
"source": "big",
|
| 695 |
+
"classes": {
|
| 696 |
+
"th00": "billing",
|
| 697 |
+
"th01": "sales",
|
| 698 |
+
"th02": "technical"
|
| 699 |
+
},
|
| 700 |
+
"criteria": {
|
| 701 |
+
"th00": "payment or subscription issues",
|
| 702 |
+
"th02": "bugs or integration problems",
|
| 703 |
+
"th01": "pricing or account questions"
|
| 704 |
+
},
|
| 705 |
+
"router_anchor": "rt14"
|
| 706 |
+
},
|
| 707 |
+
"tickets_ru": {
|
| 708 |
+
"qkey": "department",
|
| 709 |
+
"source": "big",
|
| 710 |
+
"classes": {
|
| 711 |
+
"tr00": "billing",
|
| 712 |
+
"tr01": "sales",
|
| 713 |
+
"tr02": "technical"
|
| 714 |
+
},
|
| 715 |
+
"criteria": {
|
| 716 |
+
"tr00": "payment or subscription issues",
|
| 717 |
+
"tr02": "bugs or integration problems",
|
| 718 |
+
"tr01": "pricing or account questions"
|
| 719 |
+
},
|
| 720 |
+
"router_anchor": "rt15"
|
| 721 |
+
},
|
| 722 |
+
"_router": {
|
| 723 |
+
"criteria": {
|
| 724 |
+
"rt00": "news headlines world sports business technology",
|
| 725 |
+
"rt01": "banking cards payments transfers refunds loans",
|
| 726 |
+
"rt02": "reading comprehension questions with passages",
|
| 727 |
+
"rt03": "virtual assistant everyday requests travel weather alarms",
|
| 728 |
+
"rt04": "encyclopedia topics entities places companies",
|
| 729 |
+
"rt05": "personal feelings emotions reactions",
|
| 730 |
+
"rt06": "long email messages inboxes forwarding",
|
| 731 |
+
"rt07": "game state commands actions fight flee dig",
|
| 732 |
+
"rt08": "safety checks irreversible destructive actions",
|
| 733 |
+
"rt09": "social media posts offensive language moderation",
|
| 734 |
+
"rt10": "product reviews opinions shopping",
|
| 735 |
+
"rt11": "short text messages promotions spam",
|
| 736 |
+
"rt12": "customer support conversations in bengali",
|
| 737 |
+
"rt13": "customer support conversations billing sales technical",
|
| 738 |
+
"rt14": "customer support conversations in hindi devanagari",
|
| 739 |
+
"rt15": "customer support conversations in russian"
|
| 740 |
+
}
|
| 741 |
+
}
|
| 742 |
+
},
|
| 743 |
+
"router": {
|
| 744 |
+
"agnews": "rt00",
|
| 745 |
+
"bank77": "rt01",
|
| 746 |
+
"boolq": "rt02",
|
| 747 |
+
"clinc": "rt03",
|
| 748 |
+
"dbpedia": "rt04",
|
| 749 |
+
"emotion": "rt05",
|
| 750 |
+
"enron": "rt06",
|
| 751 |
+
"game": "rt07",
|
| 752 |
+
"guard": "rt08",
|
| 753 |
+
"hate": "rt09",
|
| 754 |
+
"polarity": "rt10",
|
| 755 |
+
"sms": "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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SyFox Architecture — the SI substrate core
|
| 2 |
+
|
| 3 |
+
This document specifies exactly what happens between "state in" and "decision
|
| 4 |
+
out", and which mechanisms are ported from the Synthetic-Intelligence (SI)
|
| 5 |
+
research substrate. The rule that governs this codebase:
|
| 6 |
+
|
| 7 |
+
> **The core is SI physics only.** No transformer, no neural network, no
|
| 8 |
+
> pattern-matching classifier. Everything below is field dynamics over an
|
| 9 |
+
> explicit concept graph. Tools (JSON, CLI, HTTP, calibration math) live
|
| 10 |
+
> outside the core and never rewrite it.
|
| 11 |
+
|
| 12 |
+
## 1. Concepts and acoustic mass
|
| 13 |
+
|
| 14 |
+
Every lowercase folded token interned by the engine becomes a **concept node**
|
| 15 |
+
(`core/si_substrate.hpp`, `Substrate::intern`). Nodes carry:
|
| 16 |
+
|
| 17 |
+
* **mass** — a raw occurrence count: `intern()` adds exactly `1.0` each time
|
| 18 |
+
the concept appears in any lesson. It is **linear, not log-compressed**.
|
| 19 |
+
*Lineage:* SI "acoustic mass" — heavier units respond less to the same
|
| 20 |
+
stimulus. The sub-linear behavior lives at the **use sites**, not in the
|
| 21 |
+
counter: injection deposits `energy / sqrt(mass)` and Hebbian bind strength
|
| 22 |
+
scales by `1/sqrt(mass)`, so frequent concepts ("the", "please") cannot
|
| 23 |
+
flood the field.
|
| 24 |
+
* **energy** — transient; injected and dissipated per decision.
|
| 25 |
+
|
| 26 |
+
(An earlier revision also carried a `salience` field. Audit found it was
|
| 27 |
+
write-only — incremented at injection, read nowhere; gating selects sources
|
| 28 |
+
by energy — so it was removed. Dead state in the core is doc debt.)
|
| 29 |
+
|
| 30 |
+
Token folding (`fold`) is deterministic string normalization (plural / `-ed` /
|
| 31 |
+
`-ing` / trailing `e`), applied identically to states, options, and
|
| 32 |
+
instructions. It is I/O hygiene, not linguistics and not pattern matching.
|
| 33 |
+
|
| 34 |
+
## 2. Lanes (Hebbian bindings)
|
| 35 |
+
|
| 36 |
+
Lanes are weighted edges between concepts, stored sparsely per node with a
|
| 37 |
+
per-node lane cap (weakest lane evicted, bounded memory).
|
| 38 |
+
|
| 39 |
+
* **Bind** (`hebbian_lesson`): for a labelled lesson, every active state
|
| 40 |
+
concept binds to every outcome concept with
|
| 41 |
+
`η · (1/√mass_a + 1/√mass_b) · scale`. Adjacent state tokens also bind
|
| 42 |
+
(the co-occurrence fabric that lets energy diffuse inside a phrase).
|
| 43 |
+
*Lineage:* SI Hebbian lane bindings in `physics.hpp`.
|
| 44 |
+
* **Weaken** (`weaken`): counter-evidence subtracts lane weight; a lane whose
|
| 45 |
+
weight reaches zero dissolves. Used by Noul lessons labelled false.
|
| 46 |
+
* **Decay** (`lane_decay`): every lesson multiplies all lanes by 0.995 —
|
| 47 |
+
unused routes fade.
|
| 48 |
+
|
| 49 |
+
Learning is substrate rewiring. There are no fitted weights anywhere in the
|
| 50 |
+
core; the calibration tool (below) is external and read-only.
|
| 51 |
+
|
| 52 |
+
## 3. Injection
|
| 53 |
+
|
| 54 |
+
A state is tokenized; every token that exists in the vocabulary deposits
|
| 55 |
+
`inject_energy / sqrt(mass)` on its node. Unknown tokens stay dark — this is
|
| 56 |
+
the first half of the honest-silence contract (a state of nothing but unknown
|
| 57 |
+
words settles zero energy and defers).
|
| 58 |
+
|
| 59 |
+
## 4. Settle (the System One pass)
|
| 60 |
+
|
| 61 |
+
`settle()` runs up to `k_settle` (default 8) dissipative diffusion passes:
|
| 62 |
+
|
| 63 |
+
1. Sources are gated by **source cap** (`source_cap`, 24 by default): the
|
| 64 |
+
top-K nodes propagate each pass — ranked **by energy** by default, or by
|
| 65 |
+
**salience** when `salience_gating` is on. Gated nodes keep their energy
|
| 66 |
+
(they remain readout-visible); the cap gates flow, it does not
|
| 67 |
+
annihilate. (An earlier version pruned energy outright and destroyed 97%
|
| 68 |
+
of the field — the gating form is the correct physics and the tests pin
|
| 69 |
+
it.)
|
| 70 |
+
|
| 71 |
+
**SI salience lineage, restored after audit.** The SI substrate runs a
|
| 72 |
+
cavity salience integrator, `s = tanh(s·decay + gain·|velocity|)`
|
| 73 |
+
(`physics.hpp`, `salience_gain = 0.05`, `salience_decay = 0.995`), and
|
| 74 |
+
its TSDA layer samples the live working cap from
|
| 75 |
+
`[working_cap−4, working_cap]` = [5,9] (Miller 7 ± 2). SyFox ports both:
|
| 76 |
+
the integrator runs **every pass** on the motion proxy `|ΔE|` (a node at
|
| 77 |
+
rest is an exact fixed point, mirroring SI's sparsity guard), and
|
| 78 |
+
`miller_window = true` samples the live cap from
|
| 79 |
+
`[source_cap−4, source_cap]` each decision. One deliberate adaptation:
|
| 80 |
+
SI draws the sample from a seeded mt19937 stream; SyFox derives it from
|
| 81 |
+
the decision's state hash, so the same state always settles to the same
|
| 82 |
+
field bit-for-bit (the persistence contract outranks stochasticity).
|
| 83 |
+
`inject()` spikes salience to 1.0 on touch (TSDA spike semantics).
|
| 84 |
+
|
| 85 |
+
*Benchmark (10 in-domain decisions, 3 domains).* default energy gating
|
| 86 |
+
10/10 with calibrated-shaped confidences; salience ranking at the wide
|
| 87 |
+
cap 4/10 (motion history is a poor selector when the cap rarely trims);
|
| 88 |
+
salience + literal [5,9] window 10/10 argmax but probabilities saturate
|
| 89 |
+
at 1.0 (calibration collapse — needs the v0.2 eval harness before
|
| 90 |
+
adoption); Miller window at wide cap 9/10. Verdict: default stays
|
| 91 |
+
energy-gated at a fixed 24; the SI-faithful modes ship behind config
|
| 92 |
+
flags until a held-out eval says otherwise.
|
| 93 |
+
2. Each source retains `(1 − diffusion)` of its decayed energy and flows
|
| 94 |
+
`diffusion` out along its lanes, split proportionally to lane weight:
|
| 95 |
+
`next[b] += e·decay·diffusion·(w_ab / Σw_a)`.
|
| 96 |
+
3. Total energy is non-increasing (dissipative); the pass loop stops early
|
| 97 |
+
when the field relaxes (`total_before − total_after < eps`).
|
| 98 |
+
|
| 99 |
+
One settle per decision — all questions read the same settled field. Adding
|
| 100 |
+
questions never re-settles the substrate: flat marginal latency by structure,
|
| 101 |
+
not by scheduling.
|
| 102 |
+
|
| 103 |
+
**Derivation, not retrieval.** Because diffusion is multi-hop, a state that
|
| 104 |
+
was never in any lesson still settles to a computed answer: energy crosses
|
| 105 |
+
the co-occurrence fabric into outcome lanes laid down by *other* lessons.
|
| 106 |
+
Probe (two lessons, `alpha beta`→x and `beta gamma`→y): the untaught state
|
| 107 |
+
`alpha` alone settles with y at 0.494 — lesson 2 never mentioned alpha; the
|
| 108 |
+
two-hop path alpha→beta→y carried the evidence. The boundary is the taught
|
| 109 |
+
vocabulary and lane fabric: concepts never interned have no node, unknown
|
| 110 |
+
words settle to zero energy and defer (§6). This is the substrate-level
|
| 111 |
+
kernel of the SI stack's explicit derivation layers (meta-learner
|
| 112 |
+
macro-rules, dreamer emergent resonances, analogical mapping) — not yet
|
| 113 |
+
ported; see ROADMAP v0.3.
|
| 114 |
+
|
| 115 |
+
## 5. Readout (resonance sweep, two lanes)
|
| 116 |
+
|
| 117 |
+
Probes read the settled field at their own concepts: direct node energy plus a
|
| 118 |
+
hop term through lanes. Two readout lanes exist because two question shapes
|
| 119 |
+
need two different questions of the field:
|
| 120 |
+
|
| 121 |
+
* **Specific** (`choice`, `score`): mean lane support —
|
| 122 |
+
`hop · Σ w·e_n / Σ w`. Rewards precise coupling; a node bound diffusely to
|
| 123 |
+
half the vocabulary cannot out-read a node bound exactly to this state.
|
| 124 |
+
Options are then normalized by softmax at the fitted temperature.
|
| 125 |
+
* **Support** (`noul`): active lane mass — `hop · Σ w·e_n` (unnormalized).
|
| 126 |
+
A statement may be corroborated broadly; what matters is how much
|
| 127 |
+
lane-connected energy the field offers it. The ratio to total field energy
|
| 128 |
+
is the statement's **support**.
|
| 129 |
+
|
| 130 |
+
Both are field measurements. No weights are fitted at readout; no classes
|
| 131 |
+
exist in the core.
|
| 132 |
+
|
| 133 |
+
## 6. Honest silence
|
| 134 |
+
|
| 135 |
+
If settled field energy is below `silence_floor` (0.05):
|
| 136 |
+
|
| 137 |
+
* empty state → `deferred: true, reason: "empty_state"`
|
| 138 |
+
* all-unknown vocabulary → `reason: "unknown_vocabulary"`
|
| 139 |
+
* settled but dark → `reason: "honest_silence"`
|
| 140 |
+
|
| 141 |
+
The engine refuses to guess from nothing. *Lineage:* the SI interface's
|
| 142 |
+
honest-silence dispatch — answers only when the readout actually collapsed.
|
| 143 |
+
|
| 144 |
+
## 7. Calibration (a tool, not core)
|
| 145 |
+
|
| 146 |
+
`fit_calibration` collects readout energies on labelled rows and fits, purely
|
| 147 |
+
outside the core:
|
| 148 |
+
|
| 149 |
+
* **temperature** per choice/score — golden-section search on NLL of
|
| 150 |
+
`softmax(E_correct/T, E_wrong/T)`.
|
| 151 |
+
* **Platt scaling** for noul — logistic regression `sigmoid(a·support + b)`
|
| 152 |
+
on supports, gradient descent to convergence (separable data needs a steep
|
| 153 |
+
slope; the fit runs 4000 iterations with decaying lr).
|
| 154 |
+
|
| 155 |
+
Calibration changes how energies are *reported* as probabilities, never how
|
| 156 |
+
they are produced. Confidence for choice/score is the normalized-entropy
|
| 157 |
+
margin of the distribution; for noul it is `|p − 0.5|·2`.
|
| 158 |
+
|
| 159 |
+
## 8. Persistence
|
| 160 |
+
|
| 161 |
+
`save_model` writes `substrate.bin` (vocabulary + masses + lanes, binary),
|
| 162 |
+
`calibration.json`, and `meta.json`. Loading is exact — the same state settles
|
| 163 |
+
to the same readout bit-for-bit (pinned by tests).
|
| 164 |
+
|
| 165 |
+
## 9. Provenance
|
| 166 |
+
|
| 167 |
+
| Mechanism | Origin |
|
| 168 |
+
|---|---|
|
| 169 |
+
| Energy injection + field settle | SI `physics.hpp` substrate dynamics |
|
| 170 |
+
| Source capping (top-K, energy or salience) | SI working-set cap + TSDA live_cap ([cap−4, cap], Miller 7 ± 2) |
|
| 171 |
+
| Salience integrator tanh(s·decay + gain·motion) | SI `physics.hpp` cavity salience (verified live there) |
|
| 172 |
+
| Hebbian lane bindings + decay | SI lane learning |
|
| 173 |
+
| Honest silence | SI dispatch contract |
|
| 174 |
+
| Typed Choice/Score/Noul API | interface shape inspired by TypeSafe Jev |
|
| 175 |
+
| Temperature/Platt calibration | classical statistics (tool layer) |
|
| 176 |
+
| Derivation layer (§10) | SyFox-native design after studying SI meta_learner / dreamer / analogy as mechanism reference — no code copied; weight algebra on lanes instead of typed relation rules |
|
| 177 |
+
| No-regression gate (§11) | SyFox-native: transactional derive + bit-exact fabric snapshot/restore; policy refined by a full strength-scan (taught-row integrity + no manufactured certainty) |
|
| 178 |
+
| Jev-parity bench (§12) | SyFox-native: axis lineage from TypeSafe's published Jev material + community classification benchmarks; all numbers produced by this repo's binary |
|
| 179 |
+
| Recall (§13) | Hopfield-style associative memory reinterpreted as settled-field cosine — SI-physics-native, zero symbol-space similarity |
|
| 180 |
+
|
| 181 |
+
## 10. Derivation layer (offline, explicit)
|
| 182 |
+
|
| 183 |
+
SyFox's lanes so far carried only lived experience (`learn`). The derivation
|
| 184 |
+
layer lets the field grow knowledge **derived from** its own fabric — the
|
| 185 |
+
substrate-level kernel of what the upstream SI stack does with explicit rule
|
| 186 |
+
machinery (meta-learner macro-rules, dreamer emergent resonances, analogical
|
| 187 |
+
mapping). The primitives differ by constitution: SI composes typed relation
|
| 188 |
+
triples over a fact graph; SyFox composes **weighted lane paths** — weight
|
| 189 |
+
algebra and field dynamics, no classifiers. All engines are OFFLINE, explicit
|
| 190 |
+
CLI steps; `decide()` stays read-only and byte-identical unless the operator
|
| 191 |
+
derives on a model. Provenance: derived lanes carry a **generation counter**
|
| 192 |
+
(experienced / human-promoted = 0, each composition step +1, cap 3), persisted
|
| 193 |
+
as a versioned tail in `substrate.bin`; v1 files load clean (generation 0).
|
| 194 |
+
|
| 195 |
+
**1. Lane induction, compose mode** (`syfox derive --model DIR`): a two-hop
|
| 196 |
+
path A→B→C is evidence for A↔C, with three guards that each came out of a
|
| 197 |
+
real benchmark failure:
|
| 198 |
+
* *acoustic-mass damping* — path evidence is damped by `1/√mass(B)`, the same
|
| 199 |
+
law `settle()` applies to energy through B; without it, hub tokens ("the",
|
| 200 |
+
"command") fabricated corroboration between unrelated concepts and two demo
|
| 201 |
+
argmaxes flipped;
|
| 202 |
+
* *top-K corroboration* (K=3) — a dense fabric offers hundreds of two-hop
|
| 203 |
+
paths; treating them as independent evidence saturated the field (noul
|
| 204 |
+
collapsed to 0.999 everywhere);
|
| 205 |
+
* *ghost-guarded verifier* — every derived lane is re-checked against the
|
| 206 |
+
LIVE fabric (snapshot ghosts of already-dissolved lanes cannot justify
|
| 207 |
+
anything), over-claims are healed down to their justification, unsupported
|
| 208 |
+
ones dissolve. Composition is raise-only: observed lanes are never weakened.
|
| 209 |
+
|
| 210 |
+
**2. Lane induction, harvest mode** (`syfox derive --model DIR --examples
|
| 211 |
+
FILE.jsonl`): static algebra guesses; the settled field knows. Replay states
|
| 212 |
+
through inject→settle and record which concept pairs genuinely **co-activate**.
|
| 213 |
+
Dissipation does the filtering — cross-scenario energy decays before it
|
| 214 |
+
registers. Observed lanes are untouchable; gen-1 lanes must be re-nominated by
|
| 215 |
+
every run or they dissolve (justification is recomputable, hence deterministic).
|
| 216 |
+
Labels are not needed: the field learns structure from unlabelled exposure.
|
| 217 |
+
|
| 218 |
+
**3. Dreamer** (`syfox dream --model DIR [--steps N] [--seed S]`): inject
|
| 219 |
+
small random energy patterns, settle, and watch for undriven nodes that lit
|
| 220 |
+
up **without any direct lane to the driven set** — reached only through the
|
| 221 |
+
topology's own interference. Candidates go to `model-*/mutations.jsonl`. The
|
| 222 |
+
substrate is never modified by dreaming; a human sets `validated:true` on a
|
| 223 |
+
line and `syfox promote` applies it as a premise-grade lane. Same seed → same
|
| 224 |
+
dream, bit for bit.
|
| 225 |
+
|
| 226 |
+
**4. Analogy** (`syfox analogs --model DIR --concept WORD`, read-only): a
|
| 227 |
+
concept's signature is its lane neighbourhood (who it touches, both
|
| 228 |
+
directions); structural isomorphism = signature Jaccard; novelty potential
|
| 229 |
+
follows the L9 formulation `Phi = I·exp(k·d)`. High Phi = structurally aligned
|
| 230 |
+
AND fabric-distant: a transfer *hypothesis* for the human, never auto-applied.
|
| 231 |
+
|
| 232 |
+
*Benchmark (v0.2 → v2.1, honest).* The v0.2 verdict was measured on
|
| 233 |
+
resubstitution (eval rows = training rows): compose sharpened tickets demos
|
| 234 |
+
(technical conf 0.251→0.454) but flipped game/guard rows; harvest lifted
|
| 235 |
+
billing 0.604→0.912 but flipped a close call; no strength avoided taught-row
|
| 236 |
+
flips on the mixed-label fabrics. v2.1 replaces the measurement basis: the
|
| 237 |
+
gate now replays the HELD-OUT split (generalization safety, not memorized
|
| 238 |
+
behavior) and the harness decides per model — game ships derived (253 lanes,
|
| 239 |
+
0 held-out flips, accuracy held 0.667→0.667), tickets (9 flips) and guard
|
| 240 |
+
(1 flip) ship un-derived with the reason logged. Same enforcement philosophy,
|
| 241 |
+
honest measurement basis.
|
| 242 |
+
|
| 243 |
+
## 11. The no-regression gate (transactional derivation)
|
| 244 |
+
|
| 245 |
+
Derivation writes into the fabric; the gate (`core/gate.hpp`, CLI
|
| 246 |
+
`syfox derive --gate FILE.jsonl`) makes that write safe by construction:
|
| 247 |
+
|
| 248 |
+
1. replay every labelled row + generated close-call probes (cross-domain
|
| 249 |
+
state mixtures, deterministic generator shared with `bench`) → baseline
|
| 250 |
+
decision signatures;
|
| 251 |
+
2. snapshot the fabric **bit-exactly** — `snapshot_fabric()` copies each
|
| 252 |
+
node's lane vector in insertion order plus the provenance map, because
|
| 253 |
+
`settle()` sums over lanes in vector order (a weight set is not the
|
| 254 |
+
state);
|
| 255 |
+
3. run the derivation (conservative presets: harvest co_floor 0.15/gain
|
| 256 |
+
0.35/budgets 8·512, compose gain 0.25/top-2/budget 4);
|
| 257 |
+
4. replay the same probe set → compare;
|
| 258 |
+
5. **policy**: (a) any argmax flip on a TAUGHT row reverts — labelled
|
| 259 |
+
knowledge must survive derivation; (b) any RISE in mean confidence on the
|
| 260 |
+
MIXED probes reverts — close-call states are ambiguous by construction,
|
| 261 |
+
their argmax may re-resolve, but manufactured certainty about them is the
|
| 262 |
+
exact failure the gate exists to kill;
|
| 263 |
+
6. revert = `restore_fabric(snapshot)` → the fabric is bit-identical and
|
| 264 |
+
`decide()` output is byte-identical (pinned by test); commit = the caller
|
| 265 |
+
saves the model.
|
| 266 |
+
|
| 267 |
+
Strength-scan evidence (scripts/syfox_gate_scan.cpp, all strengths from
|
| 268 |
+
default down to 32 lanes): tickets reverts everywhere (8–18 taught flips —
|
| 269 |
+
its seed data mixes refund/invoice labels across billing and sales), guard
|
| 270 |
+
reverts at every useful strength, game commits at the conservative strength.
|
| 271 |
+
Per-model outcome: `model-game` ships derived (668 lanes, 0 taught flips,
|
| 272 |
+
mixed mean confidence 0.975→0.886 — the fabric got MORE honest about close
|
| 273 |
+
calls; demo argmaxes 3/3 unchanged; `make models` reproduces). `model-tickets`
|
| 274 |
+
and `model-guard` ship un-derived because the gate proves it, not because a
|
| 275 |
+
human remembered to check.
|
| 276 |
+
|
| 277 |
+
## 12. The Jev-parity benchmark (`syfox bench`)
|
| 278 |
+
|
| 279 |
+
`core/bench.hpp` measures the axes the System One model class is judged on
|
| 280 |
+
(axis lineage verified against TypeSafe's published Jev material and the
|
| 281 |
+
community classification benchmarks, Sept 2026): decision accuracy, latency
|
| 282 |
+
percentiles, calibration (ECE, 10 bins, + conf-when-correct vs
|
| 283 |
+
conf-when-wrong gap), honesty (OOD probes built from deterministic nonsense
|
| 284 |
+
vocabulary checked against the model's own — untaught tokens must defer),
|
| 285 |
+
guardrail hold precision/recall (noul confusion at the 0.5 threshold),
|
| 286 |
+
determinism (full replay compared byte-wise), and close-call margin
|
| 287 |
+
distribution (mixed cross-domain states; the same generator the gate
|
| 288 |
+
replays). Accuracy/calibration/guardrail aggregate over LABELLED rows only;
|
| 289 |
+
unlabelled mixed probes never pollute accuracy denominators (a real bug the
|
| 290 |
+
e2e suite caught). Every report carries a `jev_reference` block with the
|
| 291 |
+
PUBLISHED figures (67.8% workflow accuracy, 70–500 ms, pi-warden 88% hold
|
| 292 |
+
precision) for side-by-side reading — axes shared, numbers not compared
|
| 293 |
+
against toy-data resubstitution.
|
| 294 |
+
|
| 295 |
+
Seed-model results, v2.1 methodology — HELD-OUT split (70/30, stratified,
|
| 296 |
+
deterministic; `make bench-heldout`), post-gate derivation state. The v0.2
|
| 297 |
+
table that stood here measured in-domain resubstitution (eval rows = training
|
| 298 |
+
rows) and is retired; in-sample numbers remain available via `make bench` as
|
| 299 |
+
a regression contrast only.
|
| 300 |
+
|
| 301 |
+
| model | held-out choice acc (n) | score acc (n) | choice ECE | OOD defer | p50 / p95 |
|
| 302 |
+
|---|---|---|---|---|---|
|
| 303 |
+
| tickets | 1.000 (6) | 0.667 (6) | 0.012 | 1.00 | 64 / 80 µs |
|
| 304 |
+
| game (derived, gate PASS) | 0.667 (3) | — | 0.329 | 1.00 | 29 / 40 µs |
|
| 305 |
+
| guard | 0.750 (4) | — | 0.200 | 1.00 | 34 / 45 µs |
|
| 306 |
+
|
| 307 |
+
Reading: the held-out gap against in-sample (tickets 1.000 vs 1.000; guard
|
| 308 |
+
0.750 vs 0.778) is now measured instead of assumed. Calibration is fitted on
|
| 309 |
+
held-out rows only (2–3 scalars; multi-class NLL objective, 1-bit ECE
|
| 310 |
+
adoption guard) — tickets reaches ECE 0.012; game/guard are held above the
|
| 311 |
+
0.1 bar by a single held-out error each, which is arithmetic (1 wrong of
|
| 312 |
+
3–4 emitted forces ECE ≥ ~0.2), not a tuning failure. The headline metric is
|
| 313 |
+
the coverage-vs-accuracy curve (`make coverage`): tickets trades 100%
|
| 314 |
+
coverage @ 83.3% accuracy for 50% coverage @ 100% — the confident subset is
|
| 315 |
+
trustworthy, measurably. Paraphrase augmentation was implemented, measured on
|
| 316 |
+
the held-out split, and REJECTED by default (intern mass is linear, injection
|
| 317 |
+
damps 1/√mass: re-teaching near-duplicates re-weights the field toward the
|
| 318 |
+
training surface forms; tickets 1.000 → 0.500). The derivation gate replays
|
| 319 |
+
held-out rows and decides per model: game ships derived, tickets/guard ship
|
| 320 |
+
un-derived. Honesty stays structural (1.00 OOD defer everywhere); latency is
|
| 321 |
+
three to four orders of magnitude under the Jev band with the same one-pass
|
| 322 |
+
shape.
|
| 323 |
+
|
| 324 |
+
## 13. Recall (associative retrieval in energy space)
|
| 325 |
+
|
| 326 |
+
`core/recall.hpp`, CLI `syfox recall --state '...' --memories FILE.jsonl`.
|
| 327 |
+
Content-addressable memory the only way the constitution allows: settle the
|
| 328 |
+
query into an energy fingerprint (one float per node, L2-normalized), settle
|
| 329 |
+
each stored memory the same way, rank by cosine of the two settled fields.
|
| 330 |
+
No token comparison, no string distance, no n-gram overlap, no embedding
|
| 331 |
+
table, no transformer — similarity is measured in the substrate's own state
|
| 332 |
+
space, so two states resonate exactly as far as the field routes them
|
| 333 |
+
together. Unknown vocabulary resonates with nothing (empty hits — honest
|
| 334 |
+
silence, since `inject` skips unknown tokens). Read-only, bit-deterministic;
|
| 335 |
+
memory stores accept `{"state","label"}` rows or the training schema
|
| 336 |
+
(label = first label value). On the derived game model the zombie query
|
| 337 |
+
recalls the flee lessons at 0.9696–0.9421 with fight lessons at ≤0.856.
|
| 338 |
+
|
| 339 |
+
## 14. v3 — the hidden-test firewall and the evidence ledger
|
| 340 |
+
|
| 341 |
+
### 14.1 Firewall (core/firewall.hpp)
|
| 342 |
+
|
| 343 |
+
The 70/15/15 train/cal/hidden contract is enforced where a typo cannot
|
| 344 |
+
bypass it: the CLI consults the file's split role (decided by its filename
|
| 345 |
+
suffix — `_train`, `_cal`, `_hidden`, `_heldout`, anything else is
|
| 346 |
+
unclassified and stays readable, because worksheets and paraphrase files
|
| 347 |
+
must remain learnable) before opening anything.
|
| 348 |
+
|
| 349 |
+
| role | suffix | learn | calibrate | derive --gate | bench |
|
| 350 |
+
|-----------|-------------------|-------|-----------|---------------|-------|
|
| 351 |
+
| train | `_train.jsonl` | YES | yes | yes | yes |
|
| 352 |
+
| heldout | `_heldout.jsonl` | yes | YES | yes | yes |
|
| 353 |
+
| cal | `_cal.jsonl` | no | YES | yes | yes |
|
| 354 |
+
| hidden | `_hidden.jsonl` | NO | NO | NO | YES |
|
| 355 |
+
|
| 356 |
+
Rationale: calibration files exist to fit 2–3 scalars (temperature/Platt)
|
| 357 |
+
on rows the fabric never learned from. Hidden files exist to be SCORED,
|
| 358 |
+
once. A hidden row that leaks into any build path is not a mistake — it is
|
| 359 |
+
a different (worthless) number. `make firewall-check` runs the four
|
| 360 |
+
refusals against the real binary.
|
| 361 |
+
|
| 362 |
+
### 14.2 Evidence ledger (v3, Milestone 3)
|
| 363 |
+
|
| 364 |
+
Every lane key carries a `LaneEvidence` record: `support_events`,
|
| 365 |
+
`counter_events` (anti-Hebbian dissolutions), `generation` (derivation
|
| 366 |
+
provenance), `first_seq` / `last_seq` (teach-event window), and the
|
| 367 |
+
engine-set context tag (which substrate/model owned the event). The ledger
|
| 368 |
+
persists as an optional tail on `substrate.bin`; v2 files load unchanged
|
| 369 |
+
(the tail is detected at EOF) and v3 files load on v2 readers that stop at
|
| 370 |
+
the v2 end.
|
| 371 |
+
|
| 372 |
+
`decide --evidence` projects the ledger for the lanes the decision
|
| 373 |
+
actually used — a READ-ONLY view. The field is driven by lane weights;
|
| 374 |
+
the ledger never feeds back into physics. It exists so a decision can be
|
| 375 |
+
audited after the fact: which lanes, how strong, taught when, by which
|
| 376 |
+
corpus, disputed how many times.
|
| 377 |
+
|
| 378 |
+
### 14.3 Contradictions
|
| 379 |
+
|
| 380 |
+
Teaching the same (state, question) with a different outcome is a
|
| 381 |
+
contradiction: it increments the learn report's `contradictions` counter,
|
| 382 |
+
writes a contradiction record (old outcome, new outcome, both seq numbers,
|
| 383 |
+
state hash, context), and marks the affected lanes with a counter event —
|
| 384 |
+
the anti-Hebbian term weakens the disputed binding exactly as the physics
|
| 385 |
+
specifies. There is no last-write-wins: the field keeps the binding its
|
| 386 |
+
weights support, and the dispute stays on the record (`contested: true`
|
| 387 |
+
in the decide evidence view). Silent override is a design error, and the
|
| 388 |
+
adversarial suite (§15 of the README; `make adv-big`) tests for it with a
|
| 389 |
+
control arm that separates contradiction-specific damage from the generic
|
| 390 |
+
cost of re-teaching.
|
| 391 |
+
|
| 392 |
+
## 15. v3 — multicore settle and the GPU gate (M5)
|
| 393 |
+
|
| 394 |
+
### 15.1 CSR mirror
|
| 395 |
+
|
| 396 |
+
The settle hot path reads a compressed-sparse-row mirror of the out-lane
|
| 397 |
+
fabric: `csr_off_` (n+1 offsets), `csr_dst_`, `csr_w_` — contiguous
|
| 398 |
+
buffers, rebuilt lazily when the fabric mutates. The build copies each
|
| 399 |
+
source's lane vector verbatim, so per-source iteration order is exactly
|
| 400 |
+
the map order the sequential settle used: every float sum keeps its exact
|
| 401 |
+
operand order and results are bit-identical. This is the layout a GPU
|
| 402 |
+
port generalizes.
|
| 403 |
+
|
| 404 |
+
### 15.2 Deterministic OpenMP settle
|
| 405 |
+
|
| 406 |
+
`make omp` builds the same sources with `-fopenmp`. The diffusion pass
|
| 407 |
+
partitions sources with a static schedule (contiguous ascending chunks);
|
| 408 |
+
each thread scatters into its own buffer; the buffers are combined in
|
| 409 |
+
ascending thread order; therefore every accumulator sees contributions in
|
| 410 |
+
ascending SOURCE order — the sequential order. Bit-identity is a gate,
|
| 411 |
+
not a hope: `make omp-identity` fails the build if sequential and
|
| 412 |
+
`--threads 2` reports differ in any block (routing, calibration, honesty,
|
| 413 |
+
guardrail). Measured honestly: below ~10k nodes on a 2-core sandbox the
|
| 414 |
+
deterministic parallel settle is slower than sequential (thread
|
| 415 |
+
coordination exceeds the gain); it pays on denser fabrics.
|
| 416 |
+
|
| 417 |
+
### 15.3 Batched throughput and the GPU gate
|
| 418 |
+
|
| 419 |
+
`bench --throughput N` measures decisions/sec with N worker threads, each
|
| 420 |
+
owning a PRIVATE engine copy (decisions mutate the field, so workers never
|
| 421 |
+
share a substrate). It is a performance axis, not an accuracy headline —
|
| 422 |
+
a non-zero checksum proves the work happened. Measured on the 3,518-node
|
| 423 |
+
tickets fabric: 2,390 → 3,714 decisions/sec at N=2 on 2 cores.
|
| 424 |
+
|
| 425 |
+
The GPU port gate is MEASURED, not assumed: `make density` reports per-
|
| 426 |
+
fabric density and mean out-degree (tickets 0.0067 @ degree 23.5, game
|
| 427 |
+
0.0458, guard 0.0485). A GPU port happens when dense substrates make the
|
| 428 |
+
transfer costs pay for themselves — until then it stays design, and the
|
| 429 |
+
SoA/CSR buffers above are the only GPU-specific preparation the core
|
| 430 |
+
carries. No neural network enters the core at any point; the parallelism
|
| 431 |
+
is the SAME physics, executed on more cores.
|
docs/EVALUATION.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Giant model — measured evaluation (v3.1.3, one interleaved pass)
|
| 2 |
+
|
| 3 |
+
All numbers below are from real runs of the committed binary and corpora
|
| 4 |
+
(deterministic; seed 77). Engine: SyFox 3.1.2 substrate + v3.1.3 CLI routing
|
| 5 |
+
fix. `energy-norm` ON everywhere (mandatory at corpus scale — v3.1.0).
|
| 6 |
+
Selection (calibration, router wording) used CAL only; hidden was scored
|
| 7 |
+
once. Per-row records: `datasets/eval/dump_pass1.jsonl`.
|
| 8 |
+
|
| 9 |
+
## Corpus
|
| 10 |
+
|
| 11 |
+
16 domains, 76,142 train rows (152,284 lessons per epoch), 278 globally
|
| 12 |
+
unique opaque anchors, 3 full per-script calibration files + 1 latin merge.
|
| 13 |
+
Recipe (the three failure-mode fixes): empty per-row instructions at learn;
|
| 14 |
+
globally-unique anchors; round-robin domain interleave. Criteria: preserved
|
| 15 |
+
verbatim for tickets/game/guard/bank77/sms (keys remapped to anchors),
|
| 16 |
+
mined top-10 for the 8 new HF domains (train rows only). See
|
| 17 |
+
`datasets/MANIFEST.json`.
|
| 18 |
+
|
| 19 |
+
## Hidden results — latin substrate (model-giant-latin, 43,420 nodes / 1,905,170 lanes)
|
| 20 |
+
|
| 21 |
+
| domain | n | router acc | class acc | end-to-end | deferred | ms/row |
|
| 22 |
+
|---|---:|---:|---:|---:|---:|---:|
|
| 23 |
+
| tickets_en | 1,800 | 0.831 | 0.904 | 0.761 | 0 | 7.65 |
|
| 24 |
+
| bank77 | 3,080 | 0.931 | 0.023 | 0.022 | 0 | 10.47 |
|
| 25 |
+
| sms | 838 | 0.233 | 0.752 | 0.222 | 2 | 6.42 |
|
| 26 |
+
| clinc | 4,500 | 0.334 | 0.309 | 0.123 | 0 | 11.02 |
|
| 27 |
+
| enron | 1,110 | 0.394 | 0.752 | 0.323 | 0 | 6.79 |
|
| 28 |
+
| emotion | 2,000 | 0.155 | 0.249 | 0.073 | 0 | 6.76 |
|
| 29 |
+
| hate | 1,500 | 0.381 | 0.653 | 0.277 | 0 | 6.52 |
|
| 30 |
+
| agnews | 2,000 | 0.320 | 0.604 | 0.206 | 0 | 7.02 |
|
| 31 |
+
| polarity | 2,000 | 0.339 | 0.571 | 0.189 | 0 | 6.52 |
|
| 32 |
+
| dbpedia | 2,000 | 0.403 | 0.475 | 0.204 | 0 | 7.55 |
|
| 33 |
+
| boolq | 1,500 | 0.097 | 0.531 | 0.059 | 0 | 6.18 |
|
| 34 |
+
|
| 35 |
+
Weighted over these 22,328 rows: router 0.432 · class 0.454 · e2e 0.196.
|
| 36 |
+
|
| 37 |
+
## Hidden results — multilingual substrates (post-isolation-fix)
|
| 38 |
+
|
| 39 |
+
| domain | substrate | n | router | class | e2e |
|
| 40 |
+
|---|---|---:|---:|---:|---:|
|
| 41 |
+
| tickets_bn | giant-bengali (579 nodes / 12,972 lanes) | 540 | 1.000 | 0.943 | 0.943 |
|
| 42 |
+
| tickets_hi | giant-devanagari (546 / 12,353) | 539 | 1.000 | 0.920 | 0.920 |
|
| 43 |
+
| tickets_ru | giant-cyrillic (680 / 14,915) | 539 | 1.000 | 0.959 | 0.959 |
|
| 44 |
+
|
| 45 |
+
Reference dedicated fabrics (v3.0, README): bn 0.969 / hi 0.965 / ru 0.970 —
|
| 46 |
+
the giant's per-script fabrics land within 1-4.5 points at a fraction of the
|
| 47 |
+
size, with the router trivially perfect inside a single-domain substrate.
|
| 48 |
+
|
| 49 |
+
## Handcrafted probes (41; 37 scored + 4 OOD)
|
| 50 |
+
|
| 51 |
+
Router 10/41 = 0.244 · class 11/37 = 0.297. OOD: the pure-gibberish probe
|
| 52 |
+
deferred (`zzqvv plork wumfus xanquu blorp`); the other three OOD probes
|
| 53 |
+
answered at confidence 0.000-0.031 (near-silence, honest). Full transcript
|
| 54 |
+
reproducible via `tools/giant_bench.py --probes`.
|
| 55 |
+
|
| 56 |
+
## Router-criteria wording sweep (cal only, never hidden)
|
| 57 |
+
|
| 58 |
+
| variant | router cal acc (n=3,250) |
|
| 59 |
+
|---|---:|
|
| 60 |
+
| short4 (trained wording) | **0.426** |
|
| 61 |
+
| mid8 specific | 0.164 |
|
| 62 |
+
| rich12 specific | 0.079 |
|
| 63 |
+
| long abstract | 0.208 |
|
| 64 |
+
|
| 65 |
+
Richer SPECIFIC wording makes the router worse — the direct-term harvest
|
| 66 |
+
mechanism of docs/PROBING.md: criteria words that occur in states harvest
|
| 67 |
+
energy regardless of router meaning, and more words = more cross-domain
|
| 68 |
+
harvest. Abstract register words recover part of the loss but do not beat
|
| 69 |
+
the short anchor-led probe. Winner (short4) matches what pass-1 trained.
|
| 70 |
+
|
| 71 |
+
## Probe-condition dependence (measured)
|
| 72 |
+
|
| 73 |
+
The router readout depends on what ELSE the decide call asks — every
|
| 74 |
+
question's criteria tokens inject into the same settled field:
|
| 75 |
+
|
| 76 |
+
| condition | router acc |
|
| 77 |
+
|---|---:|
|
| 78 |
+
| blind (router question alone), hidden n=23,528 | **0.400** |
|
| 79 |
+
| blind, cal n=1,500 | 0.399 |
|
| 80 |
+
| informed (router + the TRUE domain's class question — the hidden table above) | 0.432 weighted |
|
| 81 |
+
| router + ALL 15 class questions, cal | 0.399 |
|
| 82 |
+
|
| 83 |
+
Asking everything does NOT recover the informed condition: the other
|
| 84 |
+
domains' criteria dilute the anchoring (competitor dilution). Production
|
| 85 |
+
contract: a caller that only asks for routing gets the honest blind
|
| 86 |
+
estimate (0.400); the class numbers apply when the caller names the domain.
|
| 87 |
+
|
| 88 |
+
## Calibration (per-script, on cal only)
|
| 89 |
+
|
| 90 |
+
- giant-latin: choice temperature 0.1777; multiclass ECE 0.333 → 0.230
|
| 91 |
+
(choice), noul Platt (a=12.64, b=-1.00) ECE 0.511 → 0.095.
|
| 92 |
+
- giant-bengali / -devanagari / -cyrillic: fitted on their own cal splits.
|
| 93 |
+
|
| 94 |
+
## Honest reading
|
| 95 |
+
|
| 96 |
+
1. **Class channels work where per-anchor data is thick**: tickets_en 0.904,
|
| 97 |
+
sms 0.752, enron 0.752, hate 0.653, agnews 0.604, polarity 0.571 in a
|
| 98 |
+
single shared fabric alongside 15 other domains.
|
| 99 |
+
2. **The single 16-way router is the e2e bottleneck** (0.10-0.40 on the new
|
| 100 |
+
domains; wording sweep shows the limit is the mechanism, not the wording).
|
| 101 |
+
e2e = router x class; when the caller names the domain (API use), use the
|
| 102 |
+
class numbers. Blind routing alone measures 0.400 on hidden (see the
|
| 103 |
+
probe-condition section).
|
| 104 |
+
3. **bank77's 77-way decision collapses in the shared fabric** (0.023 class
|
| 105 |
+
vs 0.081 for the dedicated fabric): 77 anchors competing in a 43k-node
|
| 106 |
+
multi-domain fabric is a harder readout than the dedicated fabric —
|
| 107 |
+
hub crowding at scale, consistent with the v3.1.0 anatomy.
|
| 108 |
+
4. **boolq stays near majority** (0.531 vs ~0.62 True-majority): boolean
|
| 109 |
+
passage comprehension is beyond bag-of-words SI readout — measured limit,
|
| 110 |
+
not a bug.
|
| 111 |
+
5. **One interleaved pass, not three**: pass-1 lanes sit at their decay
|
| 112 |
+
equilibrium because every domain is re-touched throughout the round-robin
|
| 113 |
+
stream (the condition that made 3-epoch consolidation necessary —
|
| 114 |
+
sequential training with lane decay 0.995/lesson — does not arise here).
|
| 115 |
+
The chunked corpus (`data/giant/chunks/`) supports additional passes; the
|
| 116 |
+
v3.1.0 ladder measured epochs 2-3 adding +0.008-0.012 on bank77 — run
|
| 117 |
+
them if margins matter more than latency of training.
|
| 118 |
+
|
| 119 |
+
## Reproduce
|
| 120 |
+
|
| 121 |
+
```
|
| 122 |
+
make all # build engine
|
| 123 |
+
python3 tools/hf_fetch.py # download HF datasets (cached)
|
| 124 |
+
python3 tools/giant_prepare.py # build corpus + chunks + probes
|
| 125 |
+
for c in 0 1 ... 11: # one pass = 12 incremental learns
|
| 126 |
+
./build/syfox learn --examples data/giant/chunks/chunk_0$c.jsonl \
|
| 127 |
+
--model model-giant --lang auto --epochs 1
|
| 128 |
+
./build/syfox calibrate --model model-giant-latin \
|
| 129 |
+
--examples data/giant/cal_latin.jsonl --energy-norm # (+ 3 scripts)
|
| 130 |
+
python3 tools/giant_bench.py --model-slug giant-latin --domains ... --dump out.jsonl
|
| 131 |
+
python3 tools/giant_bench.py --model-slug giant-latin --probes
|
| 132 |
+
python3 tools/router_sweep.py --model-slug giant-latin
|
| 133 |
+
```
|
docs/PROBING.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Probing a SyFox model — methodology (v3.1)
|
| 2 |
+
|
| 3 |
+
Handcrafted probes are diagnostic instruments, not benchmarks. Used wrong,
|
| 4 |
+
they produce misleading conclusions in BOTH directions. This doc encodes what
|
| 5 |
+
the v3.1 probe experiments measured (real UCI SMS spam, one fabric, one hidden
|
| 6 |
+
set, three decide-side criteria wordings):
|
| 7 |
+
|
| 8 |
+
| decide-side criteria | hidden top-1 | mean margin (p1-p2) |
|
| 9 |
+
|---|---|---|
|
| 10 |
+
| matched (the schema the fabric was taught) | 0.160 | 0.444 |
|
| 11 |
+
| reworded (handcrafted, abstract) | **0.842** | 0.043 |
|
| 12 |
+
| empty (labels only) | 0.422 | 0.017 |
|
| 13 |
+
|
| 14 |
+
The SAME fabric, the SAME rows. The criteria text at decide is a first-class
|
| 15 |
+
input to the readout — it selects WHICH nodes the question probes, and
|
| 16 |
+
therefore which signal (or noise) the field returns.
|
| 17 |
+
|
| 18 |
+
## Rules for handcrafted probes
|
| 19 |
+
|
| 20 |
+
1. **Never conclude from margins under reworded criteria alone.** Reworded,
|
| 21 |
+
abstract criteria suppress direct-term harvest and often raise accuracy —
|
| 22 |
+
but they also shrink margins into the tie zone (0.01-0.05 with confidence
|
| 23 |
+
~0). A tie is a real answer: it means "the field cannot separate these
|
| 24 |
+
options through THIS probe wording".
|
| 25 |
+
|
| 26 |
+
2. **Use `--defer-margin P` when ties must not masquerade as decisions.**
|
| 27 |
+
The substrate always decides (physics untouched); the flag discloses
|
| 28 |
+
margin below P as `deferred: true, reason: "low_margin"` instead of a
|
| 29 |
+
confident-looking label on 50.9/49.1 splits. Same knob on the server:
|
| 30 |
+
`"options": {"defer_margin": 0.1}`.
|
| 31 |
+
|
| 32 |
+
3. **Sweep the criteria wording — one fabric, three conditions:**
|
| 33 |
+
matched / reworded / empty. Agreement between conditions is evidence about
|
| 34 |
+
the fabric; disagreement is evidence about the wording. A fabric that only
|
| 35 |
+
works under its training schema is overfit to its own question format.
|
| 36 |
+
|
| 37 |
+
4. **Match the training schema when reproducing benchmark numbers.** The
|
| 38 |
+
held-out numbers a model reports (e.g. SMS 0.937) were measured under the
|
| 39 |
+
schema the rows carry. Handcrafted probes with new wording measure a
|
| 40 |
+
different system — not the one the number describes.
|
| 41 |
+
|
| 42 |
+
5. **Handcrafted probes bound, never establish.** They can demonstrate a
|
| 43 |
+
failure (a false negative on an obvious scam) and motivate a held-out run;
|
| 44 |
+
they cannot estimate accuracy. Formal conclusions come from
|
| 45 |
+
`bench --eval <held-out>` on the real dataset.
|
| 46 |
+
|
| 47 |
+
## Why ties happen (mechanism, measured)
|
| 48 |
+
|
| 49 |
+
At learn time the substrate wires `state words -> label + training-criteria
|
| 50 |
+
words` (Hebbian). At decide time the probe is `label + criteria-as-given`,
|
| 51 |
+
read out of the settled state field as: direct energy at probe-token nodes +
|
| 52 |
+
a weighted-mean one-hop over their lanes. Two failure modes dominate:
|
| 53 |
+
|
| 54 |
+
- **Direct-term harvest**: probe words that appear in the state add energy
|
| 55 |
+
regardless of class meaning. Class-pure bigrams containing globally common
|
| 56 |
+
words ("cash abroad" -> "cash") let one option harvest from every state.
|
| 57 |
+
- **Anchor one-hop typicality**: the label token's lanes point at its class's
|
| 58 |
+
typical vocabulary. This is the true carrier — and it shows through best
|
| 59 |
+
when the probe criteria are abstract enough to avoid the harvest.
|
| 60 |
+
|
| 61 |
+
Opaque per-class anchors (`c00..c76`) + empty instructions at learn reduce
|
| 62 |
+
hub pollution; see the v3.1.0 banking77 ladder (0.029 -> 0.091 cal) for the
|
| 63 |
+
measured effect sizes.
|
| 64 |
+
|
| 65 |
+
## Reconciliation note for model-xl probes
|
| 66 |
+
|
| 67 |
+
The model-xl diagnostic (Bangla/English/SMS ties at ~0.50/0.50 with
|
| 68 |
+
`deferred: false`) is consistent with these mechanisms: the probes used new
|
| 69 |
+
criteria wording on a 14-domain fabric where every option's probe words carry
|
| 70 |
+
comparable mass. The fabric's own held-out numbers (SMS 0.937) were measured
|
| 71 |
+
under its trained schema. Next step on that side: re-run the probes with the
|
| 72 |
+
trained schema, sweep wording, and score the real held-out sets with
|
| 73 |
+
`--defer-margin` so ties are visible instead of silent.
|
| 74 |
+
|
| 75 |
+
## 6. Runtime flags in probes (v3.1.2)
|
| 76 |
+
|
| 77 |
+
`--energy-norm`, `--salience-gating`, and `--miller-window` are readout /
|
| 78 |
+
injection instruments, not reasoning upgrades. The model-xl zero-shot
|
| 79 |
+
reports (Snake A–E, Tic-Tac-Toe, file routing) and their repo-fabric
|
| 80 |
+
confirmation are archived with the code-level mechanism in
|
| 81 |
+
[ZEROSHOT.md](ZEROSHOT.md). Short version:
|
| 82 |
+
|
| 83 |
+
- `--energy-norm` changes the injection dose — a different settled field.
|
| 84 |
+
- `--salience-gating` / `--miller-window` change which nodes propagate
|
| 85 |
+
during settling — the settled energy is conserved (bit-identical across
|
| 86 |
+
source modes, measured on 2,638 real hidden rows), only the readout
|
| 87 |
+
changes. Winner flips at constant settled energy are expected behavior.
|
| 88 |
+
- Confidence under amplified configs is concentration, not correctness:
|
| 89 |
+
high-confidence-wrong rows went 0 → 15–86 per 1,800-row fabric under the
|
| 90 |
+
amplified configs while baseline confidence never crossed the bar.
|
| 91 |
+
|
| 92 |
+
Keep zero-shot probes and trained held-out numbers in separate buckets
|
| 93 |
+
(ZEROSHOT.md §Part 1/Part 2); never quote a flagged readout against a
|
| 94 |
+
default-config benchmark.
|
docs/ZEROSHOT.md
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Zero-shot probes vs trained benchmarks (v3.1.2)
|
| 2 |
+
|
| 3 |
+
SyFox is evaluated on two separate dimensions that must never be conflated:
|
| 4 |
+
|
| 5 |
+
| dimension | what it measures | instrument |
|
| 6 |
+
|---|---|---|
|
| 7 |
+
| learned-domain performance | trained/held-out accuracy, calibration, OOD deferral, contradiction handling, latency | `bench --split hidden`, real held-out rows, trained schema |
|
| 8 |
+
| zero-shot composition | whether the settled SI field can compose relations it was never taught (constraints, topology, semantic chains) | handcrafted probes on untrained tasks |
|
| 9 |
+
|
| 10 |
+
Part 1 archives the model-xl zero-shot experiments (user-run, no
|
| 11 |
+
task-specific training; diagnostic only). Part 2 gives the code-level
|
| 12 |
+
mechanism of the runtime flags and re-measures them on repo fabrics with
|
| 13 |
+
real held-out rows (`tools/flag_probe_experiment.py`). Part 3 states the
|
| 14 |
+
interpretation rules. See also `docs/PROBING.md` for the criteria-wording
|
| 15 |
+
methodology these probes follow.
|
| 16 |
+
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
## Part 1 — model-xl zero-shot experiments (user-run, archived)
|
| 20 |
+
|
| 21 |
+
**Provenance:** `model-xl/model-xl-latin`, 45,892 nodes / ~1.89676 M lanes,
|
| 22 |
+
SyFox 3.0.0 SI substrate. No Snake, Tic-Tac-Toe, or file-organization
|
| 23 |
+
training data was used in that fabric. All numbers below are the user's
|
| 24 |
+
runs, transcribed unmodified. Two run batches exist for a few scenarios and
|
| 25 |
+
disagree in exact confidence (same winner, same direction); both are kept
|
| 26 |
+
rather than smoothed.
|
| 27 |
+
|
| 28 |
+
### Snake — zero-shot decision test (8 scenarios)
|
| 29 |
+
|
| 30 |
+
| # | Scenario | Expected | Baseline | Conf | Energy-norm | Conf |
|
| 31 |
+
|---|---|---|---|---:|---|---:|
|
| 32 |
+
| 1 | Food ahead | Right | Right | 0.001 | Right | 0.924 |
|
| 33 |
+
| 2 | Wall ahead | Up/Down | Right | 0 | Right | 0.536 |
|
| 34 |
+
| 3 | Body blocks right | Up/Down/Left | Up | 0 | Up | 0.289 |
|
| 35 |
+
| 4 | Food behind while moving right | Up/Down | Right | 0.001 | Right | 0.952 |
|
| 36 |
+
| 5 | Food at wall; right is lethal | Up/Down | Right | 0.004 | Right | 0.499 |
|
| 37 |
+
| 6 | Long-term survival | Up | Up | 0.004 | Up | 0.556 |
|
| 38 |
+
| 7 | Only safe move | Down | Down | 0.005 | Down | 0.510 |
|
| 39 |
+
| 8 | Shortest safe route | Up | Right | 0.002 | Right | 0.525 |
|
| 40 |
+
|
| 41 |
+
Earlier run batch (same scenarios, independently run): food directly ahead
|
| 42 |
+
→ right 97.8%; body blocking right → up 56.3%; long-term survival → up
|
| 43 |
+
69.4%; only legal move → down 71.4%.
|
| 44 |
+
|
| 45 |
+
Observations (measured):
|
| 46 |
+
|
| 47 |
+
- Energy normalization dramatically increased separation of the EXISTING
|
| 48 |
+
attractors (conf 0.001 → 0.924 on #1) without guaranteeing correct
|
| 49 |
+
constraint reasoning: #2, #4, #5 kept selecting the unsafe direction,
|
| 50 |
+
now with high confidence.
|
| 51 |
+
- The two scenarios with the clearest trained-style signal (#1 food ahead,
|
| 52 |
+
#7 only safe move) were selected under both configurations.
|
| 53 |
+
- Baseline confidence ~0.001-0.005 is the near-uniform readout of a fabric
|
| 54 |
+
with no trained signal for the task — the honest-silence regime, not a
|
| 55 |
+
dead fabric.
|
| 56 |
+
|
| 57 |
+
### Snake — runtime flag experiment (forced safe move)
|
| 58 |
+
|
| 59 |
+
| Config | Flags | Selected | Confidence |
|
| 60 |
+
|---|---|---|---:|
|
| 61 |
+
| A | baseline | Down (correct) | 0.005 |
|
| 62 |
+
| B | `--energy-norm` | Down (correct) | 0.510 |
|
| 63 |
+
| C | `--energy-norm --salience-gating` | Up (illegal) | 0.515 |
|
| 64 |
+
| D | `--energy-norm --miller-window` | Left (illegal) | 0.805 |
|
| 65 |
+
| E | all three | Up (illegal) | 0.516 |
|
| 66 |
+
|
| 67 |
+
The energy-normalized variants (B–E) all reported the same settled energy
|
| 68 |
+
(83.928) while the selected answer changed. An earlier batch measured the
|
| 69 |
+
same qualitative outcome with different confidences (B 0.714, D 0.924).
|
| 70 |
+
This is the single most important observation in the report and it is
|
| 71 |
+
mechanism-explained in Part 2.
|
| 72 |
+
|
| 73 |
+
### Tic-Tac-Toe — zero-shot symbolic composition
|
| 74 |
+
|
| 75 |
+
The probe explicitly supplied the 3×3 topology, position numbering, the win
|
| 76 |
+
rule, and the full board (X: 1,2 · O: 4,5 · X to move; winning move = 3).
|
| 77 |
+
Result — baseline: selected 8, conf 0; `--energy-norm`: selected 8, conf
|
| 78 |
+
0.011, with the full distribution:
|
| 79 |
+
|
| 80 |
+
```
|
| 81 |
+
1=0.085 2=0.123 3=0.081 4=0.113 5=0.089
|
| 82 |
+
6=0.108 7=0.118 8=0.170 9=0.112
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
Position 3 (the actual winning move) received the LOWEST mass of all nine
|
| 86 |
+
options (0.081). The fabric did not compose `X + X + empty → winning move`
|
| 87 |
+
even with every fact supplied. This is a zero-shot symbolic-composition
|
| 88 |
+
failure, not evidence about a trained SyFox.
|
| 89 |
+
|
| 90 |
+
### File-organizer routing — zero-shot semantic mapping
|
| 91 |
+
|
| 92 |
+
Folders and meanings supplied; file `annual_report.pdf` explicitly
|
| 93 |
+
described as "an office report" and "not a newly downloaded uncategorized
|
| 94 |
+
file". Expected: Documents. Result with `--energy-norm`:
|
| 95 |
+
|
| 96 |
+
```
|
| 97 |
+
Documents=0.004 Pictures=0.016 Music=0.563 (selected)
|
| 98 |
+
Videos=0.084 Downloads=0.333 confidence 0.386
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
The intended chain `annual_report.pdf → office report → document →
|
| 102 |
+
Documents` did not form; the readout settled on Music, with Downloads
|
| 103 |
+
second (0.333) despite the explicit exclusion.
|
| 104 |
+
|
| 105 |
+
### What Part 1 establishes
|
| 106 |
+
|
| 107 |
+
- Energy normalization amplifies whatever ordering the field already has;
|
| 108 |
+
amplification is not reasoning.
|
| 109 |
+
- Multi-condition constraints (lethal wall, forbidden reversal, exclusions)
|
| 110 |
+
are not composed on unseen tasks.
|
| 111 |
+
- Confidence is signal concentration, not correctness: config D reached
|
| 112 |
+
0.805 (earlier batch 0.924) on an ILLEGAL move.
|
| 113 |
+
|
| 114 |
+
---
|
| 115 |
+
|
| 116 |
+
## Part 2 — what the runtime flags actually touch (code + measurement)
|
| 117 |
+
|
| 118 |
+
### Injection dose vs source selection
|
| 119 |
+
|
| 120 |
+
The three flags act at two different points:
|
| 121 |
+
|
| 122 |
+
- `--energy-norm` (M1) changes the decide-side injection dose
|
| 123 |
+
(`core/syfox.hpp`, `set_energy_norm`): every probe word injects more
|
| 124 |
+
energy, so the SETTLED FIELD ITSELF is different.
|
| 125 |
+
- `--salience-gating` and `--miller-window` change which nodes may
|
| 126 |
+
PROPAGATE energy during the settle passes (`core/si_substrate.hpp`,
|
| 127 |
+
`settle()`): "gated nodes keep their energy (readout-visible) but stay
|
| 128 |
+
silent as sources." The Miller cap is drawn from the decision's state
|
| 129 |
+
hash (`[source_cap-4, source_cap]`), so it is deterministic per state.
|
| 130 |
+
- Because a settle pass conserves energy up to uniform per-node decay
|
| 131 |
+
(propagation only redistributes energy between nodes), the total settled
|
| 132 |
+
energy is INVARIANT to source selection. Source modes change WHERE energy
|
| 133 |
+
sits, never HOW MUCH exists — and therefore change the readout, not the
|
| 134 |
+
field.
|
| 135 |
+
|
| 136 |
+
### Measured on repo fabrics (this release)
|
| 137 |
+
|
| 138 |
+
`tools/flag_probe_experiment.py`, real held-out rows, TRAINED schema,
|
| 139 |
+
five configs A–E as above. Deterministic: repeated runs reproduce every
|
| 140 |
+
number.
|
| 141 |
+
|
| 142 |
+
**model-tickets-big-latin** (1,800 hidden rows):
|
| 143 |
+
|
| 144 |
+
| config | top-1 | margin | conf | defer | hiConfWrong | flip vs A |
|
| 145 |
+
|---|---:|---:|---:|---:|---:|---:|
|
| 146 |
+
| A baseline | 0.971 | 0.0355 | 0.002 | 35 | 0 | – |
|
| 147 |
+
| B energy | 0.971 | 0.9430 | 0.923 | 0 | 21 | 0.1% |
|
| 148 |
+
| C energy+salience | 0.930 | 0.9567 | 0.944 | 0 | 86 | 6.1% |
|
| 149 |
+
| D energy+miller | 0.975 | 0.9556 | 0.940 | 0 | 20 | 1.5% |
|
| 150 |
+
| E all | 0.923 | 0.9493 | 0.937 | 0 | 83 | 6.9% |
|
| 151 |
+
|
| 152 |
+
**model-sms-natural** (838 hidden rows):
|
| 153 |
+
|
| 154 |
+
| config | top-1 | margin | conf | defer | hiConfWrong | flip vs A |
|
| 155 |
+
|---|---:|---:|---:|---:|---:|---:|
|
| 156 |
+
| A baseline | 0.170 | 0.0086 | 0.000 | 68 | 0 | – |
|
| 157 |
+
| B energy | 0.160 | 0.1668 | 0.060 | 2 | 0 | 0.1% |
|
| 158 |
+
| C energy+salience | 0.360 | 0.3819 | 0.234 | 2 | 19 | 22.6% |
|
| 159 |
+
| D energy+miller | 0.161 | 0.1688 | 0.063 | 2 | 0 | 3.0% |
|
| 160 |
+
| E all | 0.379 | 0.3941 | 0.253 | 2 | 15 | 23.9% |
|
| 161 |
+
|
| 162 |
+
**Settled-energy spread per row (same rows across configs):**
|
| 163 |
+
|
| 164 |
+
| comparison | tickets-big | sms-natural |
|
| 165 |
+
|---|---|---|
|
| 166 |
+
| A vs B (injection dose changes) | mean 7.324, max 20.185, 0% of rows within 0.001 | mean 7.865, max 47.273, 0% |
|
| 167 |
+
| B vs C/D/E (source modes vary, dose constant) | mean 0.0000, max 0.0010, **99.5% bit-identical** | mean 0.0000, max 0.0010, **99.8% bit-identical** |
|
| 168 |
+
|
| 169 |
+
Findings, all measured:
|
| 170 |
+
|
| 171 |
+
1. **The model-xl Snake observation reproduces exactly.** With the
|
| 172 |
+
injection dose held constant (B–E), settled energy is bit-identical
|
| 173 |
+
(spread ≤ 0.001 on 99.5–99.8% of rows; the exceptions are float
|
| 174 |
+
rounding) while the winner changes on 1.5–23.9% of rows. Source modes
|
| 175 |
+
are readout-side selectors over one unchanged field.
|
| 176 |
+
2. **Energy-norm on a trained schema is amplification, not
|
| 177 |
+
re-decision:** flipping 0.1% of winners at unchanged accuracy (0.971 →
|
| 178 |
+
0.971) while margins rise 26× (0.0355 → 0.9430) and confidence 0.002 →
|
| 179 |
+
0.923. It also lifts the 35 baseline deferrals to 0 — its documented M1
|
| 180 |
+
purpose. On zero-shot probes (near-uniform baseline) the same mechanism
|
| 181 |
+
CAN flip winners, because there the field has no stable ordering to
|
| 182 |
+
preserve.
|
| 183 |
+
3. **Salience gating re-reads the field and is fabric-dependent:**
|
| 184 |
+
−4.1 points on tickets-big (0.971 → 0.930) but +19 points on
|
| 185 |
+
sms-natural (0.160 → 0.360), where the full-source readout is dominated
|
| 186 |
+
by harvest noise (see PROBING.md) and salience-ranked sources suppress
|
| 187 |
+
it. Same field in both cases.
|
| 188 |
+
4. **High-confidence-wrong rows (conf ≥ 0.5 while wrong):** baseline 0 on
|
| 189 |
+
both fabrics (confidence 0.000-0.002 never crosses the bar) → 15–86
|
| 190 |
+
rows under amplified configs. Amplified confidence without accuracy
|
| 191 |
+
gain is exactly the D-config risk the model-xl report demonstrated with
|
| 192 |
+
0.805 on an illegal move.
|
| 193 |
+
5. **Benchmark numbers are measured under their documented config.** Flags
|
| 194 |
+
re-shape the readout; any flagged operating point is a different
|
| 195 |
+
measurement and must be re-benched before it is quoted.
|
| 196 |
+
|
| 197 |
+
---
|
| 198 |
+
|
| 199 |
+
## Part 3 — interpretation rules
|
| 200 |
+
|
| 201 |
+
1. **Confidence = concentration, never correctness.** Use
|
| 202 |
+
`decide --defer-margin P` (or server `options.defer_margin`) so
|
| 203 |
+
sub-threshold separations are disclosed as `deferred: true, reason:
|
| 204 |
+
low_margin` instead of looking like decisions.
|
| 205 |
+
2. **Flags are diagnostic instruments, not defaults.** They answer "what
|
| 206 |
+
does the field look like through a different readout" — they do not
|
| 207 |
+
improve the field. Default-config numbers remain the reference.
|
| 208 |
+
3. **Zero-shot probes bound, they never establish.** A probe can
|
| 209 |
+
demonstrate a failure (Snake #5, Tic-Tac-Toe position 3, file routing)
|
| 210 |
+
and motivate a held-out run; it cannot estimate accuracy. Training on a
|
| 211 |
+
task and re-probing is the only path to a number.
|
| 212 |
+
4. **Sweep the wording, not just the flags** — the matched/reworded/empty
|
| 213 |
+
sweep of PROBING.md applies to every zero-shot probe here; near-uniform
|
| 214 |
+
distributions are the probe-condition family, not a dead fabric.
|
| 215 |
+
|
| 216 |
+
## Data sources
|
| 217 |
+
|
| 218 |
+
- **banking77**: PolyAI task-specific dialogues (`data/bank77_*`; bulk
|
| 219 |
+
splits gitignored, regenerable via `tools/bank77_prepare.py`).
|
| 220 |
+
- **SMS**: UCI SMS Spam Collection (free-for-research corpus;
|
| 221 |
+
`data/sms_*.jsonl` committed so the v3.1.1 probe experiment and this
|
| 222 |
+
flag experiment reprodu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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SyFox — System One decision engine on an SI substrate core
|
| 2 |
+
CXX ?= g++
|
| 3 |
+
CXXFLAGS ?= -std=c++17 -O2 -Wall -Wextra -Wpedantic
|
| 4 |
+
BUILD := build
|
| 5 |
+
|
| 6 |
+
all: build/syfox build/syfox-test build/libsyfox_core.so
|
| 7 |
+
|
| 8 |
+
build:
|
| 9 |
+
mkdir -p build
|
| 10 |
+
|
| 11 |
+
CORE_HDRS := core/syfox.hpp core/si_substrate.hpp core/normalize.hpp core/ngram.hpp core/script.hpp core/derive.hpp core/bench.hpp core/gate.hpp core/recall.hpp core/json.hpp core/firewall.hpp
|
| 12 |
+
|
| 13 |
+
build/syfox: src/syfox_cli.cpp $(CORE_HDRS) | build
|
| 14 |
+
$(CXX) $(CXXFLAGS) -I. $< -o $@
|
| 15 |
+
|
| 16 |
+
build/syfox-test: src/syfox_test.cpp $(CORE_HDRS) | build
|
| 17 |
+
$(CXX) $(CXXFLAGS) -I. $< -o $@
|
| 18 |
+
|
| 19 |
+
# v3 Milestone 5: deterministic parallel-settle build (OpenMP, fixed
|
| 20 |
+
# reduction order). Bit-identical to the sequential build by construction and
|
| 21 |
+
# by test (syfox-test-omp proves it on the probe fabric).
|
| 22 |
+
build/syfox-omp: src/syfox_cli.cpp $(CORE_HDRS) | build
|
| 23 |
+
$(CXX) $(CXXFLAGS) -fopenmp -I. $< -o $@
|
| 24 |
+
|
| 25 |
+
build/syfox-test-omp: src/syfox_test.cpp $(CORE_HDRS) | build
|
| 26 |
+
$(CXX) $(CXXFLAGS) -fopenmp -I. $< -o $@
|
| 27 |
+
|
| 28 |
+
build/libsyfox_core.so: src/syfox_core.cpp $(CORE_HDRS) | build
|
| 29 |
+
$(CXX) $(CXXFLAGS) -fPIC -shared -I. $< -o $@
|
| 30 |
+
|
| 31 |
+
# ---------------------------------------------------------------------------
|
| 32 |
+
# v2.1 model build (P1 + P6 of the eval-methodology fix):
|
| 33 |
+
# * the fabric learns ONLY from data/*_train.jsonl — never from
|
| 34 |
+
# *_heldout.jsonl (P1), and (measured) never from the paraphrase
|
| 35 |
+
# augmentation by default: see P3 note below and README "augmentation
|
| 36 |
+
# dose-response"
|
| 37 |
+
# * temperature/Platt scalars are fitted on the HELD-OUT split (P6) — the
|
| 38 |
+
# fabric sees no heldout state; the fit sets 2-3 scalars and is monotone,
|
| 39 |
+
# so argmax decisions are unaffected
|
| 40 |
+
# * derivation is NOT run here: `make heldout-gate` runs it per model under
|
| 41 |
+
# the no-regression gate against the heldout rows (P5)
|
| 42 |
+
# Deterministic: every model is rebuilt from its seed data, not grown in place.
|
| 43 |
+
# ---------------------------------------------------------------------------
|
| 44 |
+
models: build/syfox
|
| 45 |
+
rm -rf model-tickets model-game model-guard
|
| 46 |
+
@# v2.2: taught WITH trigram lanes (fabric carries the sub-word bridges).
|
| 47 |
+
@# Decide-time default is word-level: `make bench-heldout` reproduces the
|
| 48 |
+
@# v2.1 numbers exactly; bridges activate via --ngrams on / --lang auto.
|
| 49 |
+
./build/syfox learn --ngrams on --model model-tickets --examples data/tickets_train.jsonl
|
| 50 |
+
./build/syfox learn --ngrams on --model model-game --examples data/game_train.jsonl
|
| 51 |
+
./build/syfox learn --ngrams on --model model-guard --examples data/guard_train.jsonl
|
| 52 |
+
@# P6: calibration fit on held-out rows (scalars only; argmax unaffected)
|
| 53 |
+
./build/syfox calibrate --ngrams on --model model-tickets --examples data/tickets_heldout.jsonl
|
| 54 |
+
./build/syfox calibrate --ngrams on --model model-game --examples data/game_heldout.jsonl
|
| 55 |
+
./build/syfox calibrate --ngrams on --model model-guard --examples data/guard_heldout.jsonl
|
| 56 |
+
|
| 57 |
+
# ---------------------------------------------------------------------------
|
| 58 |
+
# P3 reproduction: the same build WITH the paraphrase augmentation applied to
|
| 59 |
+
# training (train + *_paraphrased.jsonl, 5 variants per taught state). The
|
| 60 |
+
# heldout harness MEASURED this recipe regressing accuracy on every domain
|
| 61 |
+
# (tickets 1.000 -> 0.500, guard 0.750 -> 0.667, game 0.667 -> 0.667): the
|
| 62 |
+
# substrate damps re-exposed tokens by 1/sqrt(mass) and intern() counts
|
| 63 |
+
# occurrences linearly, so re-teaching near-duplicate lessons re-weights the
|
| 64 |
+
# field toward the training surface forms. Kept as a target so the A/B is
|
| 65 |
+
# reproducible; NOT the default build. Details: README "augmentation
|
| 66 |
+
# dose-response".
|
| 67 |
+
# ---------------------------------------------------------------------------
|
| 68 |
+
models-augmented: build/syfox
|
| 69 |
+
rm -rf model-tickets model-game model-guard
|
| 70 |
+
./build/syfox learn --model model-tickets --examples data/tickets_train.jsonl
|
| 71 |
+
./build/syfox learn --model model-tickets --examples data/tickets_paraphrased.jsonl
|
| 72 |
+
./build/syfox learn --model model-game --examples data/game_train.jsonl
|
| 73 |
+
./build/syfox learn --model model-game --examples data/game_paraphrased.jsonl
|
| 74 |
+
./build/syfox learn --model model-guard --examples data/guard_train.jsonl
|
| 75 |
+
./build/syfox learn --model model-guard --examples data/guard_paraphrased.jsonl
|
| 76 |
+
./build/syfox calibrate --model model-tickets --examples data/tickets_heldout.jsonl
|
| 77 |
+
./build/syfox calibrate --model model-game --examples data/game_heldout.jsonl
|
| 78 |
+
./build/syfox calibrate --model model-guard --examples data/guard_heldout.jsonl
|
| 79 |
+
|
| 80 |
+
# ---------------------------------------------------------------------------
|
| 81 |
+
# P5: transactional derivation, gated on the HELD-OUT rows. Pass => derived
|
| 82 |
+
# lanes committed (accuracy_before/after reported); revert => the fabric is
|
| 83 |
+
# restored bit-for-bit and the model ships un-derived with a logged reason.
|
| 84 |
+
# ---------------------------------------------------------------------------
|
| 85 |
+
# Order matters for honest measurement: `make heldout-gate` rebuilds fresh
|
| 86 |
+
# models and applies the gates; `bench-heldout` / `coverage` deliberately do
|
| 87 |
+
# NOT depend on `models` (a rebuild would wipe the committed derivation) —
|
| 88 |
+
# they measure the CURRENT on-disk model state.
|
| 89 |
+
heldout-gate: build/syfox models
|
| 90 |
+
./build/syfox derive --model model-tickets --gate data/tickets_heldout.jsonl --examples data/tickets_train.jsonl | tee build/gate-tickets.json
|
| 91 |
+
./build/syfox derive --model model-game --gate data/game_heldout.jsonl --examples data/game_train.jsonl | tee build/gate-game.json
|
| 92 |
+
./build/syfox derive --model model-guard --gate data/guard_heldout.jsonl --examples data/guard_train.jsonl | tee build/gate-guard.json
|
| 93 |
+
|
| 94 |
+
# ---------------------------------------------------------------------------
|
| 95 |
+
# v2.2 variant-augmented build ("vast data"): train lessons first, then the
|
| 96 |
+
# generated variant rows re-taught with --augment (mass-guarded: lanes
|
| 97 |
+
# strengthen, acoustic mass unchanged — the v2.1 re-deposition artifact is
|
| 98 |
+
# structurally impossible in this recipe). Eval data is untouched: calibrate
|
| 99 |
+
# still fits only on the held-out split, bench still scores it read-only.
|
| 100 |
+
# ---------------------------------------------------------------------------
|
| 101 |
+
models-vast: build/syfox
|
| 102 |
+
rm -rf model-tickets model-game model-guard
|
| 103 |
+
./build/syfox learn --model model-tickets --examples data/tickets_train.jsonl
|
| 104 |
+
./build/syfox learn --model model-tickets --examples data/tickets_expanded.jsonl --augment
|
| 105 |
+
./build/syfox learn --model model-game --examples data/game_train.jsonl
|
| 106 |
+
./build/syfox learn --model model-game --examples data/game_expanded.jsonl --augment
|
| 107 |
+
./build/syfox learn --model model-guard --examples data/guard_train.jsonl
|
| 108 |
+
./build/syfox learn --model model-guard --examples data/guard_expanded.jsonl --augment
|
| 109 |
+
./build/syfox calibrate --model model-tickets --examples data/tickets_heldout.jsonl
|
| 110 |
+
./build/syfox calibrate --model model-game --examples data/game_heldout.jsonl
|
| 111 |
+
./build/syfox calibrate --model model-guard --examples data/guard_heldout.jsonl
|
| 112 |
+
|
| 113 |
+
models-vast-full: build/syfox
|
| 114 |
+
rm -rf model-tickets model-game model-guard
|
| 115 |
+
./build/syfox learn --model model-tickets --examples data/tickets_train.jsonl
|
| 116 |
+
./build/syfox learn --model model-tickets --examples data/tickets_expanded_full.jsonl --augment
|
| 117 |
+
./build/syfox learn --model model-game --examples data/game_train.jsonl
|
| 118 |
+
./build/syfox learn --model model-game --examples data/game_expanded_full.jsonl --augment
|
| 119 |
+
./build/syfox learn --model model-guard --examples data/guard_train.jsonl
|
| 120 |
+
./build/syfox learn --model model-guard --examples data/guard_expanded_full.jsonl --augment
|
| 121 |
+
./build/syfox calibrate --model model-tickets --examples data/tickets_heldout.jsonl
|
| 122 |
+
./build/syfox calibrate --model model-game --examples data/game_heldout.jsonl
|
| 123 |
+
./build/syfox calibrate --model model-guard --examples data/guard_heldout.jsonl
|
| 124 |
+
|
| 125 |
+
# ---------------------------------------------------------------------------
|
| 126 |
+
# v2.2 multilingual: one SI substrate per script family, built by routing.
|
| 127 |
+
# Latin lessons route to model-tickets-latin, Bengali to -bengali, Hindi
|
| 128 |
+
# (Devanagari) to -devanagari, Russian (Cyrillic) to -cyrillic.
|
| 129 |
+
# ---------------------------------------------------------------------------
|
| 130 |
+
models-multilingual: build/syfox
|
| 131 |
+
rm -rf model-tickets-latin model-tickets-bengali model-tickets-devanagari model-tickets-cyrillic
|
| 132 |
+
./build/syfox learn --model model-tickets --lang auto --examples data/tickets_train.jsonl
|
| 133 |
+
./build/syfox learn --model model-tickets --lang auto --examples data/tickets_bn_train.jsonl
|
| 134 |
+
./build/syfox learn --model model-tickets --lang auto --examples data/tickets_hi_train.jsonl
|
| 135 |
+
./build/syfox learn --model model-tickets --lang auto --examples data/tickets_ru_train.jsonl
|
| 136 |
+
./build/syfox calibrate --model model-tickets-latin --examples data/tickets_train.jsonl
|
| 137 |
+
./build/syfox calibrate --model model-tickets-bengali --examples data/tickets_bn_train.jsonl
|
| 138 |
+
./build/syfox calibrate --model model-tickets-devanagari --examples data/tickets_hi_train.jsonl
|
| 139 |
+
./build/syfox calibrate --model model-tickets-cyrillic --examples data/tickets_ru_train.jsonl
|
| 140 |
+
|
| 141 |
+
# Held-out discipline for Bengali (train + heldout exist); hi/ru are demos.
|
| 142 |
+
bench-multilingual: build/syfox models-multilingual
|
| 143 |
+
./build/syfox bench --model model-tickets --lang auto --eval data/tickets_bn_heldout.jsonl | tee build/bench-bn-heldout.json
|
| 144 |
+
./build/syfox bench --model model-tickets --lang auto --eval data/tickets_bn_train.jsonl | tee build/bench-bn-train.json
|
| 145 |
+
|
| 146 |
+
# ---------------------------------------------------------------------------
|
| 147 |
+
# v2.2 typo-robustness sweep: deterministic corruption, grams ON vs OFF
|
| 148 |
+
# (the A/B that measures what the trigram lanes actually buy).
|
| 149 |
+
# ---------------------------------------------------------------------------
|
| 150 |
+
typos: build/syfox models
|
| 151 |
+
./build/syfox bench --ngrams on --model model-tickets --split heldout --typos 40 | tee build/typos-tickets-grams.json
|
| 152 |
+
./build/syfox bench --ngrams off --model model-tickets --split heldout --typos 40 | tee build/typos-tickets-nograms.json
|
| 153 |
+
./build/syfox bench --model model-tickets --lang auto --eval data/tickets_bn_heldout.jsonl --typos 40 | tee build/typos-bengali.json
|
| 154 |
+
|
| 155 |
+
# Disjoint-vocabulary generalization eval (unseen words, known intents).
|
| 156 |
+
bench-extra: build/syfox
|
| 157 |
+
./build/syfox bench --model model-tickets --eval data/tickets_eval_extra.jsonl | tee build/bench-extra-tickets.json
|
| 158 |
+
./build/syfox bench --model model-tickets --ngrams off --eval data/tickets_eval_extra.jsonl | tee build/bench-extra-tickets-nograms.json
|
| 159 |
+
|
| 160 |
+
test: build/syfox-test
|
| 161 |
+
./build/syfox-test
|
| 162 |
+
|
| 163 |
+
# Jev-parity eval suite on the three seed models.
|
| 164 |
+
# make bench -> train split (in-sample; labelled as such)
|
| 165 |
+
# make bench-heldout -> held-out split (the honest headline number)
|
| 166 |
+
# make coverage -> coverage-vs-accuracy curves on the held-out split
|
| 167 |
+
bench: build/syfox models
|
| 168 |
+
./build/syfox bench --model model-tickets --split train | tee build/bench-tickets.json
|
| 169 |
+
./build/syfox bench --model model-game --split train | tee build/bench-game.json
|
| 170 |
+
./build/syfox bench --model model-guard --split train | tee build/bench-guard.json
|
| 171 |
+
|
| 172 |
+
bench-heldout: build/syfox
|
| 173 |
+
./build/syfox bench --model model-tickets --split heldout | tee build/bench-heldout-tickets.json
|
| 174 |
+
./build/syfox bench --model model-game --split heldout | tee build/bench-heldout-game.json
|
| 175 |
+
./build/syfox bench --model model-guard --split heldout | tee build/bench-heldout-guard.json
|
| 176 |
+
|
| 177 |
+
coverage: build/syfox
|
| 178 |
+
./build/syfox bench --model model-tickets --split heldout --coverage-curve | tee build/coverage-tickets.txt
|
| 179 |
+
./build/syfox bench --model model-game --split heldout --coverage-curve | tee build/coverage-game.txt
|
| 180 |
+
./build/syfox bench --model model-guard --split heldout --coverage-curve | tee build/coverage-guard.txt
|
| 181 |
+
|
| 182 |
+
demo: models
|
| 183 |
+
@echo "=========== TICKETS ==========="
|
| 184 |
+
./build/syfox demo --domain tickets --model model-tickets
|
| 185 |
+
@echo "============ GAME ============="
|
| 186 |
+
./build/syfox demo --domain game --model model-game
|
| 187 |
+
@echo "=========== GUARD ============="
|
| 188 |
+
./build/syfox demo --domain guard --model model-guard
|
| 189 |
+
|
| 190 |
+
serve: build/syfox models
|
| 191 |
+
python3 server/app.py --model model-tickets --port 8010
|
| 192 |
+
|
| 193 |
+
clean:
|
| 194 |
+
rm -rf build
|
| 195 |
+
|
| 196 |
+
.PHONY: all models models-augmented models-vast models-vast-full models-multilingual bench-multilingual typos bench-extra heldout-gate test bench bench-heldout coverage demo serve omp adv-big throughput density clean
|
| 197 |
+
|
| 198 |
+
# ---------------------------------------------------------------------------
|
| 199 |
+
# v3 Milestone 1 — big-corpus models (data/big, 70/15/15 splits).
|
| 200 |
+
# learn reads ONLY *_train.jsonl (firewall refuses _cal/_hidden)
|
| 201 |
+
# calibrate fits on *_cal.jsonl (firewall refuses _hidden)
|
| 202 |
+
# hidden scored by bench-big only (never taught/calibrated/derived)
|
| 203 |
+
# Milestone-2 policy: --dedup skips exact duplicate lessons (auditable via
|
| 204 |
+
# dedup_skipped; 0 on the distinct corpus). --novelty measured slightly
|
| 205 |
+
# negative at floor 0.25 (-1.0pt), neutral at 0.90 — ships OFF; the A/B
|
| 206 |
+
# target below reproduces the measurement.
|
| 207 |
+
# ---------------------------------------------------------------------------
|
| 208 |
+
models-big: build/syfox
|
| 209 |
+
rm -rf model-tickets-big model-tickets-big-latin model-tickets-big-bengali \
|
| 210 |
+
model-tickets-big-devanagari model-tickets-big-cyrillic \
|
| 211 |
+
model-game-big model-game-big-latin model-guard-big model-guard-big-latin
|
| 212 |
+
./build/syfox learn --ngrams on --dedup --lang auto --model model-tickets-big --examples data/big/tickets_en_train.jsonl
|
| 213 |
+
./build/syfox learn --ngrams on --dedup --lang auto --model model-game-big --examples data/big/game_train.jsonl
|
| 214 |
+
./build/syfox learn --ngrams on --dedup --lang auto --model model-guard-big --examples data/big/guard_train.jsonl
|
| 215 |
+
./build/syfox calibrate --energy-norm --lang auto --model model-tickets-big --examples data/big/tickets_en_cal.jsonl
|
| 216 |
+
./build/syfox calibrate --energy-norm --lang auto --model model-game-big --examples data/big/game_cal.jsonl
|
| 217 |
+
./build/syfox calibrate --energy-norm --lang auto --model model-guard-big --examples data/big/guard_cal.jsonl
|
| 218 |
+
|
| 219 |
+
# Bengali / Hindi / Russian substrates (routed per script family); each
|
| 220 |
+
# hidden split carries 540 rows (>= the 500 the milestone requires).
|
| 221 |
+
models-big-ml: models-big
|
| 222 |
+
./build/syfox learn --lang auto --dedup --model model-tickets-big --examples data/big/tickets_bn_train.jsonl
|
| 223 |
+
./build/syfox learn --lang auto --dedup --model model-tickets-big --examples data/big/tickets_hi_train.jsonl
|
| 224 |
+
./build/syfox learn --lang auto --dedup --model model-tickets-big --examples data/big/tickets_ru_train.jsonl
|
| 225 |
+
./build/syfox calibrate --energy-norm --lang auto --model model-tickets-big --examples data/big/tickets_bn_cal.jsonl
|
| 226 |
+
./build/syfox calibrate --energy-norm --lang auto --model model-tickets-big --examples data/big/tickets_hi_cal.jsonl
|
| 227 |
+
./build/syfox calibrate --energy-norm --lang auto --model model-tickets-big --examples data/big/tickets_ru_cal.jsonl
|
| 228 |
+
|
| 229 |
+
# Milestone-1 headline: HIDDEN-TEST report, full timing/determinism settings.
|
| 230 |
+
bench-big: models-big
|
| 231 |
+
./build/syfox bench --energy-norm --lang auto --model model-tickets-big --eval data/big/tickets_en_hidden.jsonl | tee build/bench-hidden-tickets-en.json
|
| 232 |
+
./build/syfox bench --energy-norm --lang auto --model model-game-big --eval data/big/game_hidden.jsonl | tee build/bench-hidden-game.json
|
| 233 |
+
./build/syfox bench --energy-norm --lang auto --model model-guard-big --eval data/big/guard_hidden.jsonl | tee build/bench-hidden-guard.json
|
| 234 |
+
|
| 235 |
+
bench-big-ml: models-big-ml
|
| 236 |
+
./build/syfox bench --energy-norm --lang auto --model model-tickets-big --eval data/big/tickets_bn_hidden.jsonl | tee build/bench-hidden-tickets-bn.json
|
| 237 |
+
./build/syfox bench --energy-norm --lang auto --model model-tickets-big --eval data/big/tickets_hi_hidden.jsonl | tee build/bench-hidden-tickets-hi.json
|
| 238 |
+
./build/syfox bench --energy-norm --lang auto --model model-tickets-big --eval data/big/tickets_ru_hidden.jsonl | tee build/bench-hidden-tickets-ru.json
|
| 239 |
+
|
| 240 |
+
# Coverage-vs-accuracy on the hidden tests (the headline metric).
|
| 241 |
+
coverage-big: models-big
|
| 242 |
+
./build/syfox bench --energy-norm --lang auto --model model-tickets-big --eval data/big/tickets_en_hidden.jsonl --coverage-curve | tee build/coverage-hidden-tickets-en.txt
|
| 243 |
+
./build/syfox bench --energy-norm --lang auto --model model-game-big --eval data/big/game_hidden.jsonl --coverage-curve | tee build/coverage-hidden-game.txt
|
| 244 |
+
./build/syfox bench --energy-norm --lang auto --model model-guard-big --eval data/big/guard_hidden.jsonl --coverage-curve | tee build/coverage-hidden-guard.txt
|
| 245 |
+
|
| 246 |
+
# ---------------------------------------------------------------------------
|
| 247 |
+
# v3 Milestone 2 — the distinct-vs-repeated A/B (equal lesson counts).
|
| 248 |
+
# A: 8,400 distinct rows (25,200 lessons) -> hidden choice acc
|
| 249 |
+
# B: 1,050 rows re-taught 8x (25,200 lessons) -> hidden choice acc
|
| 250 |
+
# B-dedup: the same file with duplicate lessons skipped (dedup_skipped
|
| 251 |
+
# reports 7/8 of B's lessons as zero-information).
|
| 252 |
+
# ---------------------------------------------------------------------------
|
| 253 |
+
bank77: build/syfox
|
| 254 |
+
python3 tools/bank77_prepare.py --topk 20 --opaque-labels --no-instructions
|
| 255 |
+
./build/syfox learn --examples data/bank77_train.jsonl --model model-bank77-best --epochs 3
|
| 256 |
+
./build/syfox calibrate --model model-bank77-best --examples data/bank77_cal.jsonl
|
| 257 |
+
./build/syfox bench --model model-bank77-best --eval data/bank77_cal.jsonl --energy-norm
|
| 258 |
+
|
| 259 |
+
bank77-report: bank77
|
| 260 |
+
python3 tools/bank77_analysis.py --model model-bank77-best --eval data/bank77_hidden.jsonl --arbitrate --dump data/bank77_hidden_predictions.jsonl | tee data/bank77_report_hidden.txt
|
| 261 |
+
|
| 262 |
+
ab-distinct: build/syfox
|
| 263 |
+
@head -n 1050 data/big/tickets_en_train.jsonl > build/ab-repeat-src.jsonl
|
| 264 |
+
@for i in 1 2 3 4 5 6 7 8; do cat build/ab-repeat-src.jsonl; done > build/ab-repeat.jsonl
|
| 265 |
+
rm -rf model-ab
|
| 266 |
+
./build/syfox learn --ngrams on --dedup --model model-ab --examples data/big/tickets_en_train.jsonl | tee build/ab-A-learn.json
|
| 267 |
+
./build/syfox calibrate --model model-ab --examples data/big/tickets_en_cal.jsonl > /dev/null
|
| 268 |
+
./build/syfox bench --model model-ab --eval data/big/tickets_en_hidden.jsonl --latency-reps 1 --replays 0 | tee build/ab-A-distinct.json
|
| 269 |
+
rm -rf model-ab
|
| 270 |
+
./build/syfox learn --ngrams on --model model-ab --examples build/ab-repeat.jsonl | tee build/ab-B-learn.json
|
| 271 |
+
./build/syfox calibrate --model model-ab --examples data/big/tickets_en_cal.jsonl > /dev/null
|
| 272 |
+
./build/syfox bench --model model-ab --eval data/big/tickets_en_hidden.jsonl --latency-reps 1 --replays 0 | tee build/ab-B-repeated.json
|
| 273 |
+
rm -rf model-ab
|
| 274 |
+
./build/syfox learn --ngrams on --dedup --model model-ab --examples build/ab-repeat.jsonl | tee build/ab-Bd-learn.json
|
| 275 |
+
./build/syfox calibrate --model model-ab --examples data/big/tickets_en_cal.jsonl > /dev/null
|
| 276 |
+
./build/syfox bench --model model-ab --eval data/big/tickets_en_hidden.jsonl --latency-reps 1 --replays 0 | tee build/ab-B-dedup.json
|
| 277 |
+
rm -rf model-ab build/ab-repeat-src.jsonl
|
| 278 |
+
@echo "A/B complete: build/ab-A-distinct.json vs ab-B-repeated.json vs ab-B-dedup.json"
|
| 279 |
+
|
| 280 |
+
# Milestone-1b: the dose-response probe (does distinct experience scale?).
|
| 281 |
+
scale-probe: build/syfox
|
| 282 |
+
tools/scale_probe.sh
|
| 283 |
+
|
| 284 |
+
# Milestone-1: prove the firewall refuses hidden/calibration reads.
|
| 285 |
+
firewall-check: build/syfox
|
| 286 |
+
@! ./build/syfox learn --model model-x --examples data/big/tickets_en_hidden.jsonl 2>/dev/null
|
| 287 |
+
@echo "ok learn refuses _hidden"
|
| 288 |
+
@! ./build/syfox learn --model model-x --examples data/big/tickets_en_cal.jsonl 2>/dev/null
|
| 289 |
+
@echo "ok learn refuses _cal"
|
| 290 |
+
@! ./build/syfox calibrate --model model-x --examples data/big/tickets_en_hidden.jsonl 2>/dev/null
|
| 291 |
+
@echo "ok calibrate refuses _hidden"
|
| 292 |
+
@! ./build/syfox derive --model model-tickets --gate data/big/game_hidden.jsonl 2>/dev/null
|
| 293 |
+
@echo "ok derive --gate refuses _hidden"
|
| 294 |
+
|
| 295 |
+
# ---------------------------------------------------------------------------
|
| 296 |
+
# v3 Milestone 4 — the adversarial suite on the big hidden tests.
|
| 297 |
+
# Deterministic stress families + conflicting-lessons attack; honest
|
| 298 |
+
# per-family metrics (accuracy / defer / conf-when-wrong / false-conf).
|
| 299 |
+
# ---------------------------------------------------------------------------
|
| 300 |
+
adv-big: build/syfox
|
| 301 |
+
./build/syfox bench --energy-norm --lang auto --model model-tickets-big --eval data/big/tickets_en_hidden.jsonl --adversarial | tee build/adv-tickets.json
|
| 302 |
+
./build/syfox bench --energy-norm --lang auto --model model-game-big --eval data/big/game_hidden.jsonl --adversarial | tee build/adv-game.json
|
| 303 |
+
./build/syfox bench --energy-norm --lang auto --model model-guard-big --eval data/big/guard_hidden.jsonl --adversarial | tee build/adv-guard.json
|
| 304 |
+
|
| 305 |
+
# ---------------------------------------------------------------------------
|
| 306 |
+
# v3 Milestone 5 — multicore: deterministic OMP settle + batched throughput.
|
| 307 |
+
# omp builds the -fopenmp binaries (same sources, no code forks)
|
| 308 |
+
# omp-identity proves parallel settle == sequential settle BIT-IDENTICAL
|
| 309 |
+
# throughput batched decisions/sec, 1 worker vs N workers (private
|
| 310 |
+
# substrates per worker; performance axis, not accuracy)
|
| 311 |
+
# density the measured GPU gate (nodes / lanes / density / degree)
|
| 312 |
+
# ---------------------------------------------------------------------------
|
| 313 |
+
omp: build/syfox-omp build/syfox-test-omp
|
| 314 |
+
|
| 315 |
+
omp-identity: omp models-big
|
| 316 |
+
@./build/syfox bench --energy-norm --lang auto --model model-tickets-big --eval data/big/tickets_en_hidden.jsonl --latency-reps 1 --replays 0 | python3 -c "import json,sys; print(json.load(sys.stdin)['routing']['choice_accuracy'])" > build/omp-seq-acc.txt
|
| 317 |
+
@./build/syfox-omp bench --energy-norm --lang auto --model model-tickets-big --eval data/big/tickets_en_hidden.jsonl --latency-reps 1 --replays 0 --threads 2 | python3 -c "import json,sys; print(json.load(sys.stdin)['routing']['choice_accuracy'])" > build/omp-par-acc.txt
|
| 318 |
+
@./build/syfox-omp bench --energy-norm --lang auto --model model-tickets-big --eval data/big/tickets_en_hidden.jsonl --latency-reps 1 --replays 0 --threads 2 > build/omp-par-full.json
|
| 319 |
+
@./build/syfox bench --energy-norm --lang auto --model model-tickets-big --eval data/big/tickets_en_hidden.jsonl --latency-reps 1 --replays 0 > build/omp-seq-full.json
|
| 320 |
+
@python3 tools/check_omp_identity.py
|
| 321 |
+
|
| 322 |
+
throughput: build/syfox models-big
|
| 323 |
+
@# NOTE: the BASE model dir holds only routing state (--lang auto teaches
|
| 324 |
+
@# into <model>-<script> dirs), so throughput must load a real substrate:
|
| 325 |
+
@# model-tickets-big-latin. workers own private engine copies; the metric
|
| 326 |
+
@# is decisions/sec (checksum non-zero proves real decisions ran).
|
| 327 |
+
./build/syfox bench --energy-norm --model model-tickets-big-latin --eval data/big/tickets_en_hidden.jsonl --throughput 2 | tee build/throughput-tickets.json
|
| 328 |
+
|
| 329 |
+
density: build/syfox models-big
|
| 330 |
+
@echo "GPU gate (design only — no GPU in this sandbox):"
|
| 331 |
+
@echo "per-script substrate fabrics (--lang auto routes lessons into"
|
| 332 |
+
@echo "<model>-<script>; the base dir holds only routing state):"
|
| 333 |
+
@ls -d model-*-big-* 2>/dev/null | while read d; do \
|
| 334 |
+
./build/syfox stats --model "$$d" | python3 -c "import json,sys; d=json.load(sys.stdin); print('%6d nodes %7d lanes density=%.5f degree=%.2f %s' % (d.get('nodes',0), d.get('lanes',0), d.get('fabric_density',0), d.get('mean_out_degree',0), sys.argv[1]))" "$$d"; \
|
| 335 |
+
done
|
engine/core/bench.hpp
ADDED
|
@@ -0,0 +1,1245 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// SyFox — bench.hpp
|
| 3 |
+
// The Jev-parity evaluation harness: measures SyFox on the SAME axes the
|
| 4 |
+
// System One model class is judged on (researched Sept 2026):
|
| 5 |
+
//
|
| 6 |
+
// Jev published evidence | this suite measures
|
| 7 |
+
// --------------------------------------------+---------------------------
|
| 8 |
+
// 4-workflow decision accuracy 67.8% | routing accuracy
|
| 9 |
+
// (vs GPT-5.6 Terra 67.9% / Sol 74.1%) | (choice/score argmax)
|
| 10 |
+
// 70-500 ms one-pass latency, 193.6x faster | p50/p95 us per decision
|
| 11 |
+
// "calibrated Bayesian confidence" | ECE + conf/accuracy gap
|
| 12 |
+
// "never hallucinates" (schema-bound) | OOD defer rate
|
| 13 |
+
// | (honest silence)
|
| 14 |
+
// pi-warden guardrail 88% hold precision | noul hold precision,
|
| 15 |
+
// | recall, confusion
|
| 16 |
+
// non-autoregressive one-pass determinism | double-run bit identity
|
| 17 |
+
// (community: 3080-task classification bench) | close-call margin dist
|
| 18 |
+
//
|
| 19 |
+
// Honesty rules of the suite itself:
|
| 20 |
+
// * v2.1: --split heldout scores the held-out 30% (rows the fabric never
|
| 21 |
+
// learned from) — the headline number. The default train file is
|
| 22 |
+
// IN-SAMPLE and the eval_source label says so. Accuracy is never
|
| 23 |
+
// resubstitution unless the caller asks for the train split by name.
|
| 24 |
+
// * every figure here is reproducible from this binary on the same inputs;
|
| 25 |
+
// no number in the output exists without a runnable check behind it.
|
| 26 |
+
// * the jev_reference block carries PUBLISHED figures for side-by-side
|
| 27 |
+
// reading. They are not measured here and SyFox claims no parity with
|
| 28 |
+
// them beyond sharing the axes.
|
| 29 |
+
//
|
| 30 |
+
// Read-only: bench never mutates the model (decide() and the OOD probes
|
| 31 |
+
// cannot — inject() skips unknown tokens).
|
| 32 |
+
// ============================================================================
|
| 33 |
+
#pragma once
|
| 34 |
+
#include "syfox.hpp"
|
| 35 |
+
|
| 36 |
+
#include <algorithm>
|
| 37 |
+
#include <chrono>
|
| 38 |
+
#include <cmath>
|
| 39 |
+
#include <cstdlib>
|
| 40 |
+
#include <map>
|
| 41 |
+
#include <cstdio>
|
| 42 |
+
#include <set>
|
| 43 |
+
#include <sstream>
|
| 44 |
+
#include <string>
|
| 45 |
+
#include <vector>
|
| 46 |
+
|
| 47 |
+
namespace syfox {
|
| 48 |
+
namespace bench {
|
| 49 |
+
|
| 50 |
+
struct BenchConfig {
|
| 51 |
+
int ood_probes = 24; // untaught-vocabulary honesty probes
|
| 52 |
+
int closecall_probes = 48; // cross-domain mixed states
|
| 53 |
+
int determinism_runs = 2; // full eval replays, compared byte-wise
|
| 54 |
+
int latency_reps = 20; // timed repeats per eval row
|
| 55 |
+
float closecall_margin = 0.10f; // argmax margin below this = close call
|
| 56 |
+
};
|
| 57 |
+
|
| 58 |
+
// ---------------------------------------------------------------------------
|
| 59 |
+
// Deterministic typo corruption (v2.2) — the measured form of the
|
| 60 |
+
// typo-robustness claim. Real user input arrives misspelled; this mutates
|
| 61 |
+
// eval states the way keyboards do and the bench reports the accuracy drop.
|
| 62 |
+
//
|
| 63 |
+
// Determinism: corruption decisions come from FNV-1a of the WORD ITSELF,
|
| 64 |
+
// not of the row or position — the same word is corrupted identically
|
| 65 |
+
// everywhere (row-stable comparisons, replay-stable across runs).
|
| 66 |
+
// Works on codepoints (UTF-8), so Bengali/Hindi words corrupt correctly
|
| 67 |
+
// (matra drops, consonant swaps). Words < 4 codepoints are never touched
|
| 68 |
+
// (mirrors the n-gram lane minimum). Ops: deletion / adjacent swap /
|
| 69 |
+
// duplication, chosen by hash bits.
|
| 70 |
+
// ---------------------------------------------------------------------------
|
| 71 |
+
inline std::string corrupt_state(const std::string& state, float pct) {
|
| 72 |
+
if (pct <= 0.0f) return state;
|
| 73 |
+
auto fnv64 = [](const std::string& s) {
|
| 74 |
+
std::uint64_t h = 1469598103934665603ull;
|
| 75 |
+
for (unsigned char c : s) { h ^= c; h *= 1099511628211ull; }
|
| 76 |
+
return h;
|
| 77 |
+
};
|
| 78 |
+
// decode once: per-codepoint strings + letter flags
|
| 79 |
+
std::vector<std::string> cps;
|
| 80 |
+
std::vector<bool> letter;
|
| 81 |
+
for (std::size_t i = 0; i < state.size();) {
|
| 82 |
+
std::uint32_t cp = 0;
|
| 83 |
+
const std::size_t len = si::script::decode_utf8(state, i, cp);
|
| 84 |
+
cps.push_back(state.substr(i, len));
|
| 85 |
+
letter.push_back(cp != 0xFFFFFFFFu && si::script::is_letter_cp(cp));
|
| 86 |
+
i += len;
|
| 87 |
+
}
|
| 88 |
+
const unsigned want = static_cast<unsigned>(pct);
|
| 89 |
+
std::size_t i = 0;
|
| 90 |
+
while (i < cps.size()) {
|
| 91 |
+
if (!letter[i]) { ++i; continue; }
|
| 92 |
+
std::size_t j = i;
|
| 93 |
+
while (j < cps.size() && letter[j]) ++j; // letter run [i,j)
|
| 94 |
+
if (j - i >= 4) {
|
| 95 |
+
std::string w;
|
| 96 |
+
for (std::size_t k = i; k < j; ++k) w += cps[k];
|
| 97 |
+
const std::uint64_t h = fnv64(w);
|
| 98 |
+
if (static_cast<unsigned>(h % 100ull) < want) {
|
| 99 |
+
const std::size_t pos = static_cast<std::size_t>((h >> 7) % (j - i));
|
| 100 |
+
const std::size_t op = static_cast<std::size_t>((h >> 19) % 3ull);
|
| 101 |
+
if (op == 0) { // deletion
|
| 102 |
+
cps.erase(cps.begin() + static_cast<std::ptrdiff_t>(i + pos));
|
| 103 |
+
--j;
|
| 104 |
+
} else if (op == 1 && pos + 1 < j - i) { // adjacent swap
|
| 105 |
+
std::swap(cps[i + pos], cps[i + pos + 1]);
|
| 106 |
+
} else if (op == 1) { // swap impossible at edge
|
| 107 |
+
cps.erase(cps.begin() + static_cast<std::ptrdiff_t>(i + pos));
|
| 108 |
+
--j;
|
| 109 |
+
} else { // duplication
|
| 110 |
+
cps.insert(cps.begin() + static_cast<std::ptrdiff_t>(i + pos), cps[i + pos]);
|
| 111 |
+
++j;
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
}
|
| 115 |
+
i = j;
|
| 116 |
+
}
|
| 117 |
+
std::string out;
|
| 118 |
+
for (const auto& c : cps) out += c;
|
| 119 |
+
return out;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
// A replay unit: one state + the typed questions to ask about it + the
|
| 123 |
+
// expected labels (qid -> label). Generated probes carry no labels and are
|
| 124 |
+
// scored only for margins/deferral, never for accuracy.
|
| 125 |
+
struct Probe {
|
| 126 |
+
std::string state;
|
| 127 |
+
sfx::JV questions;
|
| 128 |
+
std::map<std::string, std::string> labels;
|
| 129 |
+
bool taught = true;
|
| 130 |
+
};
|
| 131 |
+
|
| 132 |
+
// Deterministic nonsense vocabulary for the honesty probes. Every token is
|
| 133 |
+
// checked against the model's vocabulary before use; a token the model
|
| 134 |
+
// happens to know is skipped (no fake OOD). v2.2: the check extends to
|
| 135 |
+
// SUB-WORD material — a word whose trigrams overlap taught g3:* lanes
|
| 136 |
+
// ("teapot" vs taught "team": g3:tea) carries partial evidence under the
|
| 137 |
+
// trigram encoding and is NOT out-of-distribution anymore; probing with it
|
| 138 |
+
// would fake a silence violation. Truly unentangled vocabulary must still
|
| 139 |
+
// defer at 100% — that is the contract this probe guards.
|
| 140 |
+
inline std::vector<std::string> ood_states(const si::Substrate& s, int n) {
|
| 141 |
+
static const char* kNonsense[] = {
|
| 142 |
+
"zorblatz", "quibblemock", "framistan", "velocirapture", "glorgnax",
|
| 143 |
+
"wubblefuzz", "krakenshadow", "mimsy", "borogove", "slartibartfast",
|
| 144 |
+
"flimflam", "xylophone", "recluse", "brambleditch", "thundercouch",
|
| 145 |
+
"pickleweasel", "gravyboat", "odyssey", "flapdoodle", "snickersnee",
|
| 146 |
+
"hornswoggle", "muffin", "teapot", "gubbins", "collywobbles",
|
| 147 |
+
"discombobulate", "kerfuffle", "wabbit", "skua", "fondue"
|
| 148 |
+
};
|
| 149 |
+
const int K = static_cast<int>(sizeof(kNonsense) / sizeof(kNonsense[0]));
|
| 150 |
+
auto subword_entangled = [&s](const std::string& w) {
|
| 151 |
+
for (const auto& g : si::norm::expand_ngrams({w}))
|
| 152 |
+
if (s.has(g)) return true;
|
| 153 |
+
return false;
|
| 154 |
+
};
|
| 155 |
+
std::vector<std::string> out;
|
| 156 |
+
for (int i = 0; i < n && i < K; ++i) {
|
| 157 |
+
std::vector<std::string> toks;
|
| 158 |
+
for (int k = 0; k < 3; ++k) {
|
| 159 |
+
const std::string w = kNonsense[(i * 3 + k) % K];
|
| 160 |
+
if (!s.has(w) && !subword_entangled(w)) toks.push_back(w); // unknown at word AND sub-word level
|
| 161 |
+
}
|
| 162 |
+
if (toks.empty()) continue; // all three known: skip
|
| 163 |
+
std::string st;
|
| 164 |
+
for (std::size_t k = 0; k < toks.size(); ++k) { if (k) st += " "; st += toks[k]; }
|
| 165 |
+
out.push_back(st);
|
| 166 |
+
}
|
| 167 |
+
return out;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
// The first label of a row in sorted-key order (JVObj is a std::map, so this
|
| 171 |
+
// is deterministic). Used for close-call pairing.
|
| 172 |
+
inline std::string first_label(const sfx::JV& row) {
|
| 173 |
+
if (!row.has("labels") || !row.at("labels").is_obj() || row.at("labels").obj.empty())
|
| 174 |
+
return "";
|
| 175 |
+
return row.at("labels").obj.begin()->second.as_str();
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
// Mixed close-call probes: pair eval rows whose first labels differ and
|
| 179 |
+
// concatenate their states (A's questions + labels ride along). These are
|
| 180 |
+
// the states a routing fabric is most likely to flip. The derivation gate
|
| 181 |
+
// replays the SAME generator, so bench and gate numbers stay comparable.
|
| 182 |
+
inline std::vector<Probe> closecall_probes(const std::vector<sfx::JV>& rows, int cap) {
|
| 183 |
+
std::vector<Probe> out;
|
| 184 |
+
if (rows.size() < 2) return out;
|
| 185 |
+
for (std::size_t i = 0; i < rows.size() && static_cast<int>(out.size()) < cap; ++i) {
|
| 186 |
+
for (std::size_t j = i + 1; j < rows.size() && static_cast<int>(out.size()) < cap; ++j) {
|
| 187 |
+
const std::string la = first_label(rows[i]), lb = first_label(rows[j]);
|
| 188 |
+
if (la.empty() || lb.empty() || la == lb) continue;
|
| 189 |
+
if (!rows[i].has("questions") || !rows[i].at("questions").is_obj()) continue;
|
| 190 |
+
if (!rows[i].has("labels") || !rows[i].at("labels").is_obj()) continue;
|
| 191 |
+
Probe p;
|
| 192 |
+
p.state = rows[i].at("state").as_str() + " " + rows[j].at("state").as_str();
|
| 193 |
+
p.questions = rows[i].at("questions");
|
| 194 |
+
for (const auto& kv : rows[i].at("labels").obj)
|
| 195 |
+
p.labels[kv.first] = kv.second.as_str();
|
| 196 |
+
p.taught = false;
|
| 197 |
+
out.push_back(p);
|
| 198 |
+
}
|
| 199 |
+
}
|
| 200 |
+
return out;
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
// Eval probes from labelled rows: the row's own state, questions and labels.
|
| 204 |
+
inline std::vector<Probe> eval_probes(const std::vector<sfx::JV>& rows) {
|
| 205 |
+
std::vector<Probe> out;
|
| 206 |
+
for (const auto& r : rows) {
|
| 207 |
+
if (!r.has("state") || !r.has("questions") || !r.has("labels")) continue;
|
| 208 |
+
if (!r.at("questions").is_obj() || !r.at("labels").is_obj()) continue;
|
| 209 |
+
Probe p;
|
| 210 |
+
p.state = r.at("state").as_str();
|
| 211 |
+
p.questions = r.at("questions");
|
| 212 |
+
for (const auto& kv : r.at("labels").obj)
|
| 213 |
+
p.labels[kv.first] = kv.second.as_str();
|
| 214 |
+
p.taught = true;
|
| 215 |
+
out.push_back(p);
|
| 216 |
+
}
|
| 217 |
+
return out;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
// Does a stored label (level text, or level INDEX for array criteria) match
|
| 221 |
+
// the argmax label the answer produced?
|
| 222 |
+
inline bool label_matches(const sfx::JV& q, const std::string& stored, const std::string& argmax) {
|
| 223 |
+
if (stored == argmax) return true;
|
| 224 |
+
const sfx::JV& crit = q.has("criteria") ? q.at("criteria") : sfx::JV(sfx::JVObj{});
|
| 225 |
+
if (crit.is_arr()) {
|
| 226 |
+
long idx = std::strtol(stored.c_str(), nullptr, 10);
|
| 227 |
+
if (idx >= 0 && static_cast<std::size_t>(idx) < crit.arr.size())
|
| 228 |
+
return crit.arr[static_cast<std::size_t>(idx)].as_str() == argmax;
|
| 229 |
+
}
|
| 230 |
+
return false;
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
struct Bin { long n = 0; long correct = 0; double conf_sum = 0.0; double ece_conf_sum = 0.0; };
|
| 234 |
+
|
| 235 |
+
// One full pass of decisions over a probe set, accumulating the Jev axes.
|
| 236 |
+
struct PassResult {
|
| 237 |
+
struct QType {
|
| 238 |
+
long n = 0, correct = 0, close_calls = 0;
|
| 239 |
+
double conf_sum = 0.0, margin_sum = 0.0;
|
| 240 |
+
std::map<int, Bin> ece_bins;
|
| 241 |
+
};
|
| 242 |
+
QType choice, score;
|
| 243 |
+
long noul_tp = 0, noul_fp = 0, noul_tn = 0, noul_fn = 0; // pred true = HOLD
|
| 244 |
+
long deferred = 0, noul_n = 0;
|
| 245 |
+
std::vector<double> latency_us;
|
| 246 |
+
|
| 247 |
+
static int ece_bin(float conf) {
|
| 248 |
+
int b = static_cast<int>(conf * 10.0f);
|
| 249 |
+
return b < 0 ? 0 : (b > 9 ? 9 : b);
|
| 250 |
+
}
|
| 251 |
+
static double ece(const std::map<int, Bin>& bins) {
|
| 252 |
+
long total = 0; double e = 0.0;
|
| 253 |
+
for (const auto& kv : bins) total += kv.second.n;
|
| 254 |
+
if (total == 0) return 0.0;
|
| 255 |
+
for (const auto& kv : bins) {
|
| 256 |
+
const Bin& b = kv.second;
|
| 257 |
+
if (b.n == 0) continue;
|
| 258 |
+
const double acc = static_cast<double>(b.correct) / static_cast<double>(b.n);
|
| 259 |
+
// v2.1: ECE uses the MAX-PROBABILITY confidence (the signal
|
| 260 |
+
// temperature scaling acts on), not the entropy confidence. The
|
| 261 |
+
// entropy confidence stays in conf_sum for the conf-gap fields.
|
| 262 |
+
const double cf = b.ece_conf_sum / static_cast<double>(b.n);
|
| 263 |
+
e += (static_cast<double>(b.n) / static_cast<double>(total)) * std::fabs(acc - cf);
|
| 264 |
+
}
|
| 265 |
+
return e;
|
| 266 |
+
}
|
| 267 |
+
};
|
| 268 |
+
|
| 269 |
+
// The decision signature of one probe: qid -> (argmax, confidence), used by
|
| 270 |
+
// the determinism check and (in gate.hpp) by the no-regression replay.
|
| 271 |
+
inline std::map<std::string, std::pair<std::string, float>>
|
| 272 |
+
decision_signature(Engine& eng, const Probe& p) {
|
| 273 |
+
std::map<std::string, std::pair<std::string, float>> sig;
|
| 274 |
+
syfox::Usage u;
|
| 275 |
+
auto answers = eng.decide(p.state, p.questions, u);
|
| 276 |
+
std::size_t ai = 0;
|
| 277 |
+
for (const auto& qkv : p.questions.obj) {
|
| 278 |
+
if (ai >= answers.size()) break;
|
| 279 |
+
const syfox::Answer& a = answers[ai++];
|
| 280 |
+
if (a.deferred) { sig[qkv.first] = {"", -1.0f}; continue; }
|
| 281 |
+
std::string amax;
|
| 282 |
+
float top = -1.0f;
|
| 283 |
+
for (const auto& kv : a.probabilities)
|
| 284 |
+
if (kv.second > top) { top = kv.second; amax = kv.first; }
|
| 285 |
+
if (a.type == "noul") amax = a.probability >= 0.5f ? "true" : "false";
|
| 286 |
+
sig[qkv.first] = {amax, a.confidence};
|
| 287 |
+
}
|
| 288 |
+
return sig;
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
inline PassResult run_pass(Engine& eng, const std::vector<Probe>& probes, int latency_reps) {
|
| 292 |
+
PassResult pr;
|
| 293 |
+
for (const auto& p : probes) {
|
| 294 |
+
// latency: time decide() calls for a stable p50/p95
|
| 295 |
+
for (int r = 0; r < latency_reps; ++r) {
|
| 296 |
+
syfox::Usage u;
|
| 297 |
+
const auto t0 = std::chrono::steady_clock::now();
|
| 298 |
+
auto answers = eng.decide(p.state, p.questions, u);
|
| 299 |
+
const auto t1 = std::chrono::steady_clock::now();
|
| 300 |
+
pr.latency_us.push_back(
|
| 301 |
+
std::chrono::duration<double, std::micro>(t1 - t0).count());
|
| 302 |
+
if (r == 0)
|
| 303 |
+
for (const auto& a : answers) if (a.deferred) ++pr.deferred;
|
| 304 |
+
}
|
| 305 |
+
// correctness pass (untimed, separate — keeps the semantics clean)
|
| 306 |
+
syfox::Usage u;
|
| 307 |
+
auto answers = eng.decide(p.state, p.questions, u);
|
| 308 |
+
std::size_t ai = 0;
|
| 309 |
+
for (const auto& qkv : p.questions.obj) {
|
| 310 |
+
const sfx::JV& q = qkv.second;
|
| 311 |
+
if (ai >= answers.size()) break;
|
| 312 |
+
const syfox::Answer& a = answers[ai++];
|
| 313 |
+
const std::string type = q.at("type").as_str();
|
| 314 |
+
const std::string stored =
|
| 315 |
+
p.labels.count(qkv.first) ? p.labels.at(qkv.first) : "";
|
| 316 |
+
if (a.deferred) continue;
|
| 317 |
+
if (type == "choice" || type == "score") {
|
| 318 |
+
PassResult::QType& agg = (type == "choice") ? pr.choice : pr.score;
|
| 319 |
+
if (a.probabilities.empty()) continue;
|
| 320 |
+
std::string amax; float top = -1.0f, second = -1.0f;
|
| 321 |
+
for (const auto& kv : a.probabilities) {
|
| 322 |
+
if (kv.second > top) { second = top; top = kv.second; amax = kv.first; }
|
| 323 |
+
else if (kv.second > second) second = kv.second;
|
| 324 |
+
}
|
| 325 |
+
const bool correct = p.taught && label_matches(q, stored, amax);
|
| 326 |
+
++agg.n;
|
| 327 |
+
agg.correct += correct ? 1 : 0;
|
| 328 |
+
agg.conf_sum += a.confidence;
|
| 329 |
+
const float margin = std::max(0.0f, top - std::max(second, 0.0f));
|
| 330 |
+
agg.margin_sum += margin;
|
| 331 |
+
agg.close_calls += (margin < 0.10f) ? 1 : 0;
|
| 332 |
+
Bin& b = agg.ece_bins[PassResult::ece_bin(top)];
|
| 333 |
+
b.n += 1; b.correct += correct ? 1 : 0;
|
| 334 |
+
b.conf_sum += a.confidence; b.ece_conf_sum += top;
|
| 335 |
+
} else if (type == "noul") {
|
| 336 |
+
++pr.noul_n;
|
| 337 |
+
const bool pred_true = a.probability >= 0.5f;
|
| 338 |
+
const bool true_label = p.taught && stored == "true";
|
| 339 |
+
if (pred_true && true_label) ++pr.noul_tp;
|
| 340 |
+
else if (pred_true && !true_label) ++pr.noul_fp;
|
| 341 |
+
else if (!pred_true && !true_label) ++pr.noul_tn;
|
| 342 |
+
else ++pr.noul_fn;
|
| 343 |
+
}
|
| 344 |
+
}
|
| 345 |
+
}
|
| 346 |
+
return pr;
|
| 347 |
+
}
|
| 348 |
+
|
| 349 |
+
struct BenchReport {
|
| 350 |
+
std::string model;
|
| 351 |
+
std::string eval_source; // labelled with the split it came from
|
| 352 |
+
long rows = 0, probes = 0, mixed_probes = 0, ood_probes = 0;
|
| 353 |
+
|
| 354 |
+
// routing (Jev: 4-workflow accuracy 67.8%)
|
| 355 |
+
double choice_accuracy = 0, score_accuracy = 0;
|
| 356 |
+
long choice_n = 0, score_n = 0;
|
| 357 |
+
double choice_ece = 0, score_ece = 0;
|
| 358 |
+
double conf_correct = 0, conf_wrong = 0; // choice+score, confidence gap
|
| 359 |
+
double mean_margin = 0; long close_calls = 0, margin_n = 0;
|
| 360 |
+
|
| 361 |
+
// honesty (Jev: "never hallucinates", schema-bound)
|
| 362 |
+
double ood_defer_rate = 0; long ood_n = 0;
|
| 363 |
+
|
| 364 |
+
// guardrail (Jev: pi-warden 88% hold precision)
|
| 365 |
+
long g_tp = 0, g_fp = 0, g_tn = 0, g_fn = 0;
|
| 366 |
+
double hold_precision = -1.0, hold_recall = -1.0; // -1 = undefined
|
| 367 |
+
|
| 368 |
+
// latency (Jev: 70-500 ms)
|
| 369 |
+
double lat_p50_us = 0, lat_p95_us = 0, lat_mean_us = 0;
|
| 370 |
+
|
| 371 |
+
// determinism (Jev: non-autoregressive one-pass)
|
| 372 |
+
bool deterministic = true;
|
| 373 |
+
|
| 374 |
+
sfx::JV to_json() const {
|
| 375 |
+
const auto r2 = [](double v) { return std::round(v * 1000.0) / 1000.0; };
|
| 376 |
+
sfx::JVObj routing;
|
| 377 |
+
routing["choice_accuracy"] = r2(choice_accuracy);
|
| 378 |
+
routing["choice_n"] = static_cast<double>(choice_n);
|
| 379 |
+
routing["score_accuracy"] = r2(score_accuracy);
|
| 380 |
+
routing["score_n"] = static_cast<double>(score_n);
|
| 381 |
+
routing["mean_margin"] = r2(mean_margin);
|
| 382 |
+
routing["close_calls"] = static_cast<double>(close_calls);
|
| 383 |
+
routing["margin_n"] = static_cast<double>(margin_n);
|
| 384 |
+
|
| 385 |
+
sfx::JVObj calib;
|
| 386 |
+
calib["choice_ece"] = r2(choice_ece);
|
| 387 |
+
calib["score_ece"] = r2(score_ece);
|
| 388 |
+
calib["mean_conf_when_correct"] = r2(conf_correct);
|
| 389 |
+
calib["mean_conf_when_wrong"] = r2(conf_wrong);
|
| 390 |
+
|
| 391 |
+
sfx::JVObj honesty;
|
| 392 |
+
honesty["ood_defer_rate"] = r2(ood_defer_rate);
|
| 393 |
+
honesty["ood_probes"] = static_cast<double>(ood_n);
|
| 394 |
+
|
| 395 |
+
sfx::JVObj guard;
|
| 396 |
+
guard["tp"] = static_cast<double>(g_tp);
|
| 397 |
+
guard["fp"] = static_cast<double>(g_fp);
|
| 398 |
+
guard["tn"] = static_cast<double>(g_tn);
|
| 399 |
+
guard["fn"] = static_cast<double>(g_fn);
|
| 400 |
+
if (hold_precision >= 0) guard["hold_precision"] = r2(hold_precision);
|
| 401 |
+
if (hold_recall >= 0) guard["hold_recall"] = r2(hold_recall);
|
| 402 |
+
|
| 403 |
+
sfx::JVObj lat;
|
| 404 |
+
lat["p50"] = r2(lat_p50_us);
|
| 405 |
+
lat["p95"] = r2(lat_p95_us);
|
| 406 |
+
lat["mean"] = r2(lat_mean_us);
|
| 407 |
+
|
| 408 |
+
sfx::JVObj jev;
|
| 409 |
+
jev["published"] = sfx::JV(true);
|
| 410 |
+
jev["workflow_accuracy"] = 0.678;
|
| 411 |
+
jev["latency_ms"] = sfx::JV("[70, 500]");
|
| 412 |
+
jev["guardrail_hold_precision"] = 0.88;
|
| 413 |
+
jev["source"] = sfx::JV("typesafe.ai launch + press coverage, Sept 2026; axes shared, not numbers");
|
| 414 |
+
|
| 415 |
+
sfx::JVObj o;
|
| 416 |
+
o["suite"] = sfx::JV("syfox-jev-parity-v0");
|
| 417 |
+
o["model"] = sfx::JV(model);
|
| 418 |
+
o["eval_source"] = sfx::JV(eval_source);
|
| 419 |
+
o["rows"] = static_cast<double>(rows);
|
| 420 |
+
o["probes"] = static_cast<double>(probes);
|
| 421 |
+
o["mixed_probes"] = static_cast<double>(mixed_probes);
|
| 422 |
+
o["ood_probes"] = static_cast<double>(ood_probes);
|
| 423 |
+
o["routing"] = sfx::JV(routing);
|
| 424 |
+
o["calibration"] = sfx::JV(calib);
|
| 425 |
+
o["honesty"] = sfx::JV(honesty);
|
| 426 |
+
o["guardrail"] = sfx::JV(guard);
|
| 427 |
+
o["latency_us"] = sfx::JV(lat);
|
| 428 |
+
o["deterministic"] = sfx::JV(deterministic);
|
| 429 |
+
o["jev_reference"] = sfx::JV(jev);
|
| 430 |
+
return sfx::JV(o);
|
| 431 |
+
}
|
| 432 |
+
};
|
| 433 |
+
|
| 434 |
+
inline BenchReport run(Engine& eng, const std::vector<sfx::JV>& eval_rows,
|
| 435 |
+
const std::string& eval_source, const BenchConfig& bc,
|
| 436 |
+
const std::string& model_name) {
|
| 437 |
+
BenchReport rep;
|
| 438 |
+
rep.model = model_name;
|
| 439 |
+
rep.eval_source = eval_source;
|
| 440 |
+
rep.rows = static_cast<long>(eval_rows.size());
|
| 441 |
+
|
| 442 |
+
std::vector<Probe> probes = eval_probes(eval_rows);
|
| 443 |
+
const std::vector<Probe> mixed = closecall_probes(eval_rows, bc.closecall_probes);
|
| 444 |
+
rep.mixed_probes = static_cast<long>(mixed.size());
|
| 445 |
+
probes.insert(probes.end(), mixed.begin(), mixed.end());
|
| 446 |
+
rep.probes = static_cast<long>(probes.size());
|
| 447 |
+
|
| 448 |
+
// ---- accuracy / calibration / guardrail: LABELLED rows only -------------
|
| 449 |
+
// Close-call probes carry no trustworthy labels (taught=false) — counting
|
| 450 |
+
// them in the accuracy/ECE denominators would report fake errors. They
|
| 451 |
+
// get their own pass for the margin distribution, which is the quantity
|
| 452 |
+
// they exist for.
|
| 453 |
+
const std::vector<Probe> taught_probes = eval_probes(eval_rows);
|
| 454 |
+
const PassResult pr = run_pass(eng, taught_probes, bc.latency_reps);
|
| 455 |
+
const PassResult pm = mixed.empty()
|
| 456 |
+
? PassResult{} : run_pass(eng, mixed, bc.latency_reps);
|
| 457 |
+
if (pr.choice.n > 0) rep.choice_accuracy = static_cast<double>(pr.choice.correct) / pr.choice.n;
|
| 458 |
+
if (pr.score.n > 0) rep.score_accuracy = static_cast<double>(pr.score.correct) / pr.score.n;
|
| 459 |
+
rep.choice_n = pr.choice.n; rep.score_n = pr.score.n;
|
| 460 |
+
rep.choice_ece = PassResult::ece(pr.choice.ece_bins);
|
| 461 |
+
rep.score_ece = PassResult::ece(pr.score.ece_bins);
|
| 462 |
+
// margins/close-calls from the mixed probes when we have them (that is
|
| 463 |
+
// their home turf), else from the taught rows
|
| 464 |
+
{
|
| 465 |
+
const long margin_n_mixed = pm.choice.n + pm.score.n;
|
| 466 |
+
const long close_mixed = pm.choice.close_calls + pm.score.close_calls;
|
| 467 |
+
const double sum_mixed = pm.choice.margin_sum + pm.score.margin_sum;
|
| 468 |
+
const long margin_n_taught = pr.choice.n + pr.score.n;
|
| 469 |
+
const long close_taught = pr.choice.close_calls + pr.score.close_calls;
|
| 470 |
+
const double sum_taught = pr.choice.margin_sum + pr.score.margin_sum;
|
| 471 |
+
rep.margin_n = margin_n_mixed > 0 ? margin_n_mixed : margin_n_taught;
|
| 472 |
+
rep.close_calls = margin_n_mixed > 0 ? close_mixed : close_taught;
|
| 473 |
+
const double sum = margin_n_mixed > 0 ? sum_mixed : sum_taught;
|
| 474 |
+
if (rep.margin_n > 0) rep.mean_margin = sum / rep.margin_n;
|
| 475 |
+
}
|
| 476 |
+
{
|
| 477 |
+
// confidence gap over choice+score: mean conf on correct vs wrong.
|
| 478 |
+
// bins hold SUMS, so the per-bin mean must be divided out before
|
| 479 |
+
// weighting by the correct/wrong counts.
|
| 480 |
+
double c_ok = 0, c_bad = 0; long n_ok = 0, n_bad = 0;
|
| 481 |
+
for (const PassResult::QType* agg : {&pr.choice, &pr.score}) {
|
| 482 |
+
for (const auto& kv : agg->ece_bins) {
|
| 483 |
+
if (kv.second.n == 0) continue;
|
| 484 |
+
const double mean_conf = kv.second.conf_sum / kv.second.n;
|
| 485 |
+
c_ok += mean_conf * kv.second.correct;
|
| 486 |
+
c_bad += mean_conf * (kv.second.n - kv.second.correct);
|
| 487 |
+
n_ok += kv.second.correct;
|
| 488 |
+
n_bad += kv.second.n - kv.second.correct;
|
| 489 |
+
}
|
| 490 |
+
}
|
| 491 |
+
if (n_ok > 0) rep.conf_correct = c_ok / n_ok;
|
| 492 |
+
if (n_bad > 0) rep.conf_wrong = c_bad / n_bad;
|
| 493 |
+
}
|
| 494 |
+
rep.g_tp = pr.noul_tp; rep.g_fp = pr.noul_fp;
|
| 495 |
+
rep.g_tn = pr.noul_tn; rep.g_fn = pr.noul_fn;
|
| 496 |
+
if (pr.noul_tp + pr.noul_fp > 0)
|
| 497 |
+
rep.hold_precision = static_cast<double>(pr.noul_tp) / (pr.noul_tp + pr.noul_fp);
|
| 498 |
+
if (pr.noul_tp + pr.noul_fn > 0)
|
| 499 |
+
rep.hold_recall = static_cast<double>(pr.noul_tp) / (pr.noul_tp + pr.noul_fn);
|
| 500 |
+
|
| 501 |
+
// ---- honesty: OOD probes must defer (honest silence) ---------------------
|
| 502 |
+
{
|
| 503 |
+
std::vector<Probe> oods;
|
| 504 |
+
for (const auto& st : ood_states(eng.substrate(), bc.ood_probes)) {
|
| 505 |
+
// questions template: reuse the first eval row's questions if any
|
| 506 |
+
sfx::JV q = eval_rows.empty() ? sfx::JV(sfx::JVObj{})
|
| 507 |
+
: (eval_rows[0].has("questions") ? eval_rows[0].at("questions")
|
| 508 |
+
: sfx::JV(sfx::JVObj{}));
|
| 509 |
+
Probe p; p.state = st; p.questions = q; p.taught = false;
|
| 510 |
+
oods.push_back(p);
|
| 511 |
+
}
|
| 512 |
+
rep.ood_n = static_cast<long>(oods.size());
|
| 513 |
+
long deferred = 0, scored = 0;
|
| 514 |
+
for (const auto& p : oods) {
|
| 515 |
+
syfox::Usage u;
|
| 516 |
+
auto answers = eng.decide(p.state, p.questions, u);
|
| 517 |
+
if (answers.empty()) continue; // no questions asked: vacuous
|
| 518 |
+
++scored;
|
| 519 |
+
bool all_defer = true;
|
| 520 |
+
for (const auto& a : answers) if (!a.deferred) all_defer = false;
|
| 521 |
+
deferred += all_defer ? 1 : 0;
|
| 522 |
+
}
|
| 523 |
+
rep.ood_probes = scored;
|
| 524 |
+
rep.ood_defer_rate = scored ? static_cast<double>(deferred) / scored : 0.0;
|
| 525 |
+
}
|
| 526 |
+
|
| 527 |
+
// ---- determinism: full eval replay, byte-identical signatures ------------
|
| 528 |
+
for (int run = 1; run < bc.determinism_runs && rep.deterministic; ++run) {
|
| 529 |
+
std::vector<Probe> replay = eval_probes(eval_rows);
|
| 530 |
+
replay.insert(replay.end(), mixed.begin(), mixed.end());
|
| 531 |
+
if (replay.size() != probes.size()) { rep.deterministic = false; break; }
|
| 532 |
+
for (std::size_t i = 0; i < probes.size(); ++i) {
|
| 533 |
+
const auto s0 = decision_signature(eng, probes[i]);
|
| 534 |
+
const auto s1 = decision_signature(eng, replay[i]);
|
| 535 |
+
if (s0 != s1) { rep.deterministic = false; break; }
|
| 536 |
+
}
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
// ---- latency percentiles -------------------------------------------------
|
| 540 |
+
if (!pr.latency_us.empty()) {
|
| 541 |
+
std::vector<double> lat = pr.latency_us;
|
| 542 |
+
std::sort(lat.begin(), lat.end());
|
| 543 |
+
const auto pick = [&](double q) {
|
| 544 |
+
std::size_t i = static_cast<std::size_t>(q * (lat.size() - 1));
|
| 545 |
+
return lat[i];
|
| 546 |
+
};
|
| 547 |
+
rep.lat_p50_us = pick(0.50);
|
| 548 |
+
rep.lat_p95_us = pick(0.95);
|
| 549 |
+
double s = 0.0; for (double v : lat) s += v;
|
| 550 |
+
rep.lat_mean_us = s / static_cast<double>(lat.size());
|
| 551 |
+
}
|
| 552 |
+
return rep;
|
| 553 |
+
}
|
| 554 |
+
|
| 555 |
+
// ---------------------------------------------------------------------------
|
| 556 |
+
// v2.1 — selective prediction: the coverage-vs-accuracy curve.
|
| 557 |
+
//
|
| 558 |
+
// The headline metric of an honest eval is NOT top-1 accuracy (that is the
|
| 559 |
+
// coverage=100% corner of this curve). We sweep a confidence threshold over
|
| 560 |
+
// the TOP-PROBABILITY signal and report, for each threshold, what share of
|
| 561 |
+
// questions the model still answers (coverage) and how often it is right
|
| 562 |
+
// within that share (accuracy-within-coverage). Engine-level honest silence
|
| 563 |
+
// (unknown vocabulary) counts as covered=false at every threshold.
|
| 564 |
+
//
|
| 565 |
+
// Choice + score questions only: these carry the routing semantics the curve
|
| 566 |
+
// exists for. Labelled rows only.
|
| 567 |
+
// ---------------------------------------------------------------------------
|
| 568 |
+
struct CurvePoint {
|
| 569 |
+
double threshold = 0; // emit iff top-prob >= threshold
|
| 570 |
+
long emitted = 0;
|
| 571 |
+
long correct = 0;
|
| 572 |
+
double coverage = 0; // emitted / total
|
| 573 |
+
double accuracy = 0; // correct / emitted
|
| 574 |
+
};
|
| 575 |
+
|
| 576 |
+
struct OperatingPoint {
|
| 577 |
+
double target = 0; // requested minimum coverage (0.5 / 0.7 / 0.9)
|
| 578 |
+
bool feasible = false; // some threshold reaches the target coverage
|
| 579 |
+
double threshold = 0; // the LARGEST threshold still covering the target
|
| 580 |
+
double coverage = 0;
|
| 581 |
+
double accuracy = 0;
|
| 582 |
+
};
|
| 583 |
+
|
| 584 |
+
struct CoverageReport {
|
| 585 |
+
long total = 0; // labelled choice+score questions
|
| 586 |
+
std::vector<CurvePoint> points;
|
| 587 |
+
OperatingPoint op50, op70, op90; // spec-required operating points
|
| 588 |
+
|
| 589 |
+
sfx::JV to_json() const {
|
| 590 |
+
const auto r4 = [](double v) { return std::round(v * 10000.0) / 10000.0; };
|
| 591 |
+
sfx::JVArr pts;
|
| 592 |
+
for (const auto& p : points)
|
| 593 |
+
pts.push_back(sfx::JV(sfx::JVObj{
|
| 594 |
+
{"threshold", r4(p.threshold)},
|
| 595 |
+
{"emitted", static_cast<double>(p.emitted)},
|
| 596 |
+
{"correct", static_cast<double>(p.correct)},
|
| 597 |
+
{"coverage", r4(p.coverage)},
|
| 598 |
+
{"accuracy", r4(p.accuracy)}}));
|
| 599 |
+
auto opj = [](const OperatingPoint& o) {
|
| 600 |
+
return sfx::JV(sfx::JVObj{
|
| 601 |
+
{"feasible", sfx::JV(o.feasible)},
|
| 602 |
+
{"threshold", std::round(o.threshold * 10000.0) / 10000.0},
|
| 603 |
+
{"coverage", std::round(o.coverage * 10000.0) / 10000.0},
|
| 604 |
+
{"accuracy", std::round(o.accuracy * 10000.0) / 10000.0}});
|
| 605 |
+
};
|
| 606 |
+
return sfx::JV(sfx::JVObj{
|
| 607 |
+
{"total", static_cast<double>(total)},
|
| 608 |
+
{"points", sfx::JV(pts)},
|
| 609 |
+
{"at_50_coverage", opj(op50)},
|
| 610 |
+
{"at_70_coverage", opj(op70)},
|
| 611 |
+
{"at_90_coverage", opj(op90)}});
|
| 612 |
+
}
|
| 613 |
+
};
|
| 614 |
+
|
| 615 |
+
inline CoverageReport coverage_curve(Engine& eng, const std::vector<sfx::JV>& eval_rows,
|
| 616 |
+
int steps = 20) {
|
| 617 |
+
CoverageReport cr;
|
| 618 |
+
struct Sample { float conf; bool correct; bool engine_deferred; };
|
| 619 |
+
std::vector<Sample> samples;
|
| 620 |
+
|
| 621 |
+
for (const auto& p : eval_probes(eval_rows)) {
|
| 622 |
+
syfox::Usage u;
|
| 623 |
+
auto answers = eng.decide(p.state, p.questions, u);
|
| 624 |
+
std::size_t ai = 0;
|
| 625 |
+
for (const auto& qkv : p.questions.obj) {
|
| 626 |
+
if (ai >= answers.size()) break;
|
| 627 |
+
const syfox::Answer& a = answers[ai++];
|
| 628 |
+
const std::string type = qkv.second.at("type").as_str();
|
| 629 |
+
if (type != "choice" && type != "score") continue;
|
| 630 |
+
Sample s; s.engine_deferred = a.deferred; s.conf = 0.0f; s.correct = false;
|
| 631 |
+
if (!a.deferred && !a.probabilities.empty()) {
|
| 632 |
+
float top = -1.0f;
|
| 633 |
+
std::string amax;
|
| 634 |
+
for (const auto& kv : a.probabilities)
|
| 635 |
+
if (kv.second > top) { top = kv.second; amax = kv.first; }
|
| 636 |
+
s.conf = std::max(0.0f, top);
|
| 637 |
+
const std::string stored =
|
| 638 |
+
p.labels.count(qkv.first) ? p.labels.at(qkv.first) : "";
|
| 639 |
+
s.correct = label_matches(qkv.second, stored, amax);
|
| 640 |
+
}
|
| 641 |
+
samples.push_back(s);
|
| 642 |
+
}
|
| 643 |
+
}
|
| 644 |
+
cr.total = static_cast<long>(samples.size());
|
| 645 |
+
if (cr.total == 0) return cr;
|
| 646 |
+
|
| 647 |
+
for (int i = 0; i <= steps; ++i) {
|
| 648 |
+
const double tau = static_cast<double>(i) / static_cast<double>(steps);
|
| 649 |
+
CurvePoint pt; pt.threshold = tau;
|
| 650 |
+
for (const auto& s : samples) {
|
| 651 |
+
if (s.engine_deferred) continue; // honest silence: never emitted
|
| 652 |
+
if (tau > 0.0 && static_cast<double>(s.conf) < tau) continue;
|
| 653 |
+
++pt.emitted; pt.correct += s.correct ? 1 : 0;
|
| 654 |
+
}
|
| 655 |
+
pt.coverage = static_cast<double>(pt.emitted) / static_cast<double>(cr.total);
|
| 656 |
+
pt.accuracy = pt.emitted > 0
|
| 657 |
+
? static_cast<double>(pt.correct) / static_cast<double>(pt.emitted) : 0.0;
|
| 658 |
+
cr.points.push_back(pt);
|
| 659 |
+
}
|
| 660 |
+
|
| 661 |
+
// Operating point for a target coverage: the LARGEST threshold whose
|
| 662 |
+
// coverage still meets the target (answer at least that share, and be as
|
| 663 |
+
// accurate as the curve allows at that share).
|
| 664 |
+
auto pick = [&](double target) {
|
| 665 |
+
OperatingPoint op; op.target = target;
|
| 666 |
+
for (auto it = cr.points.rbegin(); it != cr.points.rend(); ++it) {
|
| 667 |
+
if (it->coverage >= target) {
|
| 668 |
+
op.feasible = true;
|
| 669 |
+
op.threshold = it->threshold;
|
| 670 |
+
op.coverage = it->coverage;
|
| 671 |
+
op.accuracy = it->accuracy;
|
| 672 |
+
return op;
|
| 673 |
+
}
|
| 674 |
+
}
|
| 675 |
+
// infeasible: report the widest-net point (threshold 0) for context
|
| 676 |
+
const CurvePoint& p0 = cr.points.front();
|
| 677 |
+
op.threshold = p0.threshold; op.coverage = p0.coverage; op.accuracy = p0.accuracy;
|
| 678 |
+
return op;
|
| 679 |
+
};
|
| 680 |
+
cr.op50 = pick(0.50); cr.op70 = pick(0.70); cr.op90 = pick(0.90);
|
| 681 |
+
return cr;
|
| 682 |
+
}
|
| 683 |
+
|
| 684 |
+
// ASCII rendering of the coverage curve: accuracy (y, 0-100%) against
|
| 685 |
+
// coverage (x, 0-100%), one mark per sweep point. Thresholds fall where
|
| 686 |
+
// they fall; guides mark the 50/70/90 operating points.
|
| 687 |
+
inline std::string coverage_plot(const CoverageReport& cr, int width = 60, int height = 20) {
|
| 688 |
+
std::vector<std::string> grid(height, std::string(width, ' '));
|
| 689 |
+
for (const auto& p : cr.points) {
|
| 690 |
+
if (p.emitted == 0 && p.threshold > 0.0) continue;
|
| 691 |
+
const int x = std::min(width - 1,
|
| 692 |
+
static_cast<int>(std::round(p.coverage * (width - 1))));
|
| 693 |
+
const int y = std::min(height - 1,
|
| 694 |
+
static_cast<int>(std::round(p.accuracy * (height - 1))));
|
| 695 |
+
grid[height - 1 - y][x] = '*'; // later (higher-threshold) points overwrite
|
| 696 |
+
}
|
| 697 |
+
auto mark = [&](const OperatingPoint& op, char c) {
|
| 698 |
+
if (!op.feasible) return;
|
| 699 |
+
const int x = std::min(width - 1,
|
| 700 |
+
static_cast<int>(std::round(op.coverage * (width - 1))));
|
| 701 |
+
const int y = std::min(height - 1,
|
| 702 |
+
static_cast<int>(std::round(op.accuracy * (height - 1))));
|
| 703 |
+
grid[height - 1 - y][x] = c; // operating points stay visible
|
| 704 |
+
};
|
| 705 |
+
mark(cr.op50, '5'); mark(cr.op70, '7'); mark(cr.op90, '9');
|
| 706 |
+
|
| 707 |
+
std::ostringstream out;
|
| 708 |
+
out << " accuracy % |";
|
| 709 |
+
for (int x = 0; x < width; ++x) out << '-';
|
| 710 |
+
out << "| coverage %\n";
|
| 711 |
+
for (int r = 0; r < height; ++r) {
|
| 712 |
+
const int acc = 100 - static_cast<int>(std::lround(100.0 * r / (height - 1)));
|
| 713 |
+
char label[16];
|
| 714 |
+
std::snprintf(label, sizeof(label), "%4d", acc);
|
| 715 |
+
out << " " << label << " |" << grid[r] << "|\n";
|
| 716 |
+
}
|
| 717 |
+
out << " ";
|
| 718 |
+
for (int i = 0; i < 11; ++i) out << '+';
|
| 719 |
+
for (int i = 0; i < width - 11; ++i) out << '-';
|
| 720 |
+
out << "\n ";
|
| 721 |
+
out << "0% 50% 100% (* sweep point; 5/7/9 = coverage>=50/70/90% op)\n";
|
| 722 |
+
return out.str();
|
| 723 |
+
}
|
| 724 |
+
|
| 725 |
+
// ---------------------------------------------------------------------------
|
| 726 |
+
// v2.1 — aggregate labelled accuracy over a row set (choice + score + noul).
|
| 727 |
+
// Used by the derive gate to report held-out accuracy before/after, and by
|
| 728 |
+
// any caller that wants one number over labelled rows. Deferred answers are
|
| 729 |
+
// neither correct nor wrong (honest silence) — they leave the denominator.
|
| 730 |
+
// ---------------------------------------------------------------------------
|
| 731 |
+
struct AccSummary {
|
| 732 |
+
long n = 0, correct = 0;
|
| 733 |
+
double accuracy = 0.0;
|
| 734 |
+
long choice_n = 0, choice_correct = 0;
|
| 735 |
+
long score_n = 0, score_correct = 0;
|
| 736 |
+
long noul_n = 0, noul_correct = 0;
|
| 737 |
+
};
|
| 738 |
+
|
| 739 |
+
inline AccSummary labelled_accuracy(Engine& eng, const std::vector<sfx::JV>& rows) {
|
| 740 |
+
const PassResult pr = run_pass(eng, eval_probes(rows), 1);
|
| 741 |
+
AccSummary s;
|
| 742 |
+
s.choice_n = pr.choice.n; s.choice_correct = pr.choice.correct;
|
| 743 |
+
s.score_n = pr.score.n; s.score_correct = pr.score.correct;
|
| 744 |
+
s.noul_n = pr.noul_n; s.noul_correct = pr.noul_tp + pr.noul_tn;
|
| 745 |
+
s.n = s.choice_n + s.score_n + s.noul_n;
|
| 746 |
+
s.correct = s.choice_correct + s.score_correct + s.noul_correct;
|
| 747 |
+
if (s.n > 0) s.accuracy = static_cast<double>(s.correct) / static_cast<double>(s.n);
|
| 748 |
+
return s;
|
| 749 |
+
}
|
| 750 |
+
|
| 751 |
+
// ---------------------------------------------------------------------------
|
| 752 |
+
// v3 Milestone 4 — adversarial / OOD evaluation suite
|
| 753 |
+
// ---------------------------------------------------------------------------
|
| 754 |
+
// Nine deterministic stress families over labelled eval rows (the hidden test
|
| 755 |
+
// in the M1 discipline). The engine under test is NEVER mutated: all families
|
| 756 |
+
// run read-only decisions, except the conflicting-lessons sub-suite, which
|
| 757 |
+
// works on a THROWAWAY copy of the engine and reports its blast radius.
|
| 758 |
+
//
|
| 759 |
+
// Metrics per family (the four the milestone asks for, made concrete):
|
| 760 |
+
// accuracy labelled-choice accuracy under the transform
|
| 761 |
+
// defer_rate fraction of choice answers deferred (honest silence)
|
| 762 |
+
// conf_when_wrong mean confidence of WRONG non-deferred answers
|
| 763 |
+
// false_conf_rate wrong AND confidence >= 0.5 AND not deferred / answered
|
| 764 |
+
//
|
| 765 |
+
// Honesty notes baked into the report:
|
| 766 |
+
// * synonym-swap paraphrases fold to the SAME token stream after
|
| 767 |
+
// normalization (Porter + synonym table), so they are not adversarial
|
| 768 |
+
// here — the paraphrase axis is covered by reorder + padding, which DO
|
| 769 |
+
// change the token stream.
|
| 770 |
+
// * score/noul questions are not scored under label-preserving transforms:
|
| 771 |
+
// a transformed state may legitimately move a frustration score or flip a
|
| 772 |
+
// guard valence, so scoring them would manufacture errors. Choice
|
| 773 |
+
// (routing) is intent-level and label-stable; that is what is scored.
|
| 774 |
+
// * every transform is a pure function of the row index: the suite replays
|
| 775 |
+
// bit-identically.
|
| 776 |
+
// ---------------------------------------------------------------------------
|
| 777 |
+
struct AdvFamilyResult {
|
| 778 |
+
std::string name, note;
|
| 779 |
+
long n = 0, answered = 0, correct = 0, deferred = 0, high_conf_wrong = 0;
|
| 780 |
+
double conf_wrong_sum = 0.0;
|
| 781 |
+
|
| 782 |
+
double accuracy() const {
|
| 783 |
+
return answered ? static_cast<double>(correct) / static_cast<double>(answered) : 0.0;
|
| 784 |
+
}
|
| 785 |
+
double defer_rate() const {
|
| 786 |
+
return n ? static_cast<double>(deferred) / static_cast<double>(n) : 0.0;
|
| 787 |
+
}
|
| 788 |
+
double conf_when_wrong() const {
|
| 789 |
+
long wrong = answered - correct;
|
| 790 |
+
return wrong > 0 ? conf_wrong_sum / static_cast<double>(wrong) : 0.0;
|
| 791 |
+
}
|
| 792 |
+
double false_conf_rate() const {
|
| 793 |
+
return answered ? static_cast<double>(high_conf_wrong) / static_cast<double>(answered) : 0.0;
|
| 794 |
+
}
|
| 795 |
+
sfx::JV to_json() const {
|
| 796 |
+
return sfx::JV(sfx::JVObj{
|
| 797 |
+
{"name", sfx::JV(name)},
|
| 798 |
+
{"n", static_cast<double>(n)},
|
| 799 |
+
{"answered", static_cast<double>(answered)},
|
| 800 |
+
{"accuracy", std::round(accuracy() * 10000.0) / 10000.0},
|
| 801 |
+
{"defer_rate", std::round(defer_rate() * 10000.0) / 10000.0},
|
| 802 |
+
{"conf_when_wrong", std::round(conf_when_wrong() * 10000.0) / 10000.0},
|
| 803 |
+
{"false_conf_rate", std::round(false_conf_rate() * 10000.0) / 10000.0},
|
| 804 |
+
{"note", sfx::JV(note)}});
|
| 805 |
+
}
|
| 806 |
+
};
|
| 807 |
+
|
| 808 |
+
// whitespace tokenizer for the state transforms (surface form; decide()
|
| 809 |
+
// re-normalizes internally, so transforming surface text is enough)
|
| 810 |
+
inline std::vector<std::string> adv_split(const std::string& s) {
|
| 811 |
+
std::vector<std::string> out;
|
| 812 |
+
std::istringstream in(s);
|
| 813 |
+
std::string w;
|
| 814 |
+
while (in >> w) out.push_back(w);
|
| 815 |
+
return out;
|
| 816 |
+
}
|
| 817 |
+
inline std::string adv_join(const std::vector<std::string>& ws) {
|
| 818 |
+
std::string out;
|
| 819 |
+
for (std::size_t i = 0; i < ws.size(); ++i) { if (i) out += " "; out += ws[i]; }
|
| 820 |
+
return out;
|
| 821 |
+
}
|
| 822 |
+
|
| 823 |
+
// label -> outcome text, identical to the CLI's learn-side resolution so the
|
| 824 |
+
// conflicting-lessons sub-suite teaches in EXACTLY the production format.
|
| 825 |
+
inline std::string adv_outcome_text(const sfx::JV& q, const std::string& label) {
|
| 826 |
+
if (!q.has("criteria")) return label;
|
| 827 |
+
const sfx::JV& crit = q.at("criteria");
|
| 828 |
+
if (crit.is_obj() && crit.has(label)) return label + " " + crit.at(label).as_str();
|
| 829 |
+
if (crit.is_arr()) {
|
| 830 |
+
for (const auto& v : crit.arr)
|
| 831 |
+
if (v.as_str() == label) return label;
|
| 832 |
+
long idx = std::strtol(label.c_str(), nullptr, 10);
|
| 833 |
+
if (idx >= 0 && idx < static_cast<long>(crit.arr.size()))
|
| 834 |
+
return crit.arr[static_cast<std::size_t>(idx)].as_str();
|
| 835 |
+
}
|
| 836 |
+
return label;
|
| 837 |
+
}
|
| 838 |
+
|
| 839 |
+
// the first choice-type question of a row (qid + question object)
|
| 840 |
+
inline bool adv_first_choice(const sfx::JV& row, std::string& qid, sfx::JV& qout) {
|
| 841 |
+
if (!row.has("questions") || !row.at("questions").is_obj()) return false;
|
| 842 |
+
for (const auto& qkv : row.at("questions").obj) {
|
| 843 |
+
if (qkv.second.has("type") && qkv.second.at("type").as_str() == "choice") {
|
| 844 |
+
qid = qkv.first; qout = qkv.second; return true;
|
| 845 |
+
}
|
| 846 |
+
}
|
| 847 |
+
return false;
|
| 848 |
+
}
|
| 849 |
+
|
| 850 |
+
// foreign vocabulary pools for near-miss / cross-domain families. Used only
|
| 851 |
+
// when the caller does not pass --mix; pools are per-domain content words.
|
| 852 |
+
inline std::vector<std::string> adv_builtin_pool(const std::string& model_name) {
|
| 853 |
+
static const char* kGame[] = {"zombie", "dungeon", "quest", "sword", "shelter",
|
| 854 |
+
"respawn", "boss", "inventory", "health", "village",
|
| 855 |
+
"attack", "defend", "resources", "night", "wall"};
|
| 856 |
+
static const char* kTicket[] = {"invoice", "refund", "login", "password", "screen",
|
| 857 |
+
"keyboard", "subscription", "shipping", "warranty",
|
| 858 |
+
"crash", "email", "account", "payment", "update", "server"};
|
| 859 |
+
static const char* kGuard[] = {"rm", "sudo", "drop", "table", "delete", "wipe",
|
| 860 |
+
"chmod", "root", "exec", "payload", "script",
|
| 861 |
+
"database", "credential", "token", "deploy"};
|
| 862 |
+
std::vector<std::string> out;
|
| 863 |
+
auto add = [&out](const char** arr, int k) {
|
| 864 |
+
for (int i = 0; i < k; ++i) out.push_back(arr[i]);
|
| 865 |
+
};
|
| 866 |
+
const bool has_ticket = model_name.find("ticket") != std::string::npos;
|
| 867 |
+
const bool has_game = model_name.find("game") != std::string::npos;
|
| 868 |
+
const bool has_guard = model_name.find("guard") != std::string::npos;
|
| 869 |
+
if (has_ticket) { add(kGame, 15); add(kGuard, 15); }
|
| 870 |
+
else if (has_game) { add(kTicket, 15); add(kGuard, 15); }
|
| 871 |
+
else if (has_guard) { add(kTicket, 15); add(kGame, 15); }
|
| 872 |
+
else { add(kGame, 15); add(kTicket, 15); } // unknown domain: everything foreign
|
| 873 |
+
return out;
|
| 874 |
+
}
|
| 875 |
+
|
| 876 |
+
// content words from --mix rows (the caller's own cross-domain corpus)
|
| 877 |
+
inline std::vector<std::string> adv_pool_from_rows(const std::vector<sfx::JV>& mix_rows) {
|
| 878 |
+
std::vector<std::string> out;
|
| 879 |
+
std::set<std::string> seen;
|
| 880 |
+
for (const auto& r : mix_rows) {
|
| 881 |
+
if (!r.has("state")) continue;
|
| 882 |
+
for (const auto& t : si::norm::normalize(r.at("state").as_str())) {
|
| 883 |
+
if (t.size() < 4 || seen.count(t)) continue;
|
| 884 |
+
seen.insert(t);
|
| 885 |
+
out.push_back(t);
|
| 886 |
+
if (out.size() >= 400) return out;
|
| 887 |
+
}
|
| 888 |
+
}
|
| 889 |
+
return out;
|
| 890 |
+
}
|
| 891 |
+
|
| 892 |
+
struct ConflictResult {
|
| 893 |
+
long taught = 0, detected = 0, contested_flagged = 0, checked = 0;
|
| 894 |
+
double untouched_acc_before = 0.0, untouched_acc_control = 0.0, untouched_acc_after = 0.0;
|
| 895 |
+
bool deterministic_after = true;
|
| 896 |
+
sfx::JV to_json() const {
|
| 897 |
+
return sfx::JV(sfx::JVObj{
|
| 898 |
+
{"contradictions_taught", static_cast<double>(taught)},
|
| 899 |
+
{"conflicts_detected", static_cast<double>(detected)},
|
| 900 |
+
{"contested_flagged", static_cast<double>(contested_flagged)},
|
| 901 |
+
{"states_checked", static_cast<double>(checked)},
|
| 902 |
+
{"untouched_acc_before", std::round(untouched_acc_before * 10000.0) / 10000.0},
|
| 903 |
+
{"untouched_acc_control", std::round(untouched_acc_control * 10000.0) / 10000.0},
|
| 904 |
+
{"untouched_acc_after", std::round(untouched_acc_after * 10000.0) / 10000.0},
|
| 905 |
+
{"deterministic_after", sfx::JV(deterministic_after)},
|
| 906 |
+
{"silent_override", sfx::JV(detected != taught || contested_flagged != checked)},
|
| 907 |
+
{"note", sfx::JV("control arm = same states re-taught with their GOLD outcomes "
|
| 908 |
+
"(same teach-event count, no dispute): isolates the forgetting-law "
|
| 909 |
+
"cost every teach event pays from contradiction-specific damage. "
|
| 910 |
+
"Accuracy basis: all labelled questions (choice+score+noul).")}});
|
| 911 |
+
}
|
| 912 |
+
};
|
| 913 |
+
|
| 914 |
+
struct AdvReport {
|
| 915 |
+
std::vector<AdvFamilyResult> families;
|
| 916 |
+
ConflictResult conflicts;
|
| 917 |
+
sfx::JV to_json() const {
|
| 918 |
+
sfx::JVArr f;
|
| 919 |
+
for (const auto& fam : families) f.push_back(fam.to_json());
|
| 920 |
+
// worst false-confidence family = the headline honesty risk
|
| 921 |
+
std::string worst; double worst_fc = -1.0;
|
| 922 |
+
for (const auto& fam : families) {
|
| 923 |
+
if (fam.answered < 10) continue; // too small to judge
|
| 924 |
+
if (fam.false_conf_rate() > worst_fc) { worst_fc = fam.false_conf_rate(); worst = fam.name; }
|
| 925 |
+
}
|
| 926 |
+
return sfx::JV(sfx::JVObj{
|
| 927 |
+
{"families", sfx::JV(f)},
|
| 928 |
+
{"conflicting_lessons", conflicts.to_json()},
|
| 929 |
+
{"worst_false_conf_family", sfx::JV(worst)},
|
| 930 |
+
{"worst_false_conf_rate", std::round(worst_fc * 10000.0) / 10000.0},
|
| 931 |
+
{"note", sfx::JV("all transforms are pure functions of the row index; "
|
| 932 |
+
"the suite replays bit-identically and never mutates the "
|
| 933 |
+
"model under test (conflicts run on a throwaway copy)")}});
|
| 934 |
+
}
|
| 935 |
+
};
|
| 936 |
+
|
| 937 |
+
// score ONE transformed probe set on choice questions only, accumulating the
|
| 938 |
+
// four M4 metrics. Deferred answers count toward defer_rate, leave accuracy.
|
| 939 |
+
inline AdvFamilyResult adv_score_family(Engine& eng, const std::vector<Probe>& probes,
|
| 940 |
+
const std::string& name, const std::string& note) {
|
| 941 |
+
AdvFamilyResult fam; fam.name = name; fam.note = note;
|
| 942 |
+
for (const auto& p : probes) {
|
| 943 |
+
syfox::Usage u;
|
| 944 |
+
auto answers = eng.decide(p.state, p.questions, u);
|
| 945 |
+
std::size_t ai = 0;
|
| 946 |
+
for (const auto& qkv : p.questions.obj) {
|
| 947 |
+
const sfx::JV& q = qkv.second;
|
| 948 |
+
if (ai >= answers.size()) break;
|
| 949 |
+
const syfox::Answer& a = answers[ai++];
|
| 950 |
+
if (q.at("type").as_str() != "choice") continue; // choice-only scoring
|
| 951 |
+
++fam.n;
|
| 952 |
+
if (a.deferred) { ++fam.deferred; continue; }
|
| 953 |
+
if (a.probabilities.empty()) { ++fam.deferred; continue; }
|
| 954 |
+
std::string amax; float top = -1.0f;
|
| 955 |
+
for (const auto& kv : a.probabilities)
|
| 956 |
+
if (kv.second > top) { top = kv.second; amax = kv.first; }
|
| 957 |
+
const std::string stored =
|
| 958 |
+
p.labels.count(qkv.first) ? p.labels.at(qkv.first) : "";
|
| 959 |
+
++fam.answered;
|
| 960 |
+
const bool correct = p.taught && label_matches(q, stored, amax);
|
| 961 |
+
fam.correct += correct ? 1 : 0;
|
| 962 |
+
if (!correct) {
|
| 963 |
+
fam.conf_wrong_sum += a.confidence;
|
| 964 |
+
if (a.confidence >= 0.5f) ++fam.high_conf_wrong;
|
| 965 |
+
}
|
| 966 |
+
}
|
| 967 |
+
}
|
| 968 |
+
return fam;
|
| 969 |
+
}
|
| 970 |
+
|
| 971 |
+
inline std::vector<Probe> adv_transform_rows(const std::vector<sfx::JV>& rows,
|
| 972 |
+
std::string (*fn)(const std::string&, std::size_t)) {
|
| 973 |
+
std::vector<Probe> out;
|
| 974 |
+
std::size_t i = 0;
|
| 975 |
+
for (const auto& r : rows) {
|
| 976 |
+
if (!r.has("state") || !r.has("questions") || !r.has("labels")) { ++i; continue; }
|
| 977 |
+
Probe p;
|
| 978 |
+
p.state = fn(r.at("state").as_str(), i);
|
| 979 |
+
p.questions = r.at("questions");
|
| 980 |
+
for (const auto& kv : r.at("labels").obj) p.labels[kv.first] = kv.second.as_str();
|
| 981 |
+
p.taught = true;
|
| 982 |
+
out.push_back(p);
|
| 983 |
+
++i;
|
| 984 |
+
}
|
| 985 |
+
return out;
|
| 986 |
+
}
|
| 987 |
+
|
| 988 |
+
// -- the transform families (pure functions of state + row index) ------------
|
| 989 |
+
inline std::string adv_reorder(const std::string& s, std::size_t) {
|
| 990 |
+
std::vector<std::string> ws = adv_split(s);
|
| 991 |
+
if (ws.size() < 3) return s;
|
| 992 |
+
const std::size_t h = ws.size() / 2;
|
| 993 |
+
std::vector<std::string> out(ws.begin() + static_cast<long>(h), ws.end());
|
| 994 |
+
out.insert(out.end(), ws.begin(), ws.begin() + static_cast<long>(h));
|
| 995 |
+
return adv_join(out);
|
| 996 |
+
}
|
| 997 |
+
inline std::string adv_padding(const std::string& s, std::size_t i) {
|
| 998 |
+
static const char* kPad[] = {
|
| 999 |
+
"Hope you are doing well today.",
|
| 1000 |
+
"Also the weather is quite nice this week.",
|
| 1001 |
+
"This is an unrelated aside about office chairs.",
|
| 1002 |
+
"By the way the meeting got rescheduled again."};
|
| 1003 |
+
return s + " " + kPad[i % 4];
|
| 1004 |
+
}
|
| 1005 |
+
inline std::string adv_typo(const std::string& s, std::size_t) {
|
| 1006 |
+
return corrupt_state(s, 15.0f);
|
| 1007 |
+
}
|
| 1008 |
+
inline std::string adv_intensifiers(const std::string& s, std::size_t) {
|
| 1009 |
+
std::vector<std::string> ws = adv_split(s);
|
| 1010 |
+
std::vector<std::string> out;
|
| 1011 |
+
long doubled = 0;
|
| 1012 |
+
for (const auto& w : ws) {
|
| 1013 |
+
out.push_back(w);
|
| 1014 |
+
if (w.size() > 3 && doubled < 3) { out.push_back(w); ++doubled; }
|
| 1015 |
+
}
|
| 1016 |
+
out.push_back("URGENT"); out.push_back("URGENT");
|
| 1017 |
+
return adv_join(out);
|
| 1018 |
+
}
|
| 1019 |
+
inline std::string adv_self_contradiction(const std::string& s, std::size_t) {
|
| 1020 |
+
return s + " Actually never mind, everything is fine now.";
|
| 1021 |
+
}
|
| 1022 |
+
inline std::string adv_negation(const std::string& s, std::size_t) {
|
| 1023 |
+
std::vector<std::string> ws = adv_split(s);
|
| 1024 |
+
for (std::size_t j = 0; j < ws.size(); ++j)
|
| 1025 |
+
if (ws[j].size() > 3) { ws.insert(ws.begin() + static_cast<long>(j), "not"); break; }
|
| 1026 |
+
return adv_join(ws);
|
| 1027 |
+
}
|
| 1028 |
+
inline std::string adv_double_negation(const std::string& s, std::size_t) {
|
| 1029 |
+
return s + " It is not that this was never handled.";
|
| 1030 |
+
}
|
| 1031 |
+
// unknown vocabulary: rows re-generated from the OOD nonsense pool (the same
|
| 1032 |
+
// machinery as the honesty probes, filtered against THIS model's vocabulary)
|
| 1033 |
+
inline std::vector<Probe> adv_unknown_probes(Engine& eng, const std::vector<sfx::JV>& rows) {
|
| 1034 |
+
std::vector<Probe> out;
|
| 1035 |
+
const auto nonsense = ood_states(eng.substrate(), 24);
|
| 1036 |
+
if (nonsense.empty()) return out;
|
| 1037 |
+
for (const auto& r : rows) {
|
| 1038 |
+
if (!r.has("questions") || !r.has("labels")) continue;
|
| 1039 |
+
Probe p;
|
| 1040 |
+
p.state = nonsense[out.size() % nonsense.size()];
|
| 1041 |
+
p.questions = r.at("questions");
|
| 1042 |
+
for (const auto& kv : r.at("labels").obj) p.labels[kv.first] = kv.second.as_str();
|
| 1043 |
+
p.taught = false; // nonsense has no gold answer: defer-only
|
| 1044 |
+
out.push_back(p);
|
| 1045 |
+
if (out.size() >= 48) break;
|
| 1046 |
+
}
|
| 1047 |
+
return out;
|
| 1048 |
+
}
|
| 1049 |
+
// near-miss: foreign words that SHARE trigrams with taught vocabulary — the
|
| 1050 |
+
// dangerous OOD class, because the traction gate may bridge them
|
| 1051 |
+
inline std::vector<Probe> adv_nearmiss_probes(Engine& eng, const std::vector<sfx::JV>& rows,
|
| 1052 |
+
const std::vector<std::string>& pool) {
|
| 1053 |
+
std::vector<Probe> out;
|
| 1054 |
+
if (pool.empty()) return out;
|
| 1055 |
+
std::vector<std::string> entangled;
|
| 1056 |
+
for (const auto& w : pool) {
|
| 1057 |
+
for (const auto& g : si::norm::expand_ngrams({w}))
|
| 1058 |
+
if (eng.substrate().has(g)) { entangled.push_back(w); break; }
|
| 1059 |
+
if (entangled.size() >= 32) break;
|
| 1060 |
+
}
|
| 1061 |
+
if (entangled.empty()) return out;
|
| 1062 |
+
for (const auto& r : rows) {
|
| 1063 |
+
if (!r.has("state") || !r.has("questions") || !r.has("labels")) continue;
|
| 1064 |
+
std::vector<std::string> ws = adv_split(r.at("state").as_str());
|
| 1065 |
+
long hit = -1;
|
| 1066 |
+
for (std::size_t j = ws.size(); j-- > 0;)
|
| 1067 |
+
if (ws[j].size() > 3) { hit = static_cast<long>(j); break; }
|
| 1068 |
+
if (hit >= 0) ws[static_cast<std::size_t>(hit)] = entangled[out.size() % entangled.size()];
|
| 1069 |
+
Probe p;
|
| 1070 |
+
p.state = adv_join(ws);
|
| 1071 |
+
p.questions = r.at("questions");
|
| 1072 |
+
for (const auto& kv : r.at("labels").obj) p.labels[kv.first] = kv.second.as_str();
|
| 1073 |
+
p.taught = true;
|
| 1074 |
+
out.push_back(p);
|
| 1075 |
+
if (out.size() >= 240) break;
|
| 1076 |
+
}
|
| 1077 |
+
return out;
|
| 1078 |
+
}
|
| 1079 |
+
// cross-domain mixture: append foreign content words to the state
|
| 1080 |
+
inline std::vector<Probe> adv_crossdomain_probes(const std::vector<sfx::JV>& rows,
|
| 1081 |
+
const std::vector<std::string>& pool) {
|
| 1082 |
+
std::vector<Probe> out;
|
| 1083 |
+
if (pool.empty()) return out;
|
| 1084 |
+
for (const auto& r : rows) {
|
| 1085 |
+
if (!r.has("state") || !r.has("questions") || !r.has("labels")) continue;
|
| 1086 |
+
std::string st = r.at("state").as_str();
|
| 1087 |
+
for (int j = 0; j < 4; ++j)
|
| 1088 |
+
st += " " + pool[(out.size() * 4 + static_cast<std::size_t>(j)) % pool.size()];
|
| 1089 |
+
Probe p;
|
| 1090 |
+
p.state = st;
|
| 1091 |
+
p.questions = r.at("questions");
|
| 1092 |
+
for (const auto& kv : r.at("labels").obj) p.labels[kv.first] = kv.second.as_str();
|
| 1093 |
+
p.taught = true;
|
| 1094 |
+
out.push_back(p);
|
| 1095 |
+
if (out.size() >= 240) break;
|
| 1096 |
+
}
|
| 1097 |
+
return out;
|
| 1098 |
+
}
|
| 1099 |
+
|
| 1100 |
+
// -- the conflicting-lessons sub-suite (throwaway engine copy) ---------------
|
| 1101 |
+
// The M3 contract under attack: contradictory lessons must (a) always be
|
| 1102 |
+
// detected, (b) always surface as contested in the evidence, (c) keep
|
| 1103 |
+
// decisions deterministic, and (d) cause no damage beyond what ANY teach
|
| 1104 |
+
// event causes (the forgetting law decays every lane on every deposit, so a
|
| 1105 |
+
// CONTROL arm — same states re-taught with their gold outcomes — isolates
|
| 1106 |
+
// the contradiction-specific cost).
|
| 1107 |
+
inline ConflictResult adv_conflict_suite(const Engine& eng, const std::vector<sfx::JV>& rows) {
|
| 1108 |
+
ConflictResult cr;
|
| 1109 |
+
// collect the rows we can contradict (a choice question with a criteria
|
| 1110 |
+
// list to pick a wrong answer from)
|
| 1111 |
+
struct Target { std::string state, instructions, gold_outcome, wrong_outcome; sfx::JV q; };
|
| 1112 |
+
std::vector<Target> targets;
|
| 1113 |
+
for (const auto& r : rows) {
|
| 1114 |
+
if (!r.has("state") || !r.has("labels")) continue;
|
| 1115 |
+
std::string qid; sfx::JV q;
|
| 1116 |
+
if (!adv_first_choice(r, qid, q)) continue;
|
| 1117 |
+
if (!r.at("labels").has(qid)) continue;
|
| 1118 |
+
const std::string gold = r.at("labels").at(qid).as_str();
|
| 1119 |
+
std::string wrong;
|
| 1120 |
+
if (q.has("criteria") && q.at("criteria").is_obj()) {
|
| 1121 |
+
for (const auto& kv : q.at("criteria").obj)
|
| 1122 |
+
if (kv.first != gold) { wrong = kv.first; break; }
|
| 1123 |
+
} else if (q.has("criteria") && q.at("criteria").is_arr()) {
|
| 1124 |
+
for (const auto& v : q.at("criteria").arr) {
|
| 1125 |
+
bool is_gold = v.as_str() == gold;
|
| 1126 |
+
long idx = std::strtol(gold.c_str(), nullptr, 10);
|
| 1127 |
+
if (idx >= 0 && idx < static_cast<long>(q.at("criteria").arr.size()) &&
|
| 1128 |
+
q.at("criteria").arr[static_cast<std::size_t>(idx)].as_str() == v.as_str())
|
| 1129 |
+
is_gold = true;
|
| 1130 |
+
if (!is_gold) { wrong = v.as_str(); break; }
|
| 1131 |
+
}
|
| 1132 |
+
}
|
| 1133 |
+
if (wrong.empty()) continue;
|
| 1134 |
+
targets.push_back({r.at("state").as_str(), q.at("instructions").as_str(),
|
| 1135 |
+
adv_outcome_text(q, gold), adv_outcome_text(q, wrong), q});
|
| 1136 |
+
if (targets.size() >= 40) break;
|
| 1137 |
+
}
|
| 1138 |
+
if (targets.empty()) return cr;
|
| 1139 |
+
std::vector<sfx::JV> suffix(rows.begin() + static_cast<long>(targets.size()), rows.end());
|
| 1140 |
+
// pristine copy for the BEFORE baseline (the engine under test is never
|
| 1141 |
+
// touched, not even for read-only scoring)
|
| 1142 |
+
syfox::Engine pristine = eng;
|
| 1143 |
+
if (!suffix.empty())
|
| 1144 |
+
cr.untouched_acc_before = labelled_accuracy(pristine, suffix).accuracy;
|
| 1145 |
+
// ATTACK copy: establish the gold lesson, then contradict it. The
|
| 1146 |
+
// establish step is required — hidden rows were never taught, and a
|
| 1147 |
+
// wrong answer to a state the fabric never learned is NOT a dispute.
|
| 1148 |
+
syfox::Engine probe = eng;
|
| 1149 |
+
const long conflicts_before = static_cast<long>(probe.conflicts().size());
|
| 1150 |
+
for (const auto& t : targets) {
|
| 1151 |
+
probe.learn_example(t.state, t.instructions, t.gold_outcome);
|
| 1152 |
+
probe.learn_example(t.state, t.instructions, t.wrong_outcome);
|
| 1153 |
+
}
|
| 1154 |
+
cr.taught = static_cast<long>(targets.size());
|
| 1155 |
+
cr.detected = static_cast<long>(probe.conflicts().size()) - conflicts_before;
|
| 1156 |
+
// CONTROL copy: same teach-event count, gold outcomes only — no dispute
|
| 1157 |
+
syfox::Engine control = eng;
|
| 1158 |
+
for (const auto& t : targets) {
|
| 1159 |
+
control.learn_example(t.state, t.instructions, t.gold_outcome);
|
| 1160 |
+
control.learn_example(t.state, t.instructions, t.gold_outcome);
|
| 1161 |
+
}
|
| 1162 |
+
if (!suffix.empty())
|
| 1163 |
+
cr.untouched_acc_control = labelled_accuracy(control, suffix).accuracy;
|
| 1164 |
+
// every contradicted state must surface as contested in its evidence
|
| 1165 |
+
for (const auto& t : targets) {
|
| 1166 |
+
syfox::Usage u;
|
| 1167 |
+
sfx::JV qobj(sfx::JVObj{});
|
| 1168 |
+
qobj.obj["q"] = t.q;
|
| 1169 |
+
auto answers = probe.decide(t.state, qobj, u);
|
| 1170 |
+
sfx::JV ev = probe.evidence_json(t.state, qobj, answers);
|
| 1171 |
+
++cr.checked;
|
| 1172 |
+
if (ev.at("contested").as_str() == "true") ++cr.contested_flagged;
|
| 1173 |
+
// determinism under dispute: same decision twice
|
| 1174 |
+
syfox::Usage u2;
|
| 1175 |
+
auto answers2 = probe.decide(t.state, qobj, u2);
|
| 1176 |
+
if (answers.size() != answers2.size()) { cr.deterministic_after = false; continue; }
|
| 1177 |
+
for (std::size_t k = 0; k < answers.size(); ++k)
|
| 1178 |
+
if (answers[k].deferred != answers2[k].deferred ||
|
| 1179 |
+
std::fabs(answers[k].confidence - answers2[k].confidence) > 1e-6f ||
|
| 1180 |
+
answers[k].choice != answers2[k].choice)
|
| 1181 |
+
cr.deterministic_after = false;
|
| 1182 |
+
}
|
| 1183 |
+
// blast radius: untouched suffix after the attack (compare with CONTROL,
|
| 1184 |
+
// not just BEFORE — every teach event pays the forgetting-law cost)
|
| 1185 |
+
if (!suffix.empty())
|
| 1186 |
+
cr.untouched_acc_after = labelled_accuracy(probe, suffix).accuracy;
|
| 1187 |
+
return cr;
|
| 1188 |
+
}
|
| 1189 |
+
|
| 1190 |
+
// -- the full suite -----------------------------------------------------------
|
| 1191 |
+
inline AdvReport adversarial_suite(Engine& eng, const std::vector<sfx::JV>& rows,
|
| 1192 |
+
const std::vector<std::string>& foreign_pool) {
|
| 1193 |
+
AdvReport rep;
|
| 1194 |
+
rep.families.push_back(adv_score_family(eng,
|
| 1195 |
+
adv_transform_rows(rows, adv_reorder), "reorder",
|
| 1196 |
+
"clause halves swapped; token stream changes, gold label unchanged"));
|
| 1197 |
+
rep.families.push_back(adv_score_family(eng,
|
| 1198 |
+
adv_transform_rows(rows, adv_padding), "padding",
|
| 1199 |
+
"irrelevant clause appended; co-occurrence fabric must not be hijacked"));
|
| 1200 |
+
rep.families.push_back(adv_score_family(eng,
|
| 1201 |
+
adv_transform_rows(rows, adv_typo), "typos",
|
| 1202 |
+
"15% deterministic codepoint corruption (deletion/swap/duplication)"));
|
| 1203 |
+
rep.families.push_back(adv_score_family(eng,
|
| 1204 |
+
adv_transform_rows(rows, adv_intensifiers), "intensifiers",
|
| 1205 |
+
"content words doubled + URGENT caps; intern-mass stress"));
|
| 1206 |
+
rep.families.push_back(adv_score_family(eng,
|
| 1207 |
+
adv_transform_rows(rows, adv_self_contradiction), "self_contradiction",
|
| 1208 |
+
"opposing-sentiment clause appended; routing intent must survive"));
|
| 1209 |
+
rep.families.push_back(adv_score_family(eng,
|
| 1210 |
+
adv_transform_rows(rows, adv_negation), "negation",
|
| 1211 |
+
"single 'not' inserted; scored on choice only (valence labels may flip)"));
|
| 1212 |
+
rep.families.push_back(adv_score_family(eng,
|
| 1213 |
+
adv_transform_rows(rows, adv_double_negation), "double_negation",
|
| 1214 |
+
"double-negation clause appended; scored on choice only"));
|
| 1215 |
+
// unknown vocabulary: expect defer_rate 1.0, zero answered
|
| 1216 |
+
{
|
| 1217 |
+
auto probes = adv_unknown_probes(eng, rows);
|
| 1218 |
+
AdvFamilyResult fam = adv_score_family(eng, probes, "unknown_concepts",
|
| 1219 |
+
"true OOD nonsense vocabulary; 100% defer is the contract, any answer is false confidence");
|
| 1220 |
+
rep.families.push_back(fam);
|
| 1221 |
+
}
|
| 1222 |
+
// near-miss: trigram-entangled foreign words
|
| 1223 |
+
{
|
| 1224 |
+
auto probes = adv_nearmiss_probes(eng, rows, foreign_pool);
|
| 1225 |
+
AdvFamilyResult fam = adv_score_family(eng, probes, "near_miss",
|
| 1226 |
+
foreign_pool.empty()
|
| 1227 |
+
? "no foreign pool available (skipped)"
|
| 1228 |
+
: "one content word replaced by a trigram-entangled foreign word; tests the traction gate");
|
| 1229 |
+
rep.families.push_back(fam);
|
| 1230 |
+
}
|
| 1231 |
+
// cross-domain mixture
|
| 1232 |
+
{
|
| 1233 |
+
auto probes = adv_crossdomain_probes(rows, foreign_pool);
|
| 1234 |
+
AdvFamilyResult fam = adv_score_family(eng, probes, "cross_domain",
|
| 1235 |
+
foreign_pool.empty()
|
| 1236 |
+
? "no foreign pool available (skipped)"
|
| 1237 |
+
: "four foreign content words appended; contamination resistance");
|
| 1238 |
+
rep.families.push_back(fam);
|
| 1239 |
+
}
|
| 1240 |
+
rep.conflicts = adv_conflict_suite(eng, rows);
|
| 1241 |
+
return rep;
|
| 1242 |
+
}
|
| 1243 |
+
|
| 1244 |
+
} // namespace bench
|
| 1245 |
+
} // namespace syfox
|
engine/core/derive.hpp
ADDED
|
@@ -0,0 +1,498 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// SyFox — derive.hpp
|
| 3 |
+
// The derivation layer: knowledge the field derives from its own fabric.
|
| 4 |
+
//
|
| 5 |
+
// Lineage: SyFox-native design after studying the upstream SI stack's
|
| 6 |
+
// derivation mechanisms (meta-learner rule induction, dreamer discovery
|
| 7 |
+
// daemon, analogical mapping) as MECHANISM REFERENCE ONLY — no code copied.
|
| 8 |
+
// The primitives differ: SI composes typed relation triples over a fact
|
| 9 |
+
// graph; SyFox composes weighted lane paths over the substrate fabric,
|
| 10 |
+
// so every rule below is weight algebra, not pattern matching. The core
|
| 11 |
+
// constitution holds: no transformer, no neural network, no classifier.
|
| 12 |
+
//
|
| 13 |
+
// Three engines:
|
| 14 |
+
//
|
| 15 |
+
// 1. LANE INDUCTION (meta-learner analog)
|
| 16 |
+
// A two-hop path A->B->C is evidence for A<->C. compose_pass() turns
|
| 17 |
+
// corroborated paths into derived lanes: weight = noisy-or of path
|
| 18 |
+
// products, damped by compose_gain (derived evidence is weaker than
|
| 19 |
+
// experience). Each derived lane carries a generation counter —
|
| 20 |
+
// composition of generations >= max_generation is refused AT WRITE TIME,
|
| 21 |
+
// so a stale-rule verifier bug (an SI audit finding) cannot occur here
|
| 22 |
+
// by construction: provenance is checked, never cached as an id.
|
| 23 |
+
// prune_stale() is the use-time verifier: a derived lane must still be
|
| 24 |
+
// justified by live parent paths; over-claiming lanes are healed down
|
| 25 |
+
// to their justification, unsupported ones dissolve.
|
| 26 |
+
// Derived lanes NEVER weaken observed lanes: compose only raises.
|
| 27 |
+
//
|
| 28 |
+
// 2. DREAMER (discovery analog)
|
| 29 |
+
// Inject small random energy patterns (SyFox physics has no drive
|
| 30 |
+
// frequency — the honest adaptation of SI's random cavity drive),
|
| 31 |
+
// settle, and watch for UNDRIVEN nodes that lit up strongly WITHOUT
|
| 32 |
+
// any direct lane to the driven set: reached only through the
|
| 33 |
+
// topology's own interference. Those become candidate facts in the
|
| 34 |
+
// mutation ledger. The substrate is never modified by dreaming; a
|
| 35 |
+
// human validates a ledger line before promote() may apply it.
|
| 36 |
+
//
|
| 37 |
+
// 3. ANALOGY (structure-mapping analog)
|
| 38 |
+
// A concept's signature is its lane neighbourhood (who it touches, in
|
| 39 |
+
// which direction). Structural isomorphism = signature Jaccard; the
|
| 40 |
+
// novelty potential follows the L9 formulation Phi = I * exp(k * d):
|
| 41 |
+
// structurally aligned AND far apart on the fabric = candidate
|
| 42 |
+
// transfer. v0.2 is read-only introspection — transfers are hypotheses
|
| 43 |
+
// for the human, never auto-applied.
|
| 44 |
+
//
|
| 45 |
+
// All engines are OFFLINE, DETERMINISTIC (no RNG except the seeded dreamer)
|
| 46 |
+
// and EXPLICIT: decide() stays read-only and byte-identical unless the
|
| 47 |
+
// operator runs derive/promote on a model.
|
| 48 |
+
// ============================================================================
|
| 49 |
+
#pragma once
|
| 50 |
+
#include "si_substrate.hpp"
|
| 51 |
+
|
| 52 |
+
#include <algorithm>
|
| 53 |
+
#include <cmath>
|
| 54 |
+
#include <cstdint>
|
| 55 |
+
#include <queue>
|
| 56 |
+
#include <random>
|
| 57 |
+
#include <unordered_map>
|
| 58 |
+
#include <unordered_set>
|
| 59 |
+
#include <vector>
|
| 60 |
+
|
| 61 |
+
namespace syfox {
|
| 62 |
+
namespace derive {
|
| 63 |
+
|
| 64 |
+
// ---------------------------------------------------------------------------
|
| 65 |
+
struct DeriveConfig {
|
| 66 |
+
float path_min = 0.02f; // min parent weight to count as evidence
|
| 67 |
+
float compose_gain = 0.50f; // derived evidence is weaker than lived evidence
|
| 68 |
+
float compose_floor = 0.005f; // below this, a derived lane is not worth laying
|
| 69 |
+
std::uint32_t max_generation = 3; // derived-of-derived depth cap (verifier bound)
|
| 70 |
+
int max_paths = 3; // corroboration cap: top-K paths per pair.
|
| 71 |
+
// Dense fabrics offer hundreds of two-hop
|
| 72 |
+
// paths; treating them as independent
|
| 73 |
+
// evidence saturates the field (benchmarked:
|
| 74 |
+
// argmax flips + noul collapse). Top-K
|
| 75 |
+
// keeps derived lanes in evidence range.
|
| 76 |
+
int max_derived_per_node = 32; // creation budget per source per pass
|
| 77 |
+
|
| 78 |
+
// Gate-safe preset (see HarvestConfig::conservative for the rationale):
|
| 79 |
+
// weaker composed evidence, fewer candidates per node, stricter
|
| 80 |
+
// corroboration. Pair with the no-regression gate in gate.hpp.
|
| 81 |
+
static DeriveConfig conservative() {
|
| 82 |
+
DeriveConfig c;
|
| 83 |
+
c.compose_gain = 0.25f;
|
| 84 |
+
c.max_derived_per_node = 4;
|
| 85 |
+
c.max_paths = 2;
|
| 86 |
+
return c;
|
| 87 |
+
}
|
| 88 |
+
};
|
| 89 |
+
|
| 90 |
+
struct DeriveStats {
|
| 91 |
+
long created = 0;
|
| 92 |
+
long strengthened = 0; // derived evidence raised an existing lane
|
| 93 |
+
long healed = 0; // verifier lowered an over-claiming derived lane
|
| 94 |
+
long dissolved = 0; // verifier dissolved an unsupported derived lane
|
| 95 |
+
};
|
| 96 |
+
|
| 97 |
+
// -- 1a. LANE INDUCTION: one composition pass (two-hop) ----------------------
|
| 98 |
+
// Deterministic: nodes in id order, candidates accumulated before any write
|
| 99 |
+
// (no intra-pass cascade), floating accumulation in a fixed order.
|
| 100 |
+
inline DeriveStats compose_pass(si::Substrate& s, const DeriveConfig& c) {
|
| 101 |
+
const std::size_t N = s.node_count();
|
| 102 |
+
// adjacency snapshot with generation: a -> [(b, w, gen)]
|
| 103 |
+
std::vector<std::vector<std::pair<si::NodeId, std::pair<float, std::uint32_t>>>> adj(N);
|
| 104 |
+
s.for_each_lane([&](si::NodeId a, si::NodeId b, float w) {
|
| 105 |
+
adj[a].push_back({b, {w, s.generation_of(a, b)}});
|
| 106 |
+
});
|
| 107 |
+
|
| 108 |
+
// candidate accumulation: cand[a][i] = {c, top-K path products, gen}
|
| 109 |
+
struct Cand { si::NodeId c; std::vector<float> paths; std::uint32_t gen; };
|
| 110 |
+
std::vector<std::vector<Cand>> cand(N);
|
| 111 |
+
|
| 112 |
+
for (std::size_t a = 0; a < N; ++a) {
|
| 113 |
+
for (const auto& ab : adj[a]) {
|
| 114 |
+
if (ab.second.first < c.path_min) continue; // A->B too weak
|
| 115 |
+
const si::NodeId b = ab.first;
|
| 116 |
+
if (b >= N) continue;
|
| 117 |
+
for (const auto& bc : adj[b]) {
|
| 118 |
+
if (bc.second.first < c.path_min) continue; // B->C too weak
|
| 119 |
+
const si::NodeId cc = bc.first;
|
| 120 |
+
if (cc == a) continue; // no self-lane
|
| 121 |
+
const std::uint32_t parent_gen = std::max(ab.second.second, bc.second.second);
|
| 122 |
+
if (parent_gen >= c.max_generation) continue; // verifier bound, at write time
|
| 123 |
+
// acoustic-mass law: evidence through an intermediate is damped
|
| 124 |
+
// by 1/sqrt(mass), the same law settle() applies to energy
|
| 125 |
+
// flowing through that node. Hubs ("the", "and") therefore
|
| 126 |
+
// cannot fabricate corroboration between unrelated concepts.
|
| 127 |
+
const float damp = 1.0f / std::sqrt(std::max(1.0f, s.node_mass(b)));
|
| 128 |
+
const float evidence = ab.second.first * bc.second.first * damp;
|
| 129 |
+
Cand* slot = nullptr;
|
| 130 |
+
for (auto& k : cand[a]) if (k.c == cc) { slot = &k; break; }
|
| 131 |
+
if (!slot) {
|
| 132 |
+
cand[a].push_back({cc, {evidence}, parent_gen + 1});
|
| 133 |
+
slot = &cand[a].back();
|
| 134 |
+
} else {
|
| 135 |
+
slot->paths.push_back(evidence); // top-K corroboration
|
| 136 |
+
slot->gen = std::min(slot->gen, parent_gen + 1); // strongest provenance wins
|
| 137 |
+
}
|
| 138 |
+
if (static_cast<int>(slot->paths.size()) > c.max_paths) {
|
| 139 |
+
auto weakest = std::min_element(slot->paths.begin(), slot->paths.end());
|
| 140 |
+
slot->paths.erase(weakest); // drop the weakest path
|
| 141 |
+
}
|
| 142 |
+
}
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
DeriveStats st;
|
| 147 |
+
for (std::size_t a = 0; a < N; ++a) {
|
| 148 |
+
long budget = c.max_derived_per_node;
|
| 149 |
+
for (const auto& k : cand[a]) {
|
| 150 |
+
if (budget <= 0) break; // per-source creation budget
|
| 151 |
+
// corroboration over at most the retained top-K paths
|
| 152 |
+
float p = 1.0f;
|
| 153 |
+
for (float e : k.paths) p *= (1.0f - e);
|
| 154 |
+
p = 1.0f - p;
|
| 155 |
+
const float derived = p * c.compose_gain;
|
| 156 |
+
if (derived < c.compose_floor) continue;
|
| 157 |
+
const float existing = s.lane_weight(static_cast<si::NodeId>(a), k.c);
|
| 158 |
+
if (existing <= 0.0f) {
|
| 159 |
+
s.bind_derived(static_cast<si::NodeId>(a), k.c, derived, k.gen);
|
| 160 |
+
++st.created; --budget;
|
| 161 |
+
} else if (derived > existing) {
|
| 162 |
+
s.bind_derived(static_cast<si::NodeId>(a), k.c, derived, k.gen);
|
| 163 |
+
++st.strengthened;
|
| 164 |
+
}
|
| 165 |
+
}
|
| 166 |
+
}
|
| 167 |
+
return st;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
// -- 1b. VERIFIER: use-time re-check of every derived lane -------------------
|
| 171 |
+
// A derived lane must be justified by live parent paths under the CURRENT
|
| 172 |
+
// fabric. Over-claimed -> healed down to justification; unjustified -> gone.
|
| 173 |
+
// Observed lanes (gen 0) are premises: never questioned here.
|
| 174 |
+
inline DeriveStats prune_stale(si::Substrate& s, const DeriveConfig& c) {
|
| 175 |
+
const std::size_t N = s.node_count();
|
| 176 |
+
struct Lane { si::NodeId a, b; float w; std::uint32_t gen; };
|
| 177 |
+
std::vector<Lane> lanes;
|
| 178 |
+
s.for_each_lane([&](si::NodeId a, si::NodeId b, float w) {
|
| 179 |
+
lanes.push_back({a, b, w, s.generation_of(a, b)});
|
| 180 |
+
});
|
| 181 |
+
std::vector<std::vector<std::pair<si::NodeId, float>>> adj(N);
|
| 182 |
+
for (const auto& l : lanes) adj[l.a].push_back({l.b, l.w});
|
| 183 |
+
|
| 184 |
+
DeriveStats st;
|
| 185 |
+
for (const auto& l : lanes) {
|
| 186 |
+
if (l.gen == 0) continue; // premise: skip
|
| 187 |
+
float best_path = 0.0f;
|
| 188 |
+
for (const auto& ab : adj[l.a]) {
|
| 189 |
+
if (ab.second < c.path_min) continue;
|
| 190 |
+
// live-fabric authority: a lane dissolved/healed earlier in this
|
| 191 |
+
// pass must not justify anything through its snapshot ghost
|
| 192 |
+
if (s.lane_weight(l.a, ab.first) != ab.second) continue;
|
| 193 |
+
if (s.generation_of(l.a, ab.first) >= l.gen) continue; // parents must be senior
|
| 194 |
+
const float damp = 1.0f / std::sqrt(std::max(1.0f, s.node_mass(ab.first)));
|
| 195 |
+
for (const auto& bc : adj[ab.first]) {
|
| 196 |
+
if (bc.first != l.b || bc.second < c.path_min) continue;
|
| 197 |
+
if (s.lane_weight(ab.first, l.b) != bc.second) continue; // ghost guard
|
| 198 |
+
if (s.generation_of(ab.first, l.b) >= l.gen) continue;
|
| 199 |
+
best_path = std::max(best_path, ab.second * bc.second * damp);
|
| 200 |
+
}
|
| 201 |
+
}
|
| 202 |
+
const float justified = best_path * c.compose_gain;
|
| 203 |
+
if (best_path <= 0.0f) {
|
| 204 |
+
s.dissolve_lane(l.a, l.b);
|
| 205 |
+
++st.dissolved;
|
| 206 |
+
} else if (justified < l.w - 1e-6f) {
|
| 207 |
+
s.set_derived_weight(l.a, l.b, justified);
|
| 208 |
+
++st.healed;
|
| 209 |
+
}
|
| 210 |
+
}
|
| 211 |
+
return st;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
// Full derivation run: verify to convergence, then compose `passes` times.
|
| 215 |
+
// Each prune pass can dissolve lanes that were ghost-justifying others; the
|
| 216 |
+
// fixed-point loop makes one run() self-consistent.
|
| 217 |
+
inline DeriveStats run(si::Substrate& s, const DeriveConfig& c, int passes) {
|
| 218 |
+
DeriveStats st;
|
| 219 |
+
for (int round = 0; round < 4; ++round) {
|
| 220 |
+
DeriveStats p = prune_stale(s, c);
|
| 221 |
+
st.healed += p.healed; st.dissolved += p.dissolved;
|
| 222 |
+
if (p.healed == 0 && p.dissolved == 0) break; // fixed point
|
| 223 |
+
}
|
| 224 |
+
for (int i = 0; i < passes; ++i) {
|
| 225 |
+
DeriveStats p = compose_pass(s, c);
|
| 226 |
+
st.created += p.created; st.strengthened += p.strengthened;
|
| 227 |
+
}
|
| 228 |
+
return st;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
// -- 1c. DYNAMIC HARVEST: the field's own dynamics nominate the lanes --------
|
| 232 |
+
// Static algebra guesses; the settled field KNOWS. Replay states through
|
| 233 |
+
// inject->settle and record which concept pairs genuinely co-activate.
|
| 234 |
+
// Dissipation does the filtering: energy that crosses scenario boundaries
|
| 235 |
+
// decays before it can register, so the harvest picks up same-context
|
| 236 |
+
// bridges and skips cross-scenario noise that static products cannot see.
|
| 237 |
+
// This mirrors the upstream SI meta-learner's stance (induce from observed
|
| 238 |
+
// derivation traces, not from static structure). Deterministic: replay in
|
| 239 |
+
// file order, fixed accumulation order, weight-sorted laying.
|
| 240 |
+
struct HarvestConfig {
|
| 241 |
+
float co_floor = 0.08f; // min normalized co-activation to count
|
| 242 |
+
float gain = 0.50f; // derived evidence is weaker than lived evidence
|
| 243 |
+
int max_per_node = 16; // laying budget per node
|
| 244 |
+
int max_total = 4096; // global laying budget per harvest run
|
| 245 |
+
|
| 246 |
+
// Gate-safe preset: small fabrics co-activate across contexts structurally,
|
| 247 |
+
// so the default thresholds nominate hundreds of bridges and the field's
|
| 248 |
+
// close calls flip. The conservative preset raises the evidence bar (only
|
| 249 |
+
// strong co-activations count), dampens the write strength, and shrinks
|
| 250 |
+
// the budgets. Pair it with the no-regression gate: if even this strength
|
| 251 |
+
// flips a replayed decision, the gate reverts and the model ships as-is.
|
| 252 |
+
static HarvestConfig conservative() {
|
| 253 |
+
HarvestConfig c;
|
| 254 |
+
c.co_floor = 0.15f;
|
| 255 |
+
c.gain = 0.35f;
|
| 256 |
+
c.max_per_node = 8;
|
| 257 |
+
c.max_total = 512;
|
| 258 |
+
return c;
|
| 259 |
+
}
|
| 260 |
+
};
|
| 261 |
+
|
| 262 |
+
struct HarvestStats { long created = 0, refreshed = 0, dissolved = 0; };
|
| 263 |
+
|
| 264 |
+
inline HarvestStats harvest(si::Substrate& s,
|
| 265 |
+
const std::vector<std::vector<std::string>>& replay_states,
|
| 266 |
+
const HarvestConfig& hc) {
|
| 267 |
+
const std::size_t N = s.node_count();
|
| 268 |
+
HarvestStats st;
|
| 269 |
+
if (N == 0 || replay_states.empty()) return st;
|
| 270 |
+
|
| 271 |
+
// undirected pair key
|
| 272 |
+
const auto pair_key = [](si::NodeId x, si::NodeId y) {
|
| 273 |
+
return (static_cast<std::uint64_t>(std::min(x, y)) << 32) | static_cast<std::uint32_t>(std::max(x, y));
|
| 274 |
+
};
|
| 275 |
+
|
| 276 |
+
std::unordered_map<std::uint64_t, float> acc;
|
| 277 |
+
for (const auto& toks : replay_states) {
|
| 278 |
+
s.reset_field();
|
| 279 |
+
s.inject(toks);
|
| 280 |
+
s.settle();
|
| 281 |
+
std::vector<si::NodeId> act;
|
| 282 |
+
for (std::size_t i = 0; i < N; ++i)
|
| 283 |
+
if (s.node_energy(static_cast<si::NodeId>(i)) > 1e-4f) act.push_back(static_cast<si::NodeId>(i));
|
| 284 |
+
for (std::size_t i = 0; i < act.size(); ++i)
|
| 285 |
+
for (std::size_t j = i + 1; j < act.size(); ++j) {
|
| 286 |
+
const float w = std::min(s.node_energy(act[i]), s.node_energy(act[j]));
|
| 287 |
+
if (w <= 0.0f) continue;
|
| 288 |
+
acc[pair_key(act[i], act[j])] += w;
|
| 289 |
+
}
|
| 290 |
+
}
|
| 291 |
+
float mx = 0.0f;
|
| 292 |
+
for (const auto& kv : acc) mx = std::max(mx, kv.second);
|
| 293 |
+
if (mx <= 0.0f) return st;
|
| 294 |
+
|
| 295 |
+
// verifier: a gen>=1 lane must be re-nominated by the CURRENT replay
|
| 296 |
+
std::unordered_set<std::uint64_t> supported;
|
| 297 |
+
for (const auto& kv : acc)
|
| 298 |
+
if (kv.second / mx >= hc.co_floor) supported.insert(kv.first);
|
| 299 |
+
std::vector<std::pair<si::NodeId, si::NodeId>> stale;
|
| 300 |
+
s.for_each_lane([&](si::NodeId a, si::NodeId b, float) {
|
| 301 |
+
if (s.generation_of(a, b) >= 1 && !supported.count(pair_key(a, b)))
|
| 302 |
+
stale.push_back({a, b});
|
| 303 |
+
});
|
| 304 |
+
std::sort(stale.begin(), stale.end());
|
| 305 |
+
for (const auto& p : stale) {
|
| 306 |
+
if (s.lane_weight(p.first, p.second) <= 0.0f) continue; // mirror already gone
|
| 307 |
+
s.dissolve_lane(p.first, p.second);
|
| 308 |
+
++st.dissolved;
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
// lay in weight order (deterministic), honoring budgets
|
| 312 |
+
std::vector<std::pair<std::uint64_t, float>> ranked(acc.begin(), acc.end());
|
| 313 |
+
std::sort(ranked.begin(), ranked.end(),
|
| 314 |
+
[](const auto& x, const auto& y) { return x.second > y.second; });
|
| 315 |
+
std::unordered_map<si::NodeId, int> per_node;
|
| 316 |
+
long laid = 0;
|
| 317 |
+
for (const auto& kv : ranked) {
|
| 318 |
+
if (laid >= hc.max_total) break;
|
| 319 |
+
const float co = kv.second / mx;
|
| 320 |
+
if (co < hc.co_floor) break; // sorted: rest is weaker
|
| 321 |
+
const si::NodeId a = static_cast<si::NodeId>(kv.first >> 32);
|
| 322 |
+
const si::NodeId b = static_cast<si::NodeId>(kv.first & 0xffffffffull);
|
| 323 |
+
if (per_node[a] >= hc.max_per_node || per_node[b] >= hc.max_per_node) continue;
|
| 324 |
+
const float derived = co * hc.gain;
|
| 325 |
+
const float existing = s.lane_weight(a, b);
|
| 326 |
+
if (existing > 0.0f && s.generation_of(a, b) == 0) continue; // observed lane: experience outranks derivation, never touched
|
| 327 |
+
if (existing <= 0.0f) {
|
| 328 |
+
s.bind_derived(a, b, derived, 1);
|
| 329 |
+
++st.created; ++laid;
|
| 330 |
+
} else if (derived > existing) {
|
| 331 |
+
s.bind_derived(a, b, derived, 1);
|
| 332 |
+
++st.refreshed;
|
| 333 |
+
} else {
|
| 334 |
+
++st.refreshed; // re-nominated, current weight stands
|
| 335 |
+
}
|
| 336 |
+
++per_node[a]; ++per_node[b];
|
| 337 |
+
}
|
| 338 |
+
return st;
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
// ---------------------------------------------------------------------------
|
| 342 |
+
// -- 2. DREAMER --------------------------------------------------------------
|
| 343 |
+
struct DreamConfig {
|
| 344 |
+
float e_min = 0.6f; // per-driven-node energy range (drive-amp analog)
|
| 345 |
+
float e_max = 1.5f;
|
| 346 |
+
float support_floor = 0.02f; // emergent share of total settled energy
|
| 347 |
+
int min_cluster = 2; // >= N independent co-vibrators (interference signature)
|
| 348 |
+
int max_per_step = 8; // record at most this many emergent nodes per step
|
| 349 |
+
int drive_nodes_max = 3; // 1..3 random driven nodes per dream step
|
| 350 |
+
};
|
| 351 |
+
|
| 352 |
+
struct DreamCandidate {
|
| 353 |
+
std::vector<si::NodeId> driven;
|
| 354 |
+
si::NodeId emergent;
|
| 355 |
+
float support; // emergent_energy / total_settled_energy
|
| 356 |
+
};
|
| 357 |
+
|
| 358 |
+
inline std::vector<DreamCandidate> dream(si::Substrate& s, const DreamConfig& dc,
|
| 359 |
+
std::uint64_t seed, int steps) {
|
| 360 |
+
std::mt19937 rng(static_cast<std::uint32_t>(seed));
|
| 361 |
+
std::uniform_real_distribution<float> energy_dist(dc.e_min, dc.e_max);
|
| 362 |
+
std::vector<DreamCandidate> out;
|
| 363 |
+
const std::size_t N = s.node_count();
|
| 364 |
+
if (N == 0 || steps <= 0) return out;
|
| 365 |
+
|
| 366 |
+
for (int step = 0; step < steps; ++step) {
|
| 367 |
+
s.reset_field();
|
| 368 |
+
// pick 1..drive_nodes_max distinct driven nodes (deterministic per seed)
|
| 369 |
+
const int k = std::min<std::size_t>(
|
| 370 |
+
1 + static_cast<std::size_t>(rng() % static_cast<std::uint32_t>(dc.drive_nodes_max)), N);
|
| 371 |
+
std::vector<si::NodeId> order(N);
|
| 372 |
+
for (std::size_t i = 0; i < N; ++i) order[i] = static_cast<si::NodeId>(i);
|
| 373 |
+
for (int i = 0; i < k; ++i) { // partial Fisher-Yates
|
| 374 |
+
const std::size_t j = i + static_cast<std::size_t>(rng() % static_cast<std::uint32_t>(N - i));
|
| 375 |
+
std::swap(order[i], order[j]);
|
| 376 |
+
}
|
| 377 |
+
std::vector<si::NodeId> driven(order.begin(), order.begin() + k);
|
| 378 |
+
for (si::NodeId id : driven) s.inject_energy(id, energy_dist(rng));
|
| 379 |
+
s.settle();
|
| 380 |
+
const float total = s.total_energy();
|
| 381 |
+
if (total <= 0.0f) continue;
|
| 382 |
+
|
| 383 |
+
// the driven set and its DIRECT lane neighbourhood are not emergent
|
| 384 |
+
std::unordered_set<si::NodeId> excluded(driven.begin(), driven.end());
|
| 385 |
+
for (si::NodeId id : driven) {
|
| 386 |
+
std::vector<std::pair<si::NodeId, float>> lanes;
|
| 387 |
+
s.lanes_of(id, lanes);
|
| 388 |
+
for (const auto& l : lanes) excluded.insert(l.first);
|
| 389 |
+
}
|
| 390 |
+
// emergent: bright, untouched by direct lanes — pure topology reach
|
| 391 |
+
std::vector<si::NodeId> emergent;
|
| 392 |
+
for (std::size_t i = 0; i < N && static_cast<int>(emergent.size()) < dc.max_per_step; ++i) {
|
| 393 |
+
if (excluded.count(static_cast<si::NodeId>(i))) continue;
|
| 394 |
+
if (s.readout_neighbours(static_cast<si::NodeId>(i)) == 0) continue; // isolated node: trivially dark
|
| 395 |
+
if (s.node_energy(static_cast<si::NodeId>(i)) / total >= dc.support_floor)
|
| 396 |
+
emergent.push_back(static_cast<si::NodeId>(i));
|
| 397 |
+
}
|
| 398 |
+
if (static_cast<int>(emergent.size()) < dc.min_cluster) continue;
|
| 399 |
+
for (si::NodeId id : emergent)
|
| 400 |
+
out.push_back({driven, id, s.node_energy(id) / total});
|
| 401 |
+
}
|
| 402 |
+
return out;
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
// ---------------------------------------------------------------------------
|
| 406 |
+
// -- 3. ANALOGY (read-only) ---------------------------------------------------
|
| 407 |
+
struct AnalogueMatch {
|
| 408 |
+
std::string concept;
|
| 409 |
+
float iso; // structural isomorphism in [0,1]
|
| 410 |
+
int hops; // fabric distance (cap 24; -1 -> treated far)
|
| 411 |
+
float phi; // novelty potential I * exp(k * d)
|
| 412 |
+
};
|
| 413 |
+
|
| 414 |
+
inline std::vector<AnalogueMatch> find_analogues(const si::Substrate& s,
|
| 415 |
+
const std::string& source,
|
| 416 |
+
int top_k = 8,
|
| 417 |
+
float min_iso = 0.10f,
|
| 418 |
+
float k = 0.15f) {
|
| 419 |
+
const std::size_t N = s.node_count();
|
| 420 |
+
std::vector<AnalogueMatch> out;
|
| 421 |
+
if (N == 0 || !s.has(source)) return out;
|
| 422 |
+
const si::NodeId A = s.find(source);
|
| 423 |
+
|
| 424 |
+
// signatures: sorted (direction, other_concept) multisets, both directions
|
| 425 |
+
std::vector<std::vector<std::pair<int, std::string>>> sig(N);
|
| 426 |
+
s.for_each_lane([&](si::NodeId a, si::NodeId b, float) {
|
| 427 |
+
if (b < N) sig[a].push_back({0, s.concept_of(b)});
|
| 428 |
+
if (a < N) sig[b].push_back({1, s.concept_of(a)});
|
| 429 |
+
});
|
| 430 |
+
for (auto& v : sig) std::sort(v.begin(), v.end());
|
| 431 |
+
|
| 432 |
+
const auto iso_of = [](const std::vector<std::pair<int, std::string>>& x,
|
| 433 |
+
const std::vector<std::pair<int, std::string>>& y) {
|
| 434 |
+
if (x.empty() && y.empty()) return 0.0f;
|
| 435 |
+
std::size_t i = 0, j = 0, inter = 0;
|
| 436 |
+
while (i < x.size() && j < y.size()) {
|
| 437 |
+
if (x[i] == y[j]) { ++inter; ++i; ++j; }
|
| 438 |
+
else if (x[i] < y[j]) ++i;
|
| 439 |
+
else ++j;
|
| 440 |
+
}
|
| 441 |
+
const std::size_t uni = x.size() + y.size() - inter;
|
| 442 |
+
return uni ? static_cast<float>(inter) / static_cast<float>(uni) : 0.0f;
|
| 443 |
+
};
|
| 444 |
+
|
| 445 |
+
// BFS hop distance (both directions), cap 24
|
| 446 |
+
const auto hop_distance = [&](si::NodeId from, si::NodeId to) {
|
| 447 |
+
if (from == to) return 0;
|
| 448 |
+
std::vector<int> depth(N, -1);
|
| 449 |
+
std::queue<si::NodeId> q;
|
| 450 |
+
depth[from] = 0; q.push(from);
|
| 451 |
+
while (!q.empty()) {
|
| 452 |
+
si::NodeId u = q.front(); q.pop();
|
| 453 |
+
if (depth[u] >= 24) continue;
|
| 454 |
+
std::vector<std::pair<si::NodeId, float>> lanes;
|
| 455 |
+
s.lanes_of(u, lanes);
|
| 456 |
+
for (const auto& l : lanes) {
|
| 457 |
+
if (depth[l.first] >= 0) continue;
|
| 458 |
+
depth[l.first] = depth[u] + 1;
|
| 459 |
+
if (l.first == to) return depth[l.first];
|
| 460 |
+
q.push(l.first);
|
| 461 |
+
}
|
| 462 |
+
}
|
| 463 |
+
return -1;
|
| 464 |
+
};
|
| 465 |
+
|
| 466 |
+
for (std::size_t b = 0; b < N; ++b) {
|
| 467 |
+
if (static_cast<si::NodeId>(b) == A || sig[b].empty()) continue;
|
| 468 |
+
const float iso = iso_of(sig[A], sig[b]);
|
| 469 |
+
if (iso < min_iso) continue;
|
| 470 |
+
const int d = hop_distance(A, static_cast<si::NodeId>(b));
|
| 471 |
+
const float d_eff = (d < 0 ? 24.0f : static_cast<float>(d));
|
| 472 |
+
out.push_back({s.concept_of(static_cast<si::NodeId>(b)), iso, d, iso * std::exp(k * d_eff)});
|
| 473 |
+
}
|
| 474 |
+
std::sort(out.begin(), out.end(), [](const AnalogueMatch& x, const AnalogueMatch& y) {
|
| 475 |
+
return x.phi > y.phi;
|
| 476 |
+
});
|
| 477 |
+
if (static_cast<int>(out.size()) > top_k) out.resize(static_cast<std::size_t>(top_k));
|
| 478 |
+
return out;
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
// ---------------------------------------------------------------------------
|
| 482 |
+
// -- PROMOTION (human-validated dream candidates -> premise-grade lanes) -----
|
| 483 |
+
// The ledger line must have been validated by a human (CLI enforces the flag);
|
| 484 |
+
// promoted lanes are ordinary Hebbian lanes (generation 0, symmetric, subject
|
| 485 |
+
// to lane decay) — they are experience once a human has vouched for them.
|
| 486 |
+
inline void apply_promotion(si::Substrate& s,
|
| 487 |
+
const std::vector<std::string>& driven_concepts,
|
| 488 |
+
const std::string& emergent_concept,
|
| 489 |
+
float support, float promote_gain) {
|
| 490 |
+
for (const auto& d : driven_concepts) {
|
| 491 |
+
if (!s.has(d) || !s.has(emergent_concept)) continue;
|
| 492 |
+
const float w = std::min(1.5f, std::max(0.05f, support * promote_gain));
|
| 493 |
+
s.bind(s.find(d), s.find(emergent_concept), w);
|
| 494 |
+
}
|
| 495 |
+
}
|
| 496 |
+
|
| 497 |
+
} // namespace derive
|
| 498 |
+
} // namespace syfox
|
engine/core/firewall.hpp
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// SyFox — firewall.hpp (Milestone 1: the hidden-test contract, in code)
|
| 3 |
+
// ---------------------------------------------------------------------------
|
| 4 |
+
// Milestone-1 discipline: every generated corpus splits 70/15/15 into
|
| 5 |
+
// train / calibration / hidden test, and the hidden test NEVER participates
|
| 6 |
+
// in training, calibration, derivation, or model selection. That contract
|
| 7 |
+
// is easy to state in a README and easier to break by typo, so it is
|
| 8 |
+
// ENFORCED here: the split a file belongs to is decided by its filename
|
| 9 |
+
// (the same <domain>_<split>.jsonl convention split_data.py and the CLI
|
| 10 |
+
// already use), and the learn / calibrate / derive commands consult this
|
| 11 |
+
// table before reading anything.
|
| 12 |
+
//
|
| 13 |
+
// role filename suffix learn calibrate derive --gate bench
|
| 14 |
+
// train _train.jsonl YES yes yes yes
|
| 15 |
+
// heldout _heldout.jsonl yes YES (v2.1 yes yes
|
| 16 |
+
// recipe)
|
| 17 |
+
// cal _cal.jsonl no YES yes yes
|
| 18 |
+
// hidden _hidden.jsonl NO NO NO YES
|
| 19 |
+
// unknown anything else yes yes yes yes
|
| 20 |
+
// (worksheets, paraphrase files, deferral logs, memories)
|
| 21 |
+
//
|
| 22 |
+
// Rationale: calibration files exist to fit 2-3 scalars (temperature /
|
| 23 |
+
// Platt) on rows the fabric never learned from. Hidden files exist to be
|
| 24 |
+
// SCORED, once, by bench. A hidden row that leaks into any build path is
|
| 25 |
+
// not a mistake, it is a different (and worthless) number.
|
| 26 |
+
// Zero dependencies. Deterministic. C++17.
|
| 27 |
+
// ============================================================================
|
| 28 |
+
#pragma once
|
| 29 |
+
#include <string>
|
| 30 |
+
|
| 31 |
+
namespace syfox {
|
| 32 |
+
namespace firewall {
|
| 33 |
+
|
| 34 |
+
enum class Role { Train, Heldout, Cal, Hidden, Unknown };
|
| 35 |
+
|
| 36 |
+
inline Role role_of_path(const std::string& path) {
|
| 37 |
+
// basename only: the split lives in the filename, not the directory
|
| 38 |
+
std::string base = path;
|
| 39 |
+
const auto slash = base.find_last_of('/');
|
| 40 |
+
if (slash != std::string::npos) base = base.substr(slash + 1);
|
| 41 |
+
auto ends_with = [&base](const char* suffix) {
|
| 42 |
+
const std::size_t n = std::char_traits<char>::length(suffix);
|
| 43 |
+
return base.size() >= n && base.compare(base.size() - n, n, suffix) == 0;
|
| 44 |
+
};
|
| 45 |
+
if (ends_with("_hidden.jsonl")) return Role::Hidden;
|
| 46 |
+
if (ends_with("_cal.jsonl")) return Role::Cal;
|
| 47 |
+
if (ends_with("_heldout.jsonl")) return Role::Heldout;
|
| 48 |
+
if (ends_with("_train.jsonl")) return Role::Train;
|
| 49 |
+
return Role::Unknown;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
inline const char* role_name(Role r) {
|
| 53 |
+
switch (r) {
|
| 54 |
+
case Role::Train: return "train";
|
| 55 |
+
case Role::Heldout: return "heldout";
|
| 56 |
+
case Role::Cal: return "calibration";
|
| 57 |
+
case Role::Hidden: return "hidden";
|
| 58 |
+
default: return "unknown";
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
// syfox learn: train rows and legacy heldout rows and anything unclassified
|
| 63 |
+
// (paraphrase files, labeling worksheets). NOT calibration, NEVER hidden.
|
| 64 |
+
inline bool learn_may_read(const std::string& path) {
|
| 65 |
+
const Role r = role_of_path(path);
|
| 66 |
+
return r != Role::Hidden && r != Role::Cal;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
// syfox calibrate: anything except the hidden test. The v2.1 recipe fits on
|
| 70 |
+
// the held-out split; the v3 recipe fits on the dedicated _cal split.
|
| 71 |
+
inline bool calibrate_may_read(const std::string& path) {
|
| 72 |
+
return role_of_path(path) != Role::Hidden;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
// derive --gate: the no-regression gate replays eval rows. Hidden rows must
|
| 76 |
+
// not steer derivation (model selection), so they are refused here too.
|
| 77 |
+
inline bool derive_gate_may_read(const std::string& path) {
|
| 78 |
+
return role_of_path(path) != Role::Hidden;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
} // namespace firewall
|
| 82 |
+
} // namespace syfox
|
engine/core/gate.hpp
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// SyFox — gate.hpp
|
| 3 |
+
// The no-regression gate: transactional derivation.
|
| 4 |
+
//
|
| 5 |
+
// The v0.1 honest verdict (ARCHITECTURE §10) was: derive sharpens
|
| 6 |
+
// well-separated domains but FLIPS close-call scenarios on small fabrics,
|
| 7 |
+
// so seed models shipped un-derived and adoption waited on an eval harness.
|
| 8 |
+
// This file IS that harness, promoted into the mechanism itself:
|
| 9 |
+
//
|
| 10 |
+
// 1. replay every gate row + generated close-call probes -> baseline
|
| 11 |
+
// 2. snapshot the lane fabric (order-preserving, bit-exact)
|
| 12 |
+
// 3. run the derivation (compose or harvest)
|
| 13 |
+
// 4. replay the same probe set -> after
|
| 14 |
+
// 5. any argmax flip (or deferral change) => restore the snapshot
|
| 15 |
+
//
|
| 16 |
+
// After a gate run the invariant holds in BOTH branches:
|
| 17 |
+
// committed => the fabric changed, and no replayed decision flipped
|
| 18 |
+
// reverted => the fabric is bit-identical, decide() is byte-identical
|
| 19 |
+
//
|
| 20 |
+
// The gate is the substrate's own honest silence, lifted one level: "the
|
| 21 |
+
// field does not write into stone what it cannot prove harmless."
|
| 22 |
+
// ============================================================================
|
| 23 |
+
#pragma once
|
| 24 |
+
#include "syfox.hpp"
|
| 25 |
+
#include "derive.hpp"
|
| 26 |
+
#include "bench.hpp"
|
| 27 |
+
|
| 28 |
+
#include <cmath>
|
| 29 |
+
#include <string>
|
| 30 |
+
#include <vector>
|
| 31 |
+
|
| 32 |
+
namespace syfox {
|
| 33 |
+
namespace gate {
|
| 34 |
+
|
| 35 |
+
struct GateConfig {
|
| 36 |
+
int max_probes = 64; // cap on generated close-call probes
|
| 37 |
+
long allowed_flips = 0; // policy: zero tolerance by default
|
| 38 |
+
};
|
| 39 |
+
|
| 40 |
+
struct GateReport {
|
| 41 |
+
bool ran = false;
|
| 42 |
+
bool committed = false;
|
| 43 |
+
long taught_probes = 0;
|
| 44 |
+
long mixed_probes = 0;
|
| 45 |
+
long taught_flips = 0;
|
| 46 |
+
long mixed_flips = 0; // informational: ambiguous states may re-resolve
|
| 47 |
+
bool conf_inflated = false; // mixed-state mean confidence rose => false certainty
|
| 48 |
+
long changed = 0; // lanes created/strengthened by the derivation
|
| 49 |
+
long removed = 0; // lanes healed/dissolved by the derivation
|
| 50 |
+
double mean_abs_dconf = 0.0; // mean |delta confidence| over non-flipped (taught)
|
| 51 |
+
double mean_conf_mixed_before = 0.0;
|
| 52 |
+
double mean_conf_mixed_after = 0.0;
|
| 53 |
+
std::vector<std::string> flip_examples; // up to 5, "qid: A -> B"
|
| 54 |
+
|
| 55 |
+
sfx::JV to_json() const {
|
| 56 |
+
const auto r4 = [](double v) { return std::round(v * 10000.0) / 10000.0; };
|
| 57 |
+
sfx::JVArr ex;
|
| 58 |
+
for (const auto& e : flip_examples) ex.push_back(sfx::JV(e));
|
| 59 |
+
return sfx::JV(sfx::JVObj{
|
| 60 |
+
{"ran", sfx::JV(ran)},
|
| 61 |
+
{"committed", sfx::JV(committed)},
|
| 62 |
+
{"taught_probes", static_cast<double>(taught_probes)},
|
| 63 |
+
{"mixed_probes", static_cast<double>(mixed_probes)},
|
| 64 |
+
{"taught_flips", static_cast<double>(taught_flips)},
|
| 65 |
+
{"mixed_flips", static_cast<double>(mixed_flips)},
|
| 66 |
+
{"conf_inflated", sfx::JV(conf_inflated)},
|
| 67 |
+
{"mean_conf_mixed_before", r4(mean_conf_mixed_before)},
|
| 68 |
+
{"mean_conf_mixed_after", r4(mean_conf_mixed_after)},
|
| 69 |
+
{"mean_abs_dconf", r4(mean_abs_dconf)},
|
| 70 |
+
{"flip_examples", sfx::JV(ex)}});
|
| 71 |
+
}
|
| 72 |
+
};
|
| 73 |
+
|
| 74 |
+
namespace detail {
|
| 75 |
+
|
| 76 |
+
// one probe signature: qid -> (argmax or "" when deferred, confidence)
|
| 77 |
+
using Sig = std::map<std::string, std::pair<std::string, float>>;
|
| 78 |
+
|
| 79 |
+
inline long count_flips(const Sig& before, const Sig& after,
|
| 80 |
+
long& flips, double& dconf_sum, long& dconf_n,
|
| 81 |
+
std::vector<std::string>& examples,
|
| 82 |
+
const std::string& state_head) {
|
| 83 |
+
long f = 0;
|
| 84 |
+
for (const auto& kv : before) {
|
| 85 |
+
auto it = after.find(kv.first);
|
| 86 |
+
if (it == after.end()) continue;
|
| 87 |
+
const bool was_deferred = kv.second.first.empty();
|
| 88 |
+
const bool now_deferred = it->second.first.empty();
|
| 89 |
+
if (was_deferred != now_deferred || kv.second.first != it->second.first) {
|
| 90 |
+
++f;
|
| 91 |
+
if (static_cast<long>(examples.size()) < 5) {
|
| 92 |
+
examples.push_back(state_head + " | " + kv.first + ": "
|
| 93 |
+
+ (was_deferred ? std::string("(deferred)") : kv.second.first)
|
| 94 |
+
+ " -> "
|
| 95 |
+
+ (now_deferred ? std::string("(deferred)") : it->second.first));
|
| 96 |
+
}
|
| 97 |
+
} else if (!was_deferred) {
|
| 98 |
+
dconf_sum += std::fabs(static_cast<double>(kv.second.second) -
|
| 99 |
+
static_cast<double>(it->second.second));
|
| 100 |
+
++dconf_n;
|
| 101 |
+
}
|
| 102 |
+
}
|
| 103 |
+
flips += f;
|
| 104 |
+
return f;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
} // namespace detail
|
| 108 |
+
|
| 109 |
+
// Run a derivation under the gate. `mode` is "compose" or "harvest".
|
| 110 |
+
// `gate_rows` are labelled eval rows (taught states + close-call generator
|
| 111 |
+
// input). `harvest_replay` are the tokenized states the harvest mode replays
|
| 112 |
+
// (usually the gate rows' states). Derivation configs are caller-chosen; the
|
| 113 |
+
// conservative presets in derive.hpp are the recommended starting point.
|
| 114 |
+
// Returns the report; the CALLER saves the model only when report.committed
|
| 115 |
+
// is true.
|
| 116 |
+
inline GateReport gated_derive(Engine& eng, const std::string& mode,
|
| 117 |
+
const std::vector<sfx::JV>& gate_rows,
|
| 118 |
+
const std::vector<std::vector<std::string>>& harvest_replay,
|
| 119 |
+
const GateConfig& gc = {},
|
| 120 |
+
const derive::HarvestConfig& hc = derive::HarvestConfig{},
|
| 121 |
+
const derive::DeriveConfig& dc = derive::DeriveConfig{}) {
|
| 122 |
+
GateReport rep;
|
| 123 |
+
rep.ran = true;
|
| 124 |
+
|
| 125 |
+
// -- 1. probe plan: taught rows + generated close-call states -------------
|
| 126 |
+
std::vector<bench::Probe> probes = bench::eval_probes(gate_rows);
|
| 127 |
+
rep.taught_probes = static_cast<long>(probes.size());
|
| 128 |
+
const std::vector<bench::Probe> mixed = bench::closecall_probes(gate_rows, gc.max_probes);
|
| 129 |
+
rep.mixed_probes = static_cast<long>(mixed.size());
|
| 130 |
+
probes.insert(probes.end(), mixed.begin(), mixed.end());
|
| 131 |
+
if (probes.empty()) return rep; // nothing to protect
|
| 132 |
+
|
| 133 |
+
// -- 2. baseline signatures ------------------------------------------------
|
| 134 |
+
std::vector<detail::Sig> before;
|
| 135 |
+
before.reserve(probes.size());
|
| 136 |
+
for (const auto& p : probes) before.push_back(bench::decision_signature(eng, p));
|
| 137 |
+
|
| 138 |
+
// -- 3. snapshot + derive ----------------------------------------------------
|
| 139 |
+
const si::Substrate::FabricSnapshot snap = eng.substrate().snapshot_fabric();
|
| 140 |
+
long changed = 0, removed = 0;
|
| 141 |
+
if (mode == "harvest") {
|
| 142 |
+
const derive::HarvestStats st = derive::harvest(eng.substrate(), harvest_replay, hc);
|
| 143 |
+
changed = st.created + st.refreshed;
|
| 144 |
+
removed = st.dissolved;
|
| 145 |
+
} else {
|
| 146 |
+
const derive::DeriveStats st = derive::run(eng.substrate(), dc, 2);
|
| 147 |
+
changed = st.created + st.strengthened;
|
| 148 |
+
removed = st.healed + st.dissolved;
|
| 149 |
+
}
|
| 150 |
+
rep.changed = changed;
|
| 151 |
+
rep.removed = removed;
|
| 152 |
+
|
| 153 |
+
// -- 4. after signatures + flip count ---------------------------------------
|
| 154 |
+
// Policy (v0.2, refined by the strength-scan experiments):
|
| 155 |
+
// * TAUGHT rows are labelled knowledge: ANY argmax flip is a regression.
|
| 156 |
+
// * MIXED close-call probes are ambiguous BY CONSTRUCTION (two different
|
| 157 |
+
// domains concatenated) — their argmax may re-resolve either way, but
|
| 158 |
+
// derivation must not manufacture certainty about them: if the mixed
|
| 159 |
+
// mean confidence RISES, the fabric is feigning sureness => revert.
|
| 160 |
+
long taught_flips = 0, mixed_flips = 0;
|
| 161 |
+
double dconf_sum = 0.0; long dconf_n = 0;
|
| 162 |
+
double mixed_conf_before = 0.0, mixed_conf_after = 0.0;
|
| 163 |
+
long mixed_conf_n = 0;
|
| 164 |
+
for (std::size_t i = 0; i < probes.size(); ++i) {
|
| 165 |
+
const bool is_mixed = i >= static_cast<std::size_t>(rep.taught_probes);
|
| 166 |
+
const detail::Sig after = bench::decision_signature(eng, probes[i]);
|
| 167 |
+
// mixed-state confidence accounting (non-deferred entries)
|
| 168 |
+
if (is_mixed) {
|
| 169 |
+
for (const auto& kv : before[i]) {
|
| 170 |
+
auto it = after.find(kv.first);
|
| 171 |
+
if (it == after.end()) continue;
|
| 172 |
+
if (kv.second.first.empty() || it->second.first.empty()) continue;
|
| 173 |
+
mixed_conf_before += kv.second.second;
|
| 174 |
+
mixed_conf_after += it->second.second;
|
| 175 |
+
++mixed_conf_n;
|
| 176 |
+
}
|
| 177 |
+
}
|
| 178 |
+
const long f = detail::count_flips(before[i], after,
|
| 179 |
+
is_mixed ? mixed_flips : taught_flips,
|
| 180 |
+
dconf_sum, dconf_n, rep.flip_examples,
|
| 181 |
+
probes[i].state.substr(0, 40));
|
| 182 |
+
(void)f;
|
| 183 |
+
}
|
| 184 |
+
rep.taught_flips = taught_flips;
|
| 185 |
+
rep.mixed_flips = mixed_flips;
|
| 186 |
+
if (mixed_conf_n > 0) {
|
| 187 |
+
rep.mean_conf_mixed_before = mixed_conf_before / mixed_conf_n;
|
| 188 |
+
rep.mean_conf_mixed_after = mixed_conf_after / mixed_conf_n;
|
| 189 |
+
}
|
| 190 |
+
if (dconf_n > 0) rep.mean_abs_dconf = dconf_sum / dconf_n;
|
| 191 |
+
rep.conf_inflated = mixed_conf_n > 0 &&
|
| 192 |
+
rep.mean_conf_mixed_after > rep.mean_conf_mixed_before + 1e-6;
|
| 193 |
+
|
| 194 |
+
// -- 5. commit or revert -----------------------------------------------------
|
| 195 |
+
if (taught_flips > gc.allowed_flips || rep.conf_inflated) {
|
| 196 |
+
eng.substrate().restore_fabric(snap);
|
| 197 |
+
rep.committed = false;
|
| 198 |
+
} else {
|
| 199 |
+
rep.committed = true;
|
| 200 |
+
}
|
| 201 |
+
return rep;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
} // namespace gate
|
| 205 |
+
} //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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// SyFox — json.hpp
|
| 3 |
+
// Minimal dependency-free JSON parser/serializer (a TOOL, not core physics).
|
| 4 |
+
// Supports: null, bool, number, string (with escapes), array, object.
|
| 5 |
+
// C++17, deterministic, no exceptions on well-formed input (throws
|
| 6 |
+
// std::runtime_error with position on malformed input).
|
| 7 |
+
// ============================================================================
|
| 8 |
+
#pragma once
|
| 9 |
+
#include <cmath>
|
| 10 |
+
#include <cstdio>
|
| 11 |
+
#include <map>
|
| 12 |
+
#include <stdexcept>
|
| 13 |
+
#include <string>
|
| 14 |
+
#include <utility>
|
| 15 |
+
#include <vector>
|
| 16 |
+
|
| 17 |
+
namespace sfx {
|
| 18 |
+
|
| 19 |
+
struct JV;
|
| 20 |
+
using JVArr = std::vector<JV>;
|
| 21 |
+
using JVObj = std::map<std::string, JV>;
|
| 22 |
+
|
| 23 |
+
struct JV {
|
| 24 |
+
enum Type { NUL, BOOL, NUM, STR, ARR, OBJ };
|
| 25 |
+
Type t = NUL;
|
| 26 |
+
bool b = false;
|
| 27 |
+
double num = 0.0;
|
| 28 |
+
std::string str;
|
| 29 |
+
JVArr arr;
|
| 30 |
+
JVObj obj;
|
| 31 |
+
|
| 32 |
+
JV() = default;
|
| 33 |
+
JV(std::nullptr_t) : t(NUL) {}
|
| 34 |
+
JV(bool v) : t(BOOL), b(v) {}
|
| 35 |
+
JV(double v) : t(NUM), num(v) {}
|
| 36 |
+
JV(int v) : t(NUM), num(v) {}
|
| 37 |
+
JV(const char* v) : t(STR), str(v) {}
|
| 38 |
+
JV(std::string v) : t(STR), str(std::move(v)) {}
|
| 39 |
+
JV(JVArr v) : t(ARR), arr(std::move(v)) {}
|
| 40 |
+
JV(JVObj v) : t(OBJ), obj(std::move(v)) {}
|
| 41 |
+
|
| 42 |
+
bool is_null() const { return t == NUL; }
|
| 43 |
+
bool is_bool() const { return t == BOOL; }
|
| 44 |
+
bool is_num() const { return t == NUM; }
|
| 45 |
+
bool is_str() const { return t == STR; }
|
| 46 |
+
bool is_arr() const { return t == ARR; }
|
| 47 |
+
bool is_obj() const { return t == OBJ; }
|
| 48 |
+
|
| 49 |
+
bool has(const std::string& k) const { return t == OBJ && obj.count(k) != 0; }
|
| 50 |
+
const JV& at(const std::string& k) const {
|
| 51 |
+
if (t != OBJ || obj.count(k) == 0) { static const JV nil; return nil; }
|
| 52 |
+
return obj.at(k);
|
| 53 |
+
}
|
| 54 |
+
// tolerant string reader: numbers and bools stringify too
|
| 55 |
+
std::string as_str(const std::string& fallback = "") const {
|
| 56 |
+
switch (t) {
|
| 57 |
+
case STR: return str;
|
| 58 |
+
case NUM: { char buf[32]; std::snprintf(buf, sizeof(buf), "%.6g", num); return buf; }
|
| 59 |
+
case BOOL: return b ? "true" : "false";
|
| 60 |
+
default: return fallback;
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
double as_num(double fallback = 0.0) const { return t == NUM ? num : fallback; }
|
| 64 |
+
|
| 65 |
+
std::string dump() const {
|
| 66 |
+
std::string out;
|
| 67 |
+
dump_to(out);
|
| 68 |
+
return out;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
static JV parse(const std::string& text) {
|
| 72 |
+
std::size_t i = 0;
|
| 73 |
+
JV v = parse_value(text, i);
|
| 74 |
+
skip_ws(text, i);
|
| 75 |
+
if (i != text.size()) throw std::runtime_error("JSON: trailing data at " + std::to_string(i));
|
| 76 |
+
return v;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
private:
|
| 80 |
+
static void skip_ws(const std::string& s, std::size_t& i) {
|
| 81 |
+
while (i < s.size() && (s[i] == ' ' || s[i] == '\t' || s[i] == '\n' || s[i] == '\r')) ++i;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
static char expect(const std::string& s, std::size_t& i, char c) {
|
| 85 |
+
if (i >= s.size() || s[i] != c)
|
| 86 |
+
throw std::runtime_error(std::string("JSON: expected '") + c + "' at " + std::to_string(i));
|
| 87 |
+
return s[i++];
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
static JV parse_value(const std::string& s, std::size_t& i) {
|
| 91 |
+
skip_ws(s, i);
|
| 92 |
+
if (i >= s.size()) throw std::runtime_error("JSON: unexpected end");
|
| 93 |
+
char c = s[i];
|
| 94 |
+
if (c == '{') return parse_obj(s, i);
|
| 95 |
+
if (c == '[') return parse_arr(s, i);
|
| 96 |
+
if (c == '"') return JV(parse_string(s, i));
|
| 97 |
+
if (c == 't') { literal(s, i, "true"); return JV(true); }
|
| 98 |
+
if (c == 'f') { literal(s, i, "false"); return JV(false); }
|
| 99 |
+
if (c == 'n') { literal(s, i, "null"); return JV(nullptr); }
|
| 100 |
+
return parse_num(s, i);
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
static void literal(const std::string& s, std::size_t& i, const char* lit) {
|
| 104 |
+
for (const char* p = lit; *p; ++p, ++i)
|
| 105 |
+
if (i >= s.size() || s[i] != *p)
|
| 106 |
+
throw std::runtime_error("JSON: bad literal at " + std::to_string(i));
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
static JV parse_num(const std::string& s, std::size_t& i) {
|
| 110 |
+
std::size_t start = i;
|
| 111 |
+
if (i < s.size() && (s[i] == '-' || s[i] == '+')) ++i;
|
| 112 |
+
bool digits = false;
|
| 113 |
+
while (i < s.size() && ((s[i] >= '0' && s[i] <= '9') || s[i] == '.' || s[i] == 'e' ||
|
| 114 |
+
s[i] == 'E' || s[i] == '-' || s[i] == '+')) {
|
| 115 |
+
if (s[i] >= '0' && s[i] <= '9') digits = true;
|
| 116 |
+
++i;
|
| 117 |
+
}
|
| 118 |
+
if (!digits) throw std::runtime_error("JSON: bad number at " + std::to_string(start));
|
| 119 |
+
return JV(std::stod(s.substr(start, i - start)));
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
static std::string parse_string(const std::string& s, std::size_t& i) {
|
| 123 |
+
expect(s, i, '"');
|
| 124 |
+
std::string out;
|
| 125 |
+
while (i < s.size()) {
|
| 126 |
+
char c = s[i++];
|
| 127 |
+
if (c == '"') return out;
|
| 128 |
+
if (c == '\\') {
|
| 129 |
+
if (i >= s.size()) break;
|
| 130 |
+
char e = s[i++];
|
| 131 |
+
switch (e) {
|
| 132 |
+
case '"': out += '"'; break;
|
| 133 |
+
case '\\': out += '\\'; break;
|
| 134 |
+
case '/': out += '/'; break;
|
| 135 |
+
case 'b': out += '\b'; break;
|
| 136 |
+
case 'f': out += '\f'; break;
|
| 137 |
+
case 'n': out += '\n'; break;
|
| 138 |
+
case 'r': out += '\r'; break;
|
| 139 |
+
case 't': out += '\t'; break;
|
| 140 |
+
case 'u': { // \uXXXX (BMP)
|
| 141 |
+
if (i + 4 > s.size()) throw std::runtime_error("JSON: bad \\u escape");
|
| 142 |
+
unsigned cp = std::stoul(s.substr(i, 4), nullptr, 16);
|
| 143 |
+
i += 4;
|
| 144 |
+
if (cp < 0x80) out += static_cast<char>(cp);
|
| 145 |
+
else if (cp < 0x800) {
|
| 146 |
+
out += static_cast<char>(0xC0 | (cp >> 6));
|
| 147 |
+
out += static_cast<char>(0x80 | (cp & 0x3F));
|
| 148 |
+
} else {
|
| 149 |
+
out += static_cast<char>(0xE0 | (cp >> 12));
|
| 150 |
+
out += static_cast<char>(0x80 | ((cp >> 6) & 0x3F));
|
| 151 |
+
out += static_cast<char>(0x80 | (cp & 0x3F));
|
| 152 |
+
}
|
| 153 |
+
break;
|
| 154 |
+
}
|
| 155 |
+
default: throw std::runtime_error("JSON: bad escape at " + std::to_string(i));
|
| 156 |
+
}
|
| 157 |
+
} else out += c;
|
| 158 |
+
}
|
| 159 |
+
throw std::runtime_error("JSON: unterminated string");
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
static JV parse_arr(const std::string& s, std::size_t& i) {
|
| 163 |
+
expect(s, i, '[');
|
| 164 |
+
JVArr arr;
|
| 165 |
+
skip_ws(s, i);
|
| 166 |
+
if (i < s.size() && s[i] == ']') { ++i; return JV(std::move(arr)); }
|
| 167 |
+
while (true) {
|
| 168 |
+
arr.push_back(parse_value(s, i));
|
| 169 |
+
skip_ws(s, i);
|
| 170 |
+
if (i < s.size() && s[i] == ',') { ++i; continue; }
|
| 171 |
+
expect(s, i, ']');
|
| 172 |
+
break;
|
| 173 |
+
}
|
| 174 |
+
return JV(std::move(arr));
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
static JV parse_obj(const std::string& s, std::size_t& i) {
|
| 178 |
+
expect(s, i, '{');
|
| 179 |
+
JVObj obj;
|
| 180 |
+
skip_ws(s, i);
|
| 181 |
+
if (i < s.size() && s[i] == '}') { ++i; return JV(std::move(obj)); }
|
| 182 |
+
while (true) {
|
| 183 |
+
skip_ws(s, i);
|
| 184 |
+
std::string key = parse_string(s, i);
|
| 185 |
+
skip_ws(s, i);
|
| 186 |
+
expect(s, i, ':');
|
| 187 |
+
obj[key] = parse_value(s, i);
|
| 188 |
+
skip_ws(s, i);
|
| 189 |
+
if (i < s.size() && s[i] == ',') { ++i; continue; }
|
| 190 |
+
expect(s, i, '}');
|
| 191 |
+
break;
|
| 192 |
+
}
|
| 193 |
+
return JV(std::move(obj));
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
static void dump_str(const std::string& v, std::string& out) {
|
| 197 |
+
out += '"';
|
| 198 |
+
for (unsigned char c : v) {
|
| 199 |
+
switch (c) {
|
| 200 |
+
case '"': out += "\\\""; break;
|
| 201 |
+
case '\\': out += "\\\\"; break;
|
| 202 |
+
case '\n': out += "\\n"; break;
|
| 203 |
+
case '\r': out += "\\r"; break;
|
| 204 |
+
case '\t': out += "\\t"; break;
|
| 205 |
+
default:
|
| 206 |
+
if (c < 0x20) { char buf[8]; std::snprintf(buf, sizeof(buf), "\\u%04x", c); out += buf; }
|
| 207 |
+
else out += static_cast<char>(c);
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
out += '"';
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
void dump_to(std::string& out) const {
|
| 214 |
+
switch (t) {
|
| 215 |
+
case NUL: out += "null"; break;
|
| 216 |
+
case BOOL: out += b ? "true" : "false"; break;
|
| 217 |
+
case NUM: {
|
| 218 |
+
if (std::isfinite(num)) {
|
| 219 |
+
char buf[32]; std::snprintf(buf, sizeof(buf), "%.6g", num); out += buf;
|
| 220 |
+
} else out += "null";
|
| 221 |
+
break;
|
| 222 |
+
}
|
| 223 |
+
case STR: dump_str(str, out); break;
|
| 224 |
+
case ARR: {
|
| 225 |
+
out += '[';
|
| 226 |
+
for (std::size_t i = 0; i < arr.size(); ++i) { if (i) out += ','; arr[i].dump_to(out); }
|
| 227 |
+
out += ']';
|
| 228 |
+
break;
|
| 229 |
+
}
|
| 230 |
+
case OBJ: {
|
| 231 |
+
out += '{';
|
| 232 |
+
bool first = true;
|
| 233 |
+
for (const auto& kv : obj) {
|
| 234 |
+
if (!first) out += ',';
|
| 235 |
+
first = false;
|
| 236 |
+
dump_str(kv.first, out);
|
| 237 |
+
out += ':';
|
| 238 |
+
kv.second.dump_to(out);
|
| 239 |
+
}
|
| 240 |
+
out += '}';
|
| 241 |
+
break;
|
| 242 |
+
}
|
| 243 |
+
}
|
| 244 |
+
}
|
| 245 |
+
};
|
| 246 |
+
|
| 247 |
+
} // namespace sfx
|
engine/core/ngram.hpp
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// SyFox — ngram.hpp
|
| 3 |
+
// Multilingual boundary layer, part 2: character n-gram lanes.
|
| 4 |
+
//
|
| 5 |
+
// Scope guard (v2.2): encoding boundary only. si_substrate.hpp is untouched.
|
| 6 |
+
// A token "refund" additionally contributes sub-token lanes named
|
| 7 |
+
// "g3:ref", "g3:efu", "g3:fun", "g3:und" — literal, inspectable strings,
|
| 8 |
+
// NOT hashes. The physics treats them like any other concept node: they
|
| 9 |
+
// are interned, co-injected with their word, and Hebbian-bound to the
|
| 10 |
+
// lesson outcome. A typo ("refnd", "rfeund") still overlaps taught
|
| 11 |
+
// trigrams, so energy reaches the right word lane through diffusion —
|
| 12 |
+
// the field does the matching, the boundary only feeds it sub-word
|
| 13 |
+
// handles. This is the fastText-style sub-word idea rebuilt as SI lane
|
| 14 |
+
// fabric: no embeddings table, no neural net, no pattern matcher.
|
| 15 |
+
//
|
| 16 |
+
// Rules (all deterministic):
|
| 17 |
+
// * trigrams only (n=3), sliding window over CODEPOINTS (not bytes),
|
| 18 |
+
// so Bengali/Hindi/Greek words decompose correctly;
|
| 19 |
+
// * tokens shorter than 4 codepoints contribute no trigrams (their only
|
| 20 |
+
// trigram would be the token itself — a redundant lane);
|
| 21 |
+
// * lane name = "g3:" + the 3 codepoints, in left-to-right order;
|
| 22 |
+
// * unknown query trigrams (never taught) stay dark — inject() skips
|
| 23 |
+
// unknown concepts, the honest-silence contract is untouched.
|
| 24 |
+
// ============================================================================
|
| 25 |
+
#pragma once
|
| 26 |
+
#include "script.hpp"
|
| 27 |
+
|
| 28 |
+
#include <string>
|
| 29 |
+
#include <vector>
|
| 30 |
+
|
| 31 |
+
namespace si {
|
| 32 |
+
namespace norm {
|
| 33 |
+
|
| 34 |
+
// Process-wide trigram switch (v2.2). DEFAULT OFF — measured A/B (README
|
| 35 |
+
// "typo-robustness matrix"): on the small Latin seed fabrics, sub-word
|
| 36 |
+
// cross-talk trades clean held-out accuracy for corruption robustness at
|
| 37 |
+
// roughly breakeven, and the v2.1 baselines are only reproduced with the
|
| 38 |
+
// word-level stream. The mechanism stays one flag away and ACTIVATES
|
| 39 |
+
// automatically for non-Latin routed substrates (`--lang auto` policy:
|
| 40 |
+
// the script barrier and their tiny vocabularies make bridges load-bearing
|
| 41 |
+
// there — the Bengali typo-routing test proves it). `--ngrams on|off`
|
| 42 |
+
// overrides explicitly. Same pattern as the synonym table: one process-wide
|
| 43 |
+
// boundary configuration, set once before any command runs.
|
| 44 |
+
inline bool& grams_enabled() { static bool on = false; return on; }
|
| 45 |
+
|
| 46 |
+
inline std::vector<std::string> expand_ngrams(const std::vector<std::string>& tokens) {
|
| 47 |
+
std::vector<std::string> out;
|
| 48 |
+
for (const auto& tok : tokens) {
|
| 49 |
+
// decode codepoints once; malformed bytes were already dropped by the
|
| 50 |
+
// tokenizer, but stay defensive: unknown bytes are skipped here too
|
| 51 |
+
std::vector<std::uint32_t> cps;
|
| 52 |
+
std::vector<std::size_t> byte_off; // codepoint -> byte offset
|
| 53 |
+
for (std::size_t i = 0; i < tok.size();) {
|
| 54 |
+
std::uint32_t cp = 0;
|
| 55 |
+
const std::size_t len = script::decode_utf8(tok, i, cp);
|
| 56 |
+
if (cp != 0xFFFFFFFFu) { cps.push_back(cp); byte_off.push_back(i); }
|
| 57 |
+
i += len;
|
| 58 |
+
}
|
| 59 |
+
if (cps.size() < 4) continue; // sub-word handles only for real words
|
| 60 |
+
out.reserve(out.size() + cps.size() - 2);
|
| 61 |
+
for (std::size_t w = 0; w + 2 < cps.size(); ++w) {
|
| 62 |
+
// each segment is exactly one codepoint: byte ranges come from
|
| 63 |
+
// the offsets table, the last one ends at the next codepoint
|
| 64 |
+
// (or end of token for the final one)
|
| 65 |
+
const std::size_t b0 = byte_off[w], e0 = byte_off[w + 1];
|
| 66 |
+
const std::size_t b1 = byte_off[w + 1], e1 = byte_off[w + 2];
|
| 67 |
+
const std::size_t b2 = byte_off[w + 2];
|
| 68 |
+
const std::size_t e2 = (w + 3 < byte_off.size()) ? byte_off[w + 3] : tok.size();
|
| 69 |
+
std::string g = "g3:";
|
| 70 |
+
g.append(tok, b0, e0 - b0);
|
| 71 |
+
g.append(tok, b1, e1 - b1);
|
| 72 |
+
g.append(tok, b2, e2 - b2);
|
| 73 |
+
out.push_back(std::move(g));
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
return out;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// The ONE state-side augmentation protocol for TEACHING: word tokens first
|
| 80 |
+
// (preserving v0.1's adjacency fabric word->word unchanged), then each
|
| 81 |
+
// word's trigrams. With grams disabled this is exactly the v2.1 token
|
| 82 |
+
// stream, byte for byte.
|
| 83 |
+
inline std::vector<std::string> state_tokens(const std::vector<std::string>& words,
|
| 84 |
+
bool with_grams) {
|
| 85 |
+
if (!with_grams) return words;
|
| 86 |
+
std::vector<std::string> out = words;
|
| 87 |
+
const std::vector<std::string> g = expand_ngrams(words);
|
| 88 |
+
out.insert(out.end(), g.begin(), g.end());
|
| 89 |
+
return out;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
// ---------------------------------------------------------------------------
|
| 93 |
+
// The v2.2 DECIDE-side protocol: trigram bridges for the unknown ONLY.
|
| 94 |
+
//
|
| 95 |
+
// Measured (v2.2 A/B): injecting every word's grams at decide time floods
|
| 96 |
+
// clean queries with sub-word energy (tickets heldout 1.000 -> 0.667, guard
|
| 97 |
+
// 0.750 -> 0.250) because unrelated words share trigrams and the extra
|
| 98 |
+
// lanes cross-talk. The fix keeps the typo robustness and drops the noise:
|
| 99 |
+
// a word the substrate KNOWS takes its direct lane (no grams -> clean
|
| 100 |
+
// behavior byte-identical to the word-only encoding); a word it does NOT
|
| 101 |
+
// know (a typo, an unseen term) contributes its trigrams as bridges into
|
| 102 |
+
// the taught gram lanes. inject() skips unknown concepts, so grams that
|
| 103 |
+
// were never taught stay dark on their own.
|
| 104 |
+
// ---------------------------------------------------------------------------
|
| 105 |
+
template <class HasFn>
|
| 106 |
+
inline std::vector<std::string> field_tokens(const std::vector<std::string>& words,
|
| 107 |
+
bool with_grams, HasFn&& has) {
|
| 108 |
+
if (!with_grams) return words;
|
| 109 |
+
std::vector<std::string> out = words;
|
| 110 |
+
for (const auto& w : words) {
|
| 111 |
+
if (has(w)) continue; // known: direct lane, no bridge
|
| 112 |
+
for (const auto& g : expand_ngrams({w})) out.push_back(g);
|
| 113 |
+
}
|
| 114 |
+
return out;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
} // namespace norm
|
| 118 |
+
} // namespace si
|
engine/core/normalize.hpp
ADDED
|
@@ -0,0 +1,462 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// SyFox — normalize.hpp
|
| 3 |
+
// Input-boundary normalization: synonym folding + Porter stemming.
|
| 4 |
+
//
|
| 5 |
+
// Scope guard (v2.1): this file lives at the ENCODING boundary, not in the
|
| 6 |
+
// physics. si_substrate.hpp is byte-identical to v0.2 — energy, decay,
|
| 7 |
+
// diffusion, lanes, readout untouched. What changes is only which token
|
| 8 |
+
// string enters the substrate: "reimbursement" now lands on the same node
|
| 9 |
+
// as "refund", "urgently" on the same node as "urgent". Teach and decide
|
| 10 |
+
// share one deterministic pipeline, so the fabric stays consistent.
|
| 11 |
+
//
|
| 12 |
+
// normalize(text) = scan alnum runs -> Porter(1980) -> synonym fold
|
| 13 |
+
//
|
| 14 |
+
// Determinism: pure functions, fixed tables, no randomness, no neural net.
|
| 15 |
+
// The synonym table is loaded from data/synonyms.txt when present
|
| 16 |
+
// (--synonyms overrides the path); otherwise an embedded copy of the same
|
| 17 |
+
// table applies. Table keys and values are stemmed AT LOAD TIME, so fold
|
| 18 |
+
// order (porter -> synonyms) is self-consistent no matter how Porter stems
|
| 19 |
+
// a given word.
|
| 20 |
+
// ============================================================================
|
| 21 |
+
#pragma once
|
| 22 |
+
#include "si_substrate.hpp"
|
| 23 |
+
#include "script.hpp"
|
| 24 |
+
|
| 25 |
+
#include <algorithm>
|
| 26 |
+
#include <cctype>
|
| 27 |
+
#include <cstdint>
|
| 28 |
+
#include <fstream>
|
| 29 |
+
#include <map>
|
| 30 |
+
#include <sstream>
|
| 31 |
+
#include <string>
|
| 32 |
+
#include <vector>
|
| 33 |
+
|
| 34 |
+
namespace si {
|
| 35 |
+
namespace norm {
|
| 36 |
+
|
| 37 |
+
// ---------------------------------------------------------------------------
|
| 38 |
+
// Porter stemmer — faithful port of M.F. Porter's reference implementation
|
| 39 |
+
// (program: Porter, 1980; the classic ANSI C version). Compact, iterative,
|
| 40 |
+
// deterministic. Words of length <= 2 pass through untouched (same as the
|
| 41 |
+
// reference driver).
|
| 42 |
+
// ---------------------------------------------------------------------------
|
| 43 |
+
struct Porter {
|
| 44 |
+
std::string b;
|
| 45 |
+
int k = 0, k0 = 0, j = 0; // b[0..k] is the word; j is a scratch offset
|
| 46 |
+
|
| 47 |
+
explicit Porter(std::string w) : b(std::move(w)) {
|
| 48 |
+
k = static_cast<int>(b.size()) - 1;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
bool cons(int i) const {
|
| 52 |
+
switch (b[i]) {
|
| 53 |
+
case 'a': case 'e': case 'i': case 'o': case 'u': return false;
|
| 54 |
+
case 'y': return (i == k0) ? true : !cons(i - 1);
|
| 55 |
+
default: return true;
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
// m() counts consonant-vowel sequences: <c><v> -> 0, <c>vc<v> -> 1, ...
|
| 60 |
+
int m() const {
|
| 61 |
+
int n = 0, i = k0;
|
| 62 |
+
while (true) { if (i > j) return n; if (!cons(i)) break; ++i; }
|
| 63 |
+
++i;
|
| 64 |
+
while (true) {
|
| 65 |
+
while (true) { if (i > j) return n; if (cons(i)) break; ++i; }
|
| 66 |
+
++i; ++n;
|
| 67 |
+
while (true) { if (i > j) return n; if (!cons(i)) break; ++i; }
|
| 68 |
+
++i;
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
bool vowel_in_stem() const {
|
| 73 |
+
for (int i = k0; i <= j; ++i) if (!cons(i)) return true;
|
| 74 |
+
return false;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
bool doublec(int i) const {
|
| 78 |
+
if (i < k0 + 1) return false;
|
| 79 |
+
if (b[i] != b[i - 1]) return false;
|
| 80 |
+
return cons(i);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
bool cvc(int i) const {
|
| 84 |
+
if (i < k0 + 2 || !cons(i) || cons(i - 1) || !cons(i - 2)) return false;
|
| 85 |
+
const char ch = b[i];
|
| 86 |
+
return !(ch == 'w' || ch == 'x' || ch == 'y');
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
// ends(): mirrors the reference — on success sets j = k - length.
|
| 90 |
+
bool ends_j(const char* s) {
|
| 91 |
+
const int length = s[0]; // first byte = length (Pascal-style)
|
| 92 |
+
if (b[k] != s[length]) return false;
|
| 93 |
+
if (length > k - k0 + 1) return false;
|
| 94 |
+
if (b.compare(k - length + 1, static_cast<std::size_t>(length), s + 1,
|
| 95 |
+
static_cast<std::size_t>(length)) != 0) return false;
|
| 96 |
+
j = k - length;
|
| 97 |
+
return true;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
void setto(const char* s) {
|
| 101 |
+
const int length = s[0];
|
| 102 |
+
b.replace(static_cast<std::size_t>(j) + 1, static_cast<std::size_t>(length), s + 1,
|
| 103 |
+
static_cast<std::size_t>(length));
|
| 104 |
+
k = j + length;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
void r(const char* s) { if (m() > 0) setto(s); }
|
| 108 |
+
|
| 109 |
+
void step1ab() {
|
| 110 |
+
if (b[k] == 's') {
|
| 111 |
+
if (ends_j("\04" "sses")) k -= 2;
|
| 112 |
+
else if (ends_j("\03" "ies")) setto("\01" "i");
|
| 113 |
+
else if (b[k - 1] != 's') k--;
|
| 114 |
+
}
|
| 115 |
+
if (ends_j("\03" "eed")) { if (m() > 0) k--; }
|
| 116 |
+
else if ((ends_j("\02" "ed") || ends_j("\03" "ing")) && vowel_in_stem()) {
|
| 117 |
+
k = j;
|
| 118 |
+
if (ends_j("\02" "at")) setto("\03" "ate");
|
| 119 |
+
else if (ends_j("\02" "bl")) setto("\03" "ble");
|
| 120 |
+
else if (ends_j("\02" "iz")) setto("\03" "ize");
|
| 121 |
+
else if (doublec(k)) {
|
| 122 |
+
k--;
|
| 123 |
+
const char ch = b[k];
|
| 124 |
+
if (ch == 'l' || ch == 's' || ch == 'z') k++;
|
| 125 |
+
}
|
| 126 |
+
else if (m() == 1 && cvc(k)) setto("\01" "e");
|
| 127 |
+
}
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
void step1c() {
|
| 131 |
+
if (ends_j("\01" "y") && vowel_in_stem()) b[k] = 'i';
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
void step2() {
|
| 135 |
+
if (k < k0 + 1) return;
|
| 136 |
+
switch (b[k - 1]) {
|
| 137 |
+
case 'a': if (ends_j("\07" "ational")) { r("\03" "ate"); break; }
|
| 138 |
+
if (ends_j("\06" "tional")) { r("\04" "tion"); break; } break;
|
| 139 |
+
case 'c': if (ends_j("\04" "enci")) { r("\04" "ence"); break; }
|
| 140 |
+
if (ends_j("\04" "anci")) { r("\04" "ance"); break; } break;
|
| 141 |
+
case 'e': if (ends_j("\04" "izer")) { r("\04" "ize"); break; } break;
|
| 142 |
+
case 'l': if (ends_j("\03" "bli")) { r("\03" "ble"); break; }
|
| 143 |
+
if (ends_j("\04" "alli")) { r("\02" "al"); break; }
|
| 144 |
+
if (ends_j("\05" "entli")) { r("\03" "ent"); break; }
|
| 145 |
+
if (ends_j("\03" "eli")) { r("\01" "e"); break; }
|
| 146 |
+
if (ends_j("\05" "ousli")) { r("\03" "ous"); break; } break;
|
| 147 |
+
case 'o': if (ends_j("\07" "ization")) { r("\03" "ize"); break; }
|
| 148 |
+
if (ends_j("\05" "ation")) { r("\03" "ate"); break; }
|
| 149 |
+
if (ends_j("\04" "ator")) { r("\03" "ate"); break; } break;
|
| 150 |
+
case 's': if (ends_j("\05" "alism")) { r("\02" "al"); break; }
|
| 151 |
+
if (ends_j("\07" "iveness")) { r("\03" "ive"); break; }
|
| 152 |
+
if (ends_j("\07" "fulness")) { r("\03" "ful"); break; }
|
| 153 |
+
if (ends_j("\07" "ousness")) { r("\03" "ous"); break; } break;
|
| 154 |
+
case 't': if (ends_j("\05" "aliti")) { r("\02" "al"); break; }
|
| 155 |
+
if (ends_j("\05" "iviti")) { r("\03" "ive"); break; }
|
| 156 |
+
if (ends_j("\06" "biliti")) { r("\03" "ble"); break; } break;
|
| 157 |
+
case 'g': if (ends_j("\04" "logi")) { r("\03" "log"); break; } break;
|
| 158 |
+
}
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
void step3() {
|
| 162 |
+
switch (b[k]) {
|
| 163 |
+
case 'e': if (ends_j("\05" "icate")) { r("\02" "ic"); break; }
|
| 164 |
+
if (ends_j("\05" "ative")) { r("\00" ""); break; }
|
| 165 |
+
if (ends_j("\05" "alize")) { r("\02" "al"); break; } break;
|
| 166 |
+
case 'i': if (ends_j("\05" "iciti")) { r("\02" "ic"); break; } break;
|
| 167 |
+
case 'l': if (ends_j("\04" "ical")) { r("\02" "ic"); break; } break;
|
| 168 |
+
case 'f': if (ends_j("\03" "ful")) { r("\00" ""); break; } break;
|
| 169 |
+
case 's': if (ends_j("\04" "ness")) { r("\00" ""); break; } break;
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
void step4() {
|
| 174 |
+
static const char* const kSuffs[] = {
|
| 175 |
+
"\02" "al", "\04" "ance", "\04" "ence", "\02" "er", "\02" "ic",
|
| 176 |
+
"\04" "able", "\04" "ible", "\03" "ant", "\05" "ement",
|
| 177 |
+
"\04" "ment", "\03" "ent", "\03" "ion", "\02" "ou", "\03" "ism",
|
| 178 |
+
"\03" "ate", "\03" "iti", "\03" "ous", "\03" "ive", "\03" "ize" };
|
| 179 |
+
// Faithful scan semantics: the FIRST suffix whose ending matches stops
|
| 180 |
+
// the scan; "ion" (index 11) additionally requires the stem to end in
|
| 181 |
+
// s/t (b[j] is the stem's last char — j was set by ends_j). If the
|
| 182 |
+
// condition fails the scan CONTINUES (a later suffix may still fire).
|
| 183 |
+
int i = 0;
|
| 184 |
+
for (; i < 19; ++i) {
|
| 185 |
+
if (ends_j(kSuffs[i])) {
|
| 186 |
+
if (i != 11 || b[j] == 's' || b[j] == 't') break;
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
if (i < 19 && m() > 1) k = j;
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
void step5() {
|
| 193 |
+
j = k;
|
| 194 |
+
if (b[k] == 'e') {
|
| 195 |
+
const int a = m();
|
| 196 |
+
if (a > 1 || (a == 1 && !cvc(k - 1))) k--;
|
| 197 |
+
}
|
| 198 |
+
if (b[k] == 'l' && doublec(k) && m() > 1) k--;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
void stem() {
|
| 202 |
+
if (k <= k0 + 1) return; // reference driver: len <= 2 untouched
|
| 203 |
+
step1ab(); step1c(); step2(); step3(); step4(); step5();
|
| 204 |
+
b.resize(static_cast<std::size_t>(k) + 1);
|
| 205 |
+
}
|
| 206 |
+
};
|
| 207 |
+
|
| 208 |
+
inline std::string porter_stem(const std::string& w) {
|
| 209 |
+
if (w.size() <= 2) return w;
|
| 210 |
+
Porter p(w);
|
| 211 |
+
p.stem();
|
| 212 |
+
return p.b;
|
| 213 |
+
}
|
| 214 |
+
|
| 215 |
+
// ---------------------------------------------------------------------------
|
| 216 |
+
// Synonym folding table: word (stemmed) -> stemmed canonical.
|
| 217 |
+
// ---------------------------------------------------------------------------
|
| 218 |
+
using SynTable = std::map<std::string, std::string>;
|
| 219 |
+
|
| 220 |
+
inline SynTable& syn_table() { static SynTable t; return t; }
|
| 221 |
+
inline bool& syn_loaded() { static bool loaded = false; return loaded; }
|
| 222 |
+
|
| 223 |
+
// Embedded copy of data/synonyms.txt (kept in lockstep; the file, when present,
|
| 224 |
+
// is authoritative). Same conservative rules: single words, label-safe swaps.
|
| 225 |
+
inline const char* default_synonyms_text() {
|
| 226 |
+
return
|
| 227 |
+
"refund: reimbursement, reimburse\n"
|
| 228 |
+
"urgent: asap, immediately, urgently, hurry\n"
|
| 229 |
+
"angry: furious, mad, upset\n"
|
| 230 |
+
"broken: faulty, busted\n"
|
| 231 |
+
"fix: repair, mend\n"
|
| 232 |
+
"problem: issue, trouble, glitch\n"
|
| 233 |
+
"slow: delayed, sluggish, laggy\n"
|
| 234 |
+
"crash: freeze, hang, froze\n"
|
| 235 |
+
"price: cost\n"
|
| 236 |
+
"scared: afraid, fearful\n"
|
| 237 |
+
"money: cash\n"
|
| 238 |
+
"wrong: incorrect, mistaken\n";
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
// Parse "canonical: variant, variant, ..." lines. Keys and values are stemmed
|
| 242 |
+
// here, so the fold is applied AFTER Porter and stays self-consistent.
|
| 243 |
+
inline void parse_synonyms_text(const std::string& text) {
|
| 244 |
+
std::string line;
|
| 245 |
+
std::istringstream ss(text);
|
| 246 |
+
while (std::getline(ss, line)) {
|
| 247 |
+
if (line.empty() || line[0] == '#') continue;
|
| 248 |
+
const std::size_t colon = line.find(':');
|
| 249 |
+
if (colon == std::string::npos) continue;
|
| 250 |
+
auto trim = [](std::string s) {
|
| 251 |
+
const auto a = s.find_first_not_of(" \t\r\n");
|
| 252 |
+
if (a == std::string::npos) return std::string();
|
| 253 |
+
const auto b = s.find_last_not_of(" \t\r\n");
|
| 254 |
+
return s.substr(a, b - a + 1);
|
| 255 |
+
};
|
| 256 |
+
auto lower = [](std::string s) {
|
| 257 |
+
for (char& c : s) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
|
| 258 |
+
return s;
|
| 259 |
+
};
|
| 260 |
+
const std::string canon_raw = lower(trim(line.substr(0, colon)));
|
| 261 |
+
if (canon_raw.empty()) continue;
|
| 262 |
+
const std::string canon = porter_stem(canon_raw);
|
| 263 |
+
syn_table()[canon] = canon; // canonical maps to itself
|
| 264 |
+
std::string rest = line.substr(colon + 1);
|
| 265 |
+
std::size_t start = 0;
|
| 266 |
+
while (start <= rest.size()) {
|
| 267 |
+
std::size_t comma = rest.find(',', start);
|
| 268 |
+
if (comma == std::string::npos) comma = rest.size();
|
| 269 |
+
const std::string var_raw = lower(trim(rest.substr(start, comma - start)));
|
| 270 |
+
if (!var_raw.empty()) syn_table()[porter_stem(var_raw)] = canon;
|
| 271 |
+
start = comma + 1;
|
| 272 |
+
}
|
| 273 |
+
}
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
inline void load_synonyms(const std::string& path) {
|
| 277 |
+
std::ifstream f(path);
|
| 278 |
+
if (!f) return; // missing file: embedded default stays
|
| 279 |
+
std::string buf((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
| 280 |
+
parse_synonyms_text(buf);
|
| 281 |
+
syn_loaded() = true;
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
inline void ensure_synonyms() {
|
| 285 |
+
if (syn_loaded()) return;
|
| 286 |
+
parse_synonyms_text(default_synonyms_text());
|
| 287 |
+
syn_loaded() = true;
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
// ---------------------------------------------------------------------------
|
| 291 |
+
// The one normalization pipeline (teach, decide, recall, harvest — everyone).
|
| 292 |
+
//
|
| 293 |
+
// v2.2 — multilingual boundary. The v2.1 pipeline scanned BYTES with
|
| 294 |
+
// std::isalnum, which in the C locale splits every multi-byte UTF-8
|
| 295 |
+
// sequence apart: a Bengali or Hindi query produced ZERO tokens (the actual
|
| 296 |
+
// language barrier). The pipeline is now codepoint-aware:
|
| 297 |
+
//
|
| 298 |
+
// * pure-ASCII input takes the SAME byte path as v2.1 — output is
|
| 299 |
+
// byte-identical (guarded by test), so existing fabrics are unaffected;
|
| 300 |
+
// * non-ASCII input decodes UTF-8 and scans letter/digit codepoint runs;
|
| 301 |
+
// a run splits where the SCRIPT changes (tokens are script-homogeneous);
|
| 302 |
+
// * Latin tokens: lowercased (ASCII fast case + Latin-1/Extended-A map),
|
| 303 |
+
// Porter + synonyms apply to pure-ASCII tokens only — Porter(1980) is
|
| 304 |
+
// an English algorithm and would corrupt accented bytes;
|
| 305 |
+
// * Cyrillic/Greek: codepoint lowercase map, no Porter, no synonyms
|
| 306 |
+
// (the fold table is English by design; forcing it would be wrong);
|
| 307 |
+
// * all other scripts: codepoints pass through as UTF-8, untouched;
|
| 308 |
+
// * token length limits 2..24 CODEPOINTS (same intent as the old
|
| 309 |
+
// 2..24 bytes rule);
|
| 310 |
+
// * malformed UTF-8 bytes are separators (deterministic, never a crash);
|
| 311 |
+
// * still no NLP pipeline, no neural net: ranges, maps, and counters.
|
| 312 |
+
//
|
| 313 |
+
// Character n-gram lanes live in ngram.hpp and are appended by
|
| 314 |
+
// state_tokens(), NOT here — labels, instructions, and readout probes
|
| 315 |
+
// stay gram-free by construction.
|
| 316 |
+
// ---------------------------------------------------------------------------
|
| 317 |
+
|
| 318 |
+
// codepoint lowercase for Latin-1 + Latin Extended-A (Cyrillic/Greek have
|
| 319 |
+
// their own maps below). Deterministic range arithmetic, no locale.
|
| 320 |
+
inline std::uint32_t lower_latin(std::uint32_t cp) {
|
| 321 |
+
if (cp >= 0x0041 && cp <= 0x005A) return cp + 0x20; // ASCII A-Z
|
| 322 |
+
if (cp >= 0x00C0 && cp <= 0x00DE && cp != 0x00D7) return cp + 0x20; // À..Þ -> à..þ
|
| 323 |
+
if (cp >= 0x0100 && cp <= 0x0137) return (cp % 2 == 0) ? cp + 1 : cp; // A-macron pairs
|
| 324 |
+
if (cp >= 0x0139 && cp <= 0x0148) return (cp % 2 == 1) ? cp + 1 : cp;
|
| 325 |
+
if (cp >= 0x014A && cp <= 0x0177) return (cp % 2 == 0) ? cp + 1 : cp;
|
| 326 |
+
if (cp == 0x0178) return 0x00FF; // Ÿ -> ÿ
|
| 327 |
+
if (cp >= 0x0179 && cp <= 0x017E) return (cp % 2 == 1) ? cp + 1 : cp;
|
| 328 |
+
if (cp >= 0x0180 && cp <= 0x01BF && cp % 2 == 1) return cp + 1;
|
| 329 |
+
if (cp >= 0x01CD && cp <= 0x01DC && cp % 2 == 1) return cp + 1;
|
| 330 |
+
if (cp >= 0x01DE && cp <= 0x01EF && cp % 2 == 0) return cp + 1;
|
| 331 |
+
if (cp >= 0x01F1 && cp <= 0x01F3) return cp + 2; // DZ/Dd/dz digraphs
|
| 332 |
+
if (cp >= 0x01F4 && cp <= 0x01F5) return (cp == 0x01F4) ? cp + 1 : cp;
|
| 333 |
+
if (cp >= 0x01FA && cp <= 0x0217 && cp % 2 == 0) return cp + 1;
|
| 334 |
+
if (cp >= 0x1E00 && cp <= 0x1EF9 && cp % 2 == 0) return cp + 1; // Vietnamese block
|
| 335 |
+
return cp;
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
inline std::uint32_t lower_cyrillic(std::uint32_t cp) {
|
| 339 |
+
if (cp >= 0x0410 && cp <= 0x042F) return cp + 0x20; // А..Я -> а..я
|
| 340 |
+
if (cp >= 0x0400 && cp <= 0x040F) return cp + 0x50; // Ѐ..Џ -> ѐ..џ
|
| 341 |
+
if ((cp >= 0x0460 && cp <= 0x0481 && cp % 2 == 0) ||
|
| 342 |
+
(cp >= 0x048A && cp <= 0x04BF && cp % 2 == 0)) return cp + 1;
|
| 343 |
+
if (cp == 0x04C0) return 0x04CF; // Пalochka
|
| 344 |
+
if (cp >= 0x04C1 && cp <= 0x04CE && cp % 2 == 1) return cp - 1;
|
| 345 |
+
return cp;
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
inline std::uint32_t lower_greek(std::uint32_t cp) {
|
| 349 |
+
if ((cp >= 0x0391 && cp <= 0x03A1) || (cp >= 0x03A3 && cp <= 0x03AB))
|
| 350 |
+
return cp + 0x20; // Α..Ω -> α..ω
|
| 351 |
+
return cp;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
inline std::uint32_t lower_cp(std::uint32_t cp, script::Script sc) {
|
| 355 |
+
switch (sc) {
|
| 356 |
+
case script::Script::Latin: return lower_latin(cp);
|
| 357 |
+
case script::Script::Cyrillic: return lower_cyrillic(cp);
|
| 358 |
+
case script::Script::Greek: return lower_greek(cp);
|
| 359 |
+
default: return cp;
|
| 360 |
+
}
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
inline void append_utf8(std::string& s, std::uint32_t cp) {
|
| 364 |
+
if (cp < 0x80) { s.push_back(static_cast<char>(cp)); return; }
|
| 365 |
+
if (cp < 0x800) {
|
| 366 |
+
s.push_back(static_cast<char>(0xC0 | (cp >> 6)));
|
| 367 |
+
s.push_back(static_cast<char>(0x80 | (cp & 0x3F)));
|
| 368 |
+
return;
|
| 369 |
+
}
|
| 370 |
+
if (cp < 0x10000) {
|
| 371 |
+
s.push_back(static_cast<char>(0xE0 | (cp >> 12)));
|
| 372 |
+
s.push_back(static_cast<char>(0x80 | ((cp >> 6) & 0x3F)));
|
| 373 |
+
s.push_back(static_cast<char>(0x80 | (cp & 0x3F)));
|
| 374 |
+
return;
|
| 375 |
+
}
|
| 376 |
+
s.push_back(static_cast<char>(0xF0 | (cp >> 18)));
|
| 377 |
+
s.push_back(static_cast<char>(0x80 | ((cp >> 12) & 0x3F)));
|
| 378 |
+
s.push_back(static_cast<char>(0x80 | ((cp >> 6) & 0x3F)));
|
| 379 |
+
s.push_back(static_cast<char>(0x80 | (cp & 0x3F)));
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
// Latin-token post-processing: identical to v2.1 for pure-ASCII tokens
|
| 383 |
+
// (porter -> synonyms); non-ASCII Latin passes through lowercased only.
|
| 384 |
+
inline std::string fold_latin_token(std::string t) {
|
| 385 |
+
bool pure_ascii = true;
|
| 386 |
+
for (char c : t) if (static_cast<unsigned char>(c) >= 0x80) { pure_ascii = false; break; }
|
| 387 |
+
if (!pure_ascii) return t;
|
| 388 |
+
t = porter_stem(t);
|
| 389 |
+
auto it = syn_table().find(t);
|
| 390 |
+
if (it != syn_table().end()) t = it->second;
|
| 391 |
+
return t;
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
inline std::vector<std::string> normalize(const std::string& text) {
|
| 395 |
+
struct Once { Once() { ensure_synonyms(); } };
|
| 396 |
+
static Once once;
|
| 397 |
+
|
| 398 |
+
// ASCII fast path: byte-for-byte the v2.1 pipeline (guarded by test).
|
| 399 |
+
bool ascii_only = true;
|
| 400 |
+
for (char raw : text)
|
| 401 |
+
if (static_cast<unsigned char>(raw) >= 0x80) { ascii_only = false; break; }
|
| 402 |
+
|
| 403 |
+
std::vector<std::string> out;
|
| 404 |
+
if (ascii_only) {
|
| 405 |
+
std::string cur;
|
| 406 |
+
auto emit = [&]() {
|
| 407 |
+
if (cur.size() >= 2 && cur.size() <= 24) {
|
| 408 |
+
std::string t = porter_stem(cur);
|
| 409 |
+
auto it = syn_table().find(t);
|
| 410 |
+
if (it != syn_table().end()) t = it->second;
|
| 411 |
+
out.push_back(std::move(t));
|
| 412 |
+
}
|
| 413 |
+
cur.clear();
|
| 414 |
+
};
|
| 415 |
+
for (char raw : text) {
|
| 416 |
+
unsigned char c = static_cast<unsigned char>(raw);
|
| 417 |
+
if (std::isalnum(c)) cur.push_back(static_cast<char>(std::tolower(c)));
|
| 418 |
+
else if (!cur.empty()) emit();
|
| 419 |
+
}
|
| 420 |
+
if (!cur.empty()) emit();
|
| 421 |
+
return out;
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
// UTF-8 codepoint path (the multilingual boundary).
|
| 425 |
+
std::string cur; // current token, UTF-8
|
| 426 |
+
std::uint32_t cur_script = 0xFFFFFFFFu; // dominant script of `cur`
|
| 427 |
+
std::size_t cur_cps = 0; // codepoint count
|
| 428 |
+
auto emit = [&]() {
|
| 429 |
+
if (cur_cps >= 2 && cur_cps <= 24) {
|
| 430 |
+
const script::Script sc = static_cast<script::Script>(cur_script);
|
| 431 |
+
out.push_back(sc == script::Script::Latin
|
| 432 |
+
? fold_latin_token(cur) : cur);
|
| 433 |
+
}
|
| 434 |
+
cur.clear(); cur_cps = 0; cur_script = 0xFFFFFFFFu;
|
| 435 |
+
};
|
| 436 |
+
std::uint32_t cp = 0;
|
| 437 |
+
std::size_t i = 0;
|
| 438 |
+
while (i < text.size()) {
|
| 439 |
+
i += script::decode_utf8(text, i, cp);
|
| 440 |
+
if (cp == 0xFFFFFFFFu) { if (!cur.empty()) emit(); continue; } // malformed: separator
|
| 441 |
+
if (script::is_letter_cp(cp)) {
|
| 442 |
+
const std::uint32_t sc = static_cast<std::uint32_t>(script::codepoint_script(cp));
|
| 443 |
+
if (cur_script != 0xFFFFFFFFu && sc != cur_script) emit(); // script change splits
|
| 444 |
+
if (cur.empty()) cur_script = sc;
|
| 445 |
+
append_utf8(cur, lower_cp(cp, static_cast<script::Script>(sc)));
|
| 446 |
+
++cur_cps;
|
| 447 |
+
} else if (script::is_digit_cp(cp)) {
|
| 448 |
+
if (cur_script != 0xFFFFFFFFu &&
|
| 449 |
+
cur_script != static_cast<std::uint32_t>(script::Script::Latin)) emit();
|
| 450 |
+
if (cur.empty()) cur_script = static_cast<std::uint32_t>(script::Script::Latin);
|
| 451 |
+
append_utf8(cur, cp); // digits: script-neutral, ASCII order
|
| 452 |
+
++cur_cps;
|
| 453 |
+
} else {
|
| 454 |
+
if (!cur.empty()) emit(); // separator
|
| 455 |
+
}
|
| 456 |
+
}
|
| 457 |
+
if (!cur.empty()) emit();
|
| 458 |
+
return out;
|
| 459 |
+
}
|
| 460 |
+
|
| 461 |
+
} // namespace norm
|
| 462 |
+
} // namespace si
|
engine/core/recall.hpp
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// SyFox — recall.hpp
|
| 3 |
+
// Associative retrieval through field dynamics.
|
| 4 |
+
//
|
| 5 |
+
// The user constraint holds: NO transformer, NO pattern matching. Recall is
|
| 6 |
+
// a Hopfield-style content-addressable memory where similarity lives in the
|
| 7 |
+
// SUBSTRATE'S OWN STATE SPACE, not in symbol space:
|
| 8 |
+
//
|
| 9 |
+
// 1. settle the query state -> its settled-energy fingerprint Fq
|
| 10 |
+
// (one float per concept node, L2-normalized)
|
| 11 |
+
// 2. settle each stored memory state -> Fm
|
| 12 |
+
// 3. resonance(Fq, Fm) = cosine of the two fields
|
| 13 |
+
//
|
| 14 |
+
// There is no token comparison, no string edit distance, no n-gram overlap,
|
| 15 |
+
// no embedding table: the fabric itself answers "which lived experience does
|
| 16 |
+
// this state most resemble" by interference of energy distributions. Two
|
| 17 |
+
// states that share no surface token can still resonate if the field routes
|
| 18 |
+
// them to the same region; two states sharing tokens can resonate weakly if
|
| 19 |
+
// the fabric keeps them apart.
|
| 20 |
+
//
|
| 21 |
+
// Read-only: fingerprints are transient field states; nothing persists.
|
| 22 |
+
// Deterministic: same model + same query + same memories => same ranking.
|
| 23 |
+
// ============================================================================
|
| 24 |
+
#pragma once
|
| 25 |
+
#include "si_substrate.hpp"
|
| 26 |
+
#include "normalize.hpp"
|
| 27 |
+
|
| 28 |
+
#include <algorithm>
|
| 29 |
+
#include <cmath>
|
| 30 |
+
#include <string>
|
| 31 |
+
#include <vector>
|
| 32 |
+
|
| 33 |
+
namespace syfox {
|
| 34 |
+
namespace recall {
|
| 35 |
+
|
| 36 |
+
struct Memory {
|
| 37 |
+
std::string label; // free text (e.g. the taught outcome)
|
| 38 |
+
std::vector<std::string> state; // tokenized memory state
|
| 39 |
+
};
|
| 40 |
+
|
| 41 |
+
struct RecallHit {
|
| 42 |
+
std::size_t index; // position in the input memory list
|
| 43 |
+
std::string label;
|
| 44 |
+
float resonance; // cosine in settled-energy space, [-0,1]
|
| 45 |
+
};
|
| 46 |
+
|
| 47 |
+
// Settled-energy fingerprint of a token list: settle, then collect the field.
|
| 48 |
+
// Unknown tokens contribute nothing (inject skips them — honest silence).
|
| 49 |
+
inline std::vector<float> fingerprint(si::Substrate& s,
|
| 50 |
+
const std::vector<std::string>& tokens) {
|
| 51 |
+
s.reset_field();
|
| 52 |
+
s.inject(tokens);
|
| 53 |
+
s.settle();
|
| 54 |
+
std::vector<float> f(s.node_count(), 0.0f);
|
| 55 |
+
double n2 = 0.0;
|
| 56 |
+
for (std::size_t i = 0; i < s.node_count(); ++i) {
|
| 57 |
+
f[i] = s.node_energy(static_cast<si::NodeId>(i));
|
| 58 |
+
n2 += static_cast<double>(f[i]) * static_cast<double>(f[i]);
|
| 59 |
+
}
|
| 60 |
+
if (n2 > 0.0) {
|
| 61 |
+
const float nrm = static_cast<float>(std::sqrt(n2));
|
| 62 |
+
for (auto& v : f) v /= nrm;
|
| 63 |
+
}
|
| 64 |
+
return f;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
inline std::vector<RecallHit> recall(si::Substrate& s,
|
| 68 |
+
const std::string& query_state,
|
| 69 |
+
const std::vector<Memory>& memories,
|
| 70 |
+
int top_k = 5) {
|
| 71 |
+
std::vector<RecallHit> hits;
|
| 72 |
+
if (memories.empty() || s.node_count() == 0) return hits;
|
| 73 |
+
// v2.2: query goes through the SAME state-side protocol as decide()
|
| 74 |
+
// (words + trigram lanes when grams are on); the CLI builds memory
|
| 75 |
+
// states with the same protocol, so both sides of the cosine speak the
|
| 76 |
+
// same encoding. Similarity itself is still settled-field cosine — the
|
| 77 |
+
// grams are fed to the physics, they are never the similarity metric.
|
| 78 |
+
const std::vector<float> fq = fingerprint(s,
|
| 79 |
+
si::norm::field_tokens(si::norm::normalize(query_state),
|
| 80 |
+
si::norm::grams_enabled(),
|
| 81 |
+
[&s](const std::string& w) { return s.has(w); }));
|
| 82 |
+
float qn2 = 0.0f;
|
| 83 |
+
for (float v : fq) qn2 += v * v;
|
| 84 |
+
if (qn2 <= 0.0f) return hits; // query resonates with nothing
|
| 85 |
+
|
| 86 |
+
for (std::size_t m = 0; m < memories.size(); ++m) {
|
| 87 |
+
const std::vector<float> fm = fingerprint(s, memories[m].state);
|
| 88 |
+
float dot = 0.0f;
|
| 89 |
+
for (std::size_t i = 0; i < fq.size() && i < fm.size(); ++i)
|
| 90 |
+
dot += fq[i] * fm[i];
|
| 91 |
+
hits.push_back({m, memories[m].label, dot}); // both normalized => cosine
|
| 92 |
+
}
|
| 93 |
+
std::stable_sort(hits.begin(), hits.end(),
|
| 94 |
+
[](const RecallHit& x, const RecallHit& y) {
|
| 95 |
+
return x.resonance > y.resonance;
|
| 96 |
+
});
|
| 97 |
+
if (static_cast<int>(hits.size()) > top_k) hits.resize(static_cast<std::size_t>(top_k));
|
| 98 |
+
return hits;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
} // namespace recall
|
| 102 |
+
} // namespace syfox
|
engine/core/script.hpp
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// SyFox — script.hpp
|
| 3 |
+
// Multilingual boundary layer, part 1: Unicode script detection.
|
| 4 |
+
//
|
| 5 |
+
// Scope guard (v2.2): this file lives at the INPUT boundary, like
|
| 6 |
+
// normalize.hpp. si_substrate.hpp is untouched — energy, decay, diffusion,
|
| 7 |
+
// lanes, readout all unchanged. What this adds is a deterministic answer to
|
| 8 |
+
// ONE question: "which script family does this text belong to?", so the
|
| 9 |
+
// operator can route queries to the right per-script substrate.
|
| 10 |
+
//
|
| 11 |
+
// Design:
|
| 12 |
+
// * UTF-8 -> codepoints (invalid bytes are separators; never a crash).
|
| 13 |
+
// * every codepoint is classified into one of 35 script families via
|
| 14 |
+
// Unicode block ranges (the same ranges the Unicode Charts use).
|
| 15 |
+
// * detect_script(text) = majority vote over LETTER codepoints.
|
| 16 |
+
// Ties break by table order (deterministic). Pure ASCII is Latin.
|
| 17 |
+
// * No NLP pipeline, no neural net, no pattern matching: a range table
|
| 18 |
+
// and a counter. Every decision reproducible by hand.
|
| 19 |
+
//
|
| 20 |
+
// Coverage: 35 families. The Latin family alone carries 60+ languages;
|
| 21 |
+
// the full table covers 100+ (see README "Multilingual" for the honest
|
| 22 |
+
// per-family language list). A family needs its own TRAINED substrate to
|
| 23 |
+
// answer questions — the router guarantees the query lands on the right
|
| 24 |
+
// one; honest silence still guards untrained vocabularies.
|
| 25 |
+
// ============================================================================
|
| 26 |
+
#pragma once
|
| 27 |
+
#include <cstdint>
|
| 28 |
+
#include <string>
|
| 29 |
+
|
| 30 |
+
namespace si {
|
| 31 |
+
namespace script {
|
| 32 |
+
|
| 33 |
+
// ---------------------------------------------------------------------------
|
| 34 |
+
// Script families (Unicode block lineage). Order matters: it is the
|
| 35 |
+
// deterministic tie-break, and "Unknown" must stay last.
|
| 36 |
+
// ---------------------------------------------------------------------------
|
| 37 |
+
enum class Script {
|
| 38 |
+
Latin, Greek, Cyrillic, Armenian, Hebrew, Arabic, Syriac, Thaana, Nko,
|
| 39 |
+
Devanagari, Bengali, Gurmukhi, Gujarati, Oriya, Tamil, Telugu, Kannada,
|
| 40 |
+
Malayalam, Sinhala, Thai, Lao, Tibetan, Myanmar, Georgian, Khmer,
|
| 41 |
+
Mongolian, Ethiopic, Cherokee, Coptic, Vai, Yi, Bopomofo, Han, Kana,
|
| 42 |
+
Hangul, Unknown
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
inline const char* slug(Script s) {
|
| 46 |
+
switch (s) {
|
| 47 |
+
case Script::Latin: return "latin";
|
| 48 |
+
case Script::Greek: return "greek";
|
| 49 |
+
case Script::Cyrillic: return "cyrillic";
|
| 50 |
+
case Script::Armenian: return "armenian";
|
| 51 |
+
case Script::Hebrew: return "hebrew";
|
| 52 |
+
case Script::Arabic: return "arabic";
|
| 53 |
+
case Script::Syriac: return "syriac";
|
| 54 |
+
case Script::Thaana: return "thaana";
|
| 55 |
+
case Script::Nko: return "nko";
|
| 56 |
+
case Script::Devanagari: return "devanagari";
|
| 57 |
+
case Script::Bengali: return "bengali";
|
| 58 |
+
case Script::Gurmukhi: return "gurmukhi";
|
| 59 |
+
case Script::Gujarati: return "gujarati";
|
| 60 |
+
case Script::Oriya: return "oriya";
|
| 61 |
+
case Script::Tamil: return "tamil";
|
| 62 |
+
case Script::Telugu: return "telugu";
|
| 63 |
+
case Script::Kannada: return "kannada";
|
| 64 |
+
case Script::Malayalam: return "malayalam";
|
| 65 |
+
case Script::Sinhala: return "sinhala";
|
| 66 |
+
case Script::Thai: return "thai";
|
| 67 |
+
case Script::Lao: return "lao";
|
| 68 |
+
case Script::Tibetan: return "tibetan";
|
| 69 |
+
case Script::Myanmar: return "myanmar";
|
| 70 |
+
case Script::Georgian: return "georgian";
|
| 71 |
+
case Script::Khmer: return "khmer";
|
| 72 |
+
case Script::Mongolian: return "mongolian";
|
| 73 |
+
case Script::Ethiopic: return "ethiopic";
|
| 74 |
+
case Script::Cherokee: return "cherokee";
|
| 75 |
+
case Script::Coptic: return "coptic";
|
| 76 |
+
case Script::Vai: return "vai";
|
| 77 |
+
case Script::Yi: return "yi";
|
| 78 |
+
case Script::Bopomofo: return "bopomofo";
|
| 79 |
+
case Script::Han: return "han";
|
| 80 |
+
case Script::Kana: return "kana";
|
| 81 |
+
case Script::Hangul: return "hangul";
|
| 82 |
+
default: return "unknown";
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
inline Script from_slug(const std::string& s) {
|
| 87 |
+
static const struct { const char* name; Script sc; } kTab[] = {
|
| 88 |
+
{"latin", Script::Latin}, {"greek", Script::Greek},
|
| 89 |
+
{"cyrillic", Script::Cyrillic}, {"armenian", Script::Armenian},
|
| 90 |
+
{"hebrew", Script::Hebrew}, {"arabic", Script::Arabic},
|
| 91 |
+
{"syriac", Script::Syriac}, {"thaana", Script::Thaana},
|
| 92 |
+
{"nko", Script::Nko}, {"devanagari", Script::Devanagari},
|
| 93 |
+
{"bengali", Script::Bengali}, {"gurmukhi", Script::Gurmukhi},
|
| 94 |
+
{"gujarati", Script::Gujarati}, {"oriya", Script::Oriya},
|
| 95 |
+
{"tamil", Script::Tamil}, {"telugu", Script::Telugu},
|
| 96 |
+
{"kannada", Script::Kannada}, {"malayalam", Script::Malayalam},
|
| 97 |
+
{"sinhala", Script::Sinhala}, {"thai", Script::Thai},
|
| 98 |
+
{"lao", Script::Lao}, {"tibetan", Script::Tibetan},
|
| 99 |
+
{"myanmar", Script::Myanmar}, {"georgian", Script::Georgian},
|
| 100 |
+
{"khmer", Script::Khmer}, {"mongolian", Script::Mongolian},
|
| 101 |
+
{"ethiopic", Script::Ethiopic}, {"cherokee", Script::Cherokee},
|
| 102 |
+
{"coptic", Script::Coptic}, {"vai", Script::Vai},
|
| 103 |
+
{"yi", Script::Yi}, {"bopomofo", Script::Bopomofo},
|
| 104 |
+
{"han", Script::Han}, {"kana", Script::Kana},
|
| 105 |
+
{"hangul", Script::Hangul},
|
| 106 |
+
};
|
| 107 |
+
for (const auto& e : kTab) if (s == e.name) return e.sc;
|
| 108 |
+
return Script::Unknown;
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
// ---------------------------------------------------------------------------
|
| 112 |
+
// UTF-8 decode: one codepoint per call. Returns bytes consumed (>=1); sets
|
| 113 |
+
// cp to the codepoint, or to 0xFFFFFFFF for a malformed sequence (the caller
|
| 114 |
+
// treats it as a separator — deterministic, never a crash).
|
| 115 |
+
// ---------------------------------------------------------------------------
|
| 116 |
+
inline std::size_t decode_utf8(const std::string& s, std::size_t i,
|
| 117 |
+
std::uint32_t& cp) {
|
| 118 |
+
const unsigned char c = static_cast<unsigned char>(s[i]);
|
| 119 |
+
if (c < 0x80) { cp = c; return 1; }
|
| 120 |
+
std::size_t len = 0; std::uint32_t v = 0;
|
| 121 |
+
if ((c & 0xE0) == 0xC0) { len = 2; v = c & 0x1Fu; }
|
| 122 |
+
else if ((c & 0xF0) == 0xE0) { len = 3; v = c & 0x0Fu; }
|
| 123 |
+
else if ((c & 0xF8) == 0xF0) { len = 4; v = c & 0x07u; }
|
| 124 |
+
else { cp = 0xFFFFFFFFu; return 1; }
|
| 125 |
+
if (i + len > s.size()) { cp = 0xFFFFFFFFu; return 1; }
|
| 126 |
+
for (std::size_t k = 1; k < len; ++k) {
|
| 127 |
+
const unsigned char cc = static_cast<unsigned char>(s[i + k]);
|
| 128 |
+
if ((cc & 0xC0) != 0x80) { cp = 0xFFFFFFFFu; return 1; }
|
| 129 |
+
v = (v << 6) | (cc & 0x3Fu);
|
| 130 |
+
}
|
| 131 |
+
cp = v;
|
| 132 |
+
return len;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
// ---------------------------------------------------------------------------
|
| 136 |
+
// The script range table. Each entry is a Unicode block range mapped to a
|
| 137 |
+
// family. Blocks are scanned linearly — the table is small, calls are per
|
| 138 |
+
// codepoint, and a linear scan keeps the determinism story trivial.
|
| 139 |
+
// ---------------------------------------------------------------------------
|
| 140 |
+
inline Script codepoint_script(std::uint32_t cp) {
|
| 141 |
+
struct R { std::uint32_t lo, hi; Script sc; };
|
| 142 |
+
static const R kRanges[] = {
|
| 143 |
+
// Latin (incl. Extended-A/B, Extended Additional for Vietnamese,
|
| 144 |
+
// IPA extensions, phonetic extensions)
|
| 145 |
+
{0x0041, 0x005A, Script::Latin}, {0x0061, 0x007A, Script::Latin},
|
| 146 |
+
{0x00AA, 0x00AA, Script::Latin}, {0x00BA, 0x00BA, Script::Latin},
|
| 147 |
+
{0x00C0, 0x00D6, Script::Latin}, {0x00D8, 0x00F6, Script::Latin},
|
| 148 |
+
{0x00F8, 0x02B8, Script::Latin}, {0x1D00, 0x1D25, Script::Latin},
|
| 149 |
+
{0x1E00, 0x1EFF, Script::Latin}, {0x2C60, 0x2C7F, Script::Latin},
|
| 150 |
+
{0xA720, 0xA7FF, Script::Latin},
|
| 151 |
+
{0x0370, 0x03FF, Script::Greek}, {0x1F00, 0x1FFF, Script::Greek},
|
| 152 |
+
{0x0400, 0x052F, Script::Cyrillic}, {0x2DE0, 0x2DFF, Script::Cyrillic},
|
| 153 |
+
{0xA640, 0xA69F, Script::Cyrillic},
|
| 154 |
+
{0x0530, 0x058F, Script::Armenian},
|
| 155 |
+
{0x0590, 0x05FF, Script::Hebrew},
|
| 156 |
+
{0x0600, 0x06FF, Script::Arabic}, {0x0750, 0x077F, Script::Arabic},
|
| 157 |
+
{0x08A0, 0x08FF, Script::Arabic}, {0xFB50, 0xFDFF, Script::Arabic},
|
| 158 |
+
{0xFE70, 0xFEFF, Script::Arabic},
|
| 159 |
+
{0x0700, 0x074F, Script::Syriac},
|
| 160 |
+
{0x0780, 0x07BF, Script::Thaana},
|
| 161 |
+
{0x07C0, 0x07FF, Script::Nko},
|
| 162 |
+
{0x0900, 0x097F, Script::Devanagari},
|
| 163 |
+
{0x0980, 0x09FF, Script::Bengali},
|
| 164 |
+
{0x0A00, 0x0A7F, Script::Gurmukhi},
|
| 165 |
+
{0x0A80, 0x0AFF, Script::Gujarati},
|
| 166 |
+
{0x0B00, 0x0B7F, Script::Oriya},
|
| 167 |
+
{0x0B80, 0x0BFF, Script::Tamil},
|
| 168 |
+
{0x0C00, 0x0C7F, Script::Telugu},
|
| 169 |
+
{0x0C80, 0x0CFF, Script::Kannada},
|
| 170 |
+
{0x0D00, 0x0D7F, Script::Malayalam},
|
| 171 |
+
{0x0D80, 0x0DFF, Script::Sinhala},
|
| 172 |
+
{0x0E00, 0x0E7F, Script::Thai},
|
| 173 |
+
{0x0E80, 0x0EFF, Script::Lao},
|
| 174 |
+
{0x0F00, 0x0FFF, Script::Tibetan},
|
| 175 |
+
{0x1000, 0x109F, Script::Myanmar},
|
| 176 |
+
{0x10A0, 0x10FF, Script::Georgian}, {0x2D00, 0x2D2F, Script::Georgian},
|
| 177 |
+
{0x1780, 0x17FF, Script::Khmer},
|
| 178 |
+
{0x1800, 0x18AF, Script::Mongolian},
|
| 179 |
+
{0x1200, 0x137F, Script::Ethiopic}, {0x1380, 0x139F, Script::Ethiopic},
|
| 180 |
+
{0x2D80, 0x2DDF, Script::Ethiopic},
|
| 181 |
+
{0x13A0, 0x13FF, Script::Cherokee},
|
| 182 |
+
{0x2C80, 0x2CFF, Script::Coptic},
|
| 183 |
+
{0xA500, 0xA63F, Script::Vai},
|
| 184 |
+
{0xA000, 0xA48F, Script::Yi},
|
| 185 |
+
{0x3100, 0x312F, Script::Bopomofo}, {0x31A0, 0x31BF, Script::Bopomofo},
|
| 186 |
+
{0x2E80, 0x2EFF, Script::Han}, {0x3400, 0x4DBF, Script::Han},
|
| 187 |
+
{0x4E00, 0x9FFF, Script::Han}, {0xF900, 0xFAFF, Script::Han},
|
| 188 |
+
{0x3040, 0x309F, Script::Kana}, {0x30A0, 0x30FF, Script::Kana},
|
| 189 |
+
{0x31F0, 0x31FF, Script::Kana},
|
| 190 |
+
{0x1100, 0x11FF, Script::Hangul}, {0x3130, 0x318F, Script::Hangul},
|
| 191 |
+
{0xA960, 0xA97F, Script::Hangul}, {0xAC00, 0xD7AF, Script::Hangul},
|
| 192 |
+
};
|
| 193 |
+
for (const auto& r : kRanges)
|
| 194 |
+
if (cp >= r.lo && cp <= r.hi) return r.sc;
|
| 195 |
+
return Script::Unknown;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
inline bool is_letter_cp(std::uint32_t cp) {
|
| 199 |
+
return codepoint_script(cp) != Script::Unknown;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
inline bool is_digit_cp(std::uint32_t cp) {
|
| 203 |
+
// ASCII digits + the fullwidth/decimal digit blocks of major scripts.
|
| 204 |
+
// Digits are script-neutral for token scanning: they attach to the
|
| 205 |
+
// current token segment like v0.1's alnum runs did.
|
| 206 |
+
return (cp >= 0x0030 && cp <= 0x0039)
|
| 207 |
+
|| (cp >= 0x09E6 && cp <= 0x09EF) // Bengali
|
| 208 |
+
|| (cp >= 0x0966 && cp <= 0x096F) // Devanagari
|
| 209 |
+
|| (cp >= 0x0660 && cp <= 0x0669) // Arabic-Indic
|
| 210 |
+
|| (cp >= 0x06F0 && cp <= 0x06F9) // Extended Arabic-Indic
|
| 211 |
+
|| (cp >= 0xFF10 && cp <= 0xFF19); // Fullwidth
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
// ---------------------------------------------------------------------------
|
| 215 |
+
// Dominant-script detection: majority vote over LETTER codepoints of the
|
| 216 |
+
// whole text. Digits and separators are neutral. Ties break by table order
|
| 217 |
+
// (earlier enum value wins) — deterministic. Empty/unknown text -> Latin
|
| 218 |
+
// (the ASCII default the engine has always had).
|
| 219 |
+
// ---------------------------------------------------------------------------
|
| 220 |
+
inline Script detect_script(const std::string& text) {
|
| 221 |
+
long counts[35] = {0}; // one per family
|
| 222 |
+
std::uint32_t cp = 0;
|
| 223 |
+
std::size_t i = 0;
|
| 224 |
+
while (i < text.size()) {
|
| 225 |
+
i += decode_utf8(text, i, cp);
|
| 226 |
+
if (cp == 0xFFFFFFFFu) continue;
|
| 227 |
+
const Script s = codepoint_script(cp);
|
| 228 |
+
if (s != Script::Unknown) ++counts[static_cast<int>(s)];
|
| 229 |
+
}
|
| 230 |
+
long best = 0;
|
| 231 |
+
for (int k = 1; k < 35; ++k) // strict > : earlier wins ties
|
| 232 |
+
if (counts[k] > counts[best]) best = k;
|
| 233 |
+
return counts[best] == 0 ? Script::Latin : static_cast<Script>(best);
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
} // namespace script
|
| 237 |
+
} // namespace si
|
engine/core/si_substrate.hpp
ADDED
|
@@ -0,0 +1,837 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// SyFox — si_substrate.hpp
|
| 3 |
+
// ---------------------------------------------------------------------------
|
| 4 |
+
// THE CORE. A faithful standalone port of the Synthetic-Intelligence
|
| 5 |
+
// physics substrate mechanics (Mr-DS-ML-85/Synthetic-Intelligence, physics.hpp
|
| 6 |
+
// lineage). Nothing here is a transformer, neural network, or pattern-matching
|
| 7 |
+
// classifier. Decisions emerge from field dynamics only:
|
| 8 |
+
//
|
| 9 |
+
// 1. INJECTION — state tokens deposit energy on concept nodes,
|
| 10 |
+
// weighted by acoustic mass (frequent concepts are
|
| 11 |
+
// "heavier" and carry less per-token energy).
|
| 12 |
+
// 2. SETTLE — energy diffuses along Hebbian lanes with decay,
|
| 13 |
+
// iterated K_settle passes; an energy-gated source cap
|
| 14 |
+
// keeps the working set bounded. The SI salience
|
| 15 |
+
// integrator (physics.hpp cavity lineage:
|
| 16 |
+
// s = tanh(s·decay + gain·|motion|)) runs every pass and
|
| 17 |
+
// is observable on every node. Two flags enable the
|
| 18 |
+
// faithful SI selection modes: salience_gating ranks
|
| 19 |
+
// sources by salience instead of raw energy; miller_window
|
| 20 |
+
// samples the live cap from [source_cap-4, source_cap]
|
| 21 |
+
// per decision (TSDA "7 ± 2"; SI draws it from a seeded
|
| 22 |
+
// mt19937, SyFox derives it from the state hash so the
|
| 23 |
+
// same state still settles bit-for-bit). The field stops
|
| 24 |
+
// when the total energy delta drops below eps.
|
| 25 |
+
// 3. READOUT — a resonance sweep reads the settled field at probe
|
| 26 |
+
// nodes (options / anchors / statements). Readout is a
|
| 27 |
+
// measurement of the field, not a classifier.
|
| 28 |
+
// 4. HEBBIAN — labelled experience binds lanes between co-active
|
| 29 |
+
// state and option concepts (fire together, wire
|
| 30 |
+
// together), with weight decay and per-node lane caps.
|
| 31 |
+
// 5. HONEST — if the settled field is below the silence floor the
|
| 32 |
+
// SILENCE substrate reports "no collapse" instead of guessing.
|
| 33 |
+
//
|
| 34 |
+
// Zero dependencies. Deterministic. C++17.
|
| 35 |
+
// ============================================================================
|
| 36 |
+
#pragma once
|
| 37 |
+
#include <algorithm>
|
| 38 |
+
#include <cmath>
|
| 39 |
+
#include <cstdint>
|
| 40 |
+
#if defined(_OPENMP)
|
| 41 |
+
#include <omp.h>
|
| 42 |
+
#endif
|
| 43 |
+
#include <fstream>
|
| 44 |
+
#include <string>
|
| 45 |
+
#include <unordered_map>
|
| 46 |
+
#include <vector>
|
| 47 |
+
|
| 48 |
+
namespace si {
|
| 49 |
+
|
| 50 |
+
using NodeId = std::uint32_t;
|
| 51 |
+
|
| 52 |
+
// ---------------------------------------------------------------------------
|
| 53 |
+
// v3 Milestone 3 — the lane evidence ledger (audit surface, NOT physics).
|
| 54 |
+
// A lane's WEIGHT drives the field (settle/readout) exactly as before; the
|
| 55 |
+
// ledger records HOW a lane earned its weight, so every decision can show
|
| 56 |
+
// its evidence and every derived relation can be audited:
|
| 57 |
+
// support_events — lessons that strengthened this lane (Hebbian binds)
|
| 58 |
+
// counter_events — anti-Hebbian weakenings (disconfirming evidence)
|
| 59 |
+
// first_seq/last_seq — the teach-event window that touched the lane
|
| 60 |
+
// (provenance; full per-lesson ids live in the
|
| 61 |
+
// model's conflicts/ledger files)
|
| 62 |
+
// context — the engine context tag at last touch (model/domain)
|
| 63 |
+
// The ledger never feeds back into settle/readout: it is bookkeeping over
|
| 64 |
+
// the physics, the way a lab notebook accompanies an experiment.
|
| 65 |
+
// ---------------------------------------------------------------------------
|
| 66 |
+
struct LaneEvidence {
|
| 67 |
+
std::uint32_t support_events = 0;
|
| 68 |
+
std::uint32_t counter_events = 0;
|
| 69 |
+
std::uint64_t first_seq = 0;
|
| 70 |
+
std::uint64_t last_seq = 0;
|
| 71 |
+
std::string context;
|
| 72 |
+
};
|
| 73 |
+
|
| 74 |
+
// ---------------------------------------------------------------------------
|
| 75 |
+
struct SubstrateConfig {
|
| 76 |
+
float decay = 0.82f; // per-pass energy retention (damping)
|
| 77 |
+
float diffusion = 0.45f; // fraction of energy that flows along lanes
|
| 78 |
+
int k_settle = 8; // max settle passes
|
| 79 |
+
float eps = 1e-4f; // phase-stability threshold (early stop)
|
| 80 |
+
float source_cap = 24.0f; // max propagation sources per pass, top-K BY ENERGY
|
| 81 |
+
// (SI-inspired bounded working set; fixed by default)
|
| 82 |
+
// -- SI salience lineage (physics.hpp cavity integrator + TSDA SalienceMap) --
|
| 83 |
+
float salience_gain = 0.05f; // SI physics.hpp salience_gain
|
| 84 |
+
float salience_decay = 0.995f; // SI physics.hpp salience_decay
|
| 85 |
+
bool salience_gating = false; // true: rank sources by salience (motion history), not energy
|
| 86 |
+
bool miller_window = false; // true: live cap sampled from [source_cap-4, source_cap]
|
| 87 |
+
// per decision (TSDA live_cap; deterministic per state)
|
| 88 |
+
float silence_floor = 0.05f; // below this total energy => honest silence
|
| 89 |
+
float inject_energy = 1.0f; // energy per fresh token
|
| 90 |
+
float learn_eta = 0.10f; // Hebbian learning rate
|
| 91 |
+
float lane_decay = 0.995f; // per-lesson lane weight decay
|
| 92 |
+
std::size_t lane_cap = 256; // max lanes per node (weakest evicted)
|
| 93 |
+
float hop_coupling = 0.35f; // 1-hop lane contribution at readout
|
| 94 |
+
};
|
| 95 |
+
|
| 96 |
+
inline float fnv1a_hash(const std::string& s) { // deterministic token hash
|
| 97 |
+
std::uint64_t h = 1469598103934665603ull;
|
| 98 |
+
for (unsigned char c : s) { h ^= c; h *= 1099511628211ull; }
|
| 99 |
+
return static_cast<float>(h & 0xFFFFFFull);
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
// ---------------------------------------------------------------------------
|
| 103 |
+
// ConceptField — nodes, lanes, and the field dynamics over them.
|
| 104 |
+
// ---------------------------------------------------------------------------
|
| 105 |
+
class Substrate {
|
| 106 |
+
public:
|
| 107 |
+
explicit Substrate(SubstrateConfig cfg = {}) : cfg_(cfg) {}
|
| 108 |
+
|
| 109 |
+
// -- vocabulary ---------------------------------------------------------
|
| 110 |
+
NodeId intern(const std::string& concept) {
|
| 111 |
+
auto it = index_.find(concept);
|
| 112 |
+
if (it != index_.end()) { nodes_[it->second].mass += 1.0f; return it->second; }
|
| 113 |
+
NodeId id = static_cast<NodeId>(nodes_.size());
|
| 114 |
+
index_.emplace(concept, id);
|
| 115 |
+
// occurrence mass: a LINEAR count of intern() calls (not log-compressed).
|
| 116 |
+
// The sub-linear behavior lives at the USE sites: injection deposits
|
| 117 |
+
// energy/sqrt(mass) and Hebbian bind strength scales by 1/sqrt(mass),
|
| 118 |
+
// so heavy concepts move less.
|
| 119 |
+
nodes_.push_back(Node{concept, 1.0f, 0.0f, 0.0f});
|
| 120 |
+
csr_dirty_ = true; // node count changed (M5 CSR mirror)
|
| 121 |
+
return id;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
bool has(const std::string& c) const { return index_.count(c) != 0; }
|
| 125 |
+
NodeId find(const std::string& c) const { return index_.at(c); }
|
| 126 |
+
std::size_t node_count() const { return nodes_.size(); }
|
| 127 |
+
std::size_t lane_count() const {
|
| 128 |
+
std::size_t n = 0;
|
| 129 |
+
for (const auto& kv : out_) n += kv.second.size();
|
| 130 |
+
return n;
|
| 131 |
+
}
|
| 132 |
+
std::size_t readout_neighbours(NodeId a) const {
|
| 133 |
+
auto it = out_.find(a);
|
| 134 |
+
return it == out_.end() ? 0 : it->second.size();
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
// -- Hebbian lane binding (fire together -> wire together) ---------------
|
| 138 |
+
void bind(NodeId a, NodeId b, float w) {
|
| 139 |
+
if (a == b || w <= 0.0f) return;
|
| 140 |
+
add_lane(a, b, w);
|
| 141 |
+
add_lane(b, a, w);
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
void add_lane(NodeId a, NodeId b, float w) {
|
| 145 |
+
auto& lanes = out_[a];
|
| 146 |
+
for (auto& l : lanes)
|
| 147 |
+
if (l.first == b) { l.second = std::min(4.0f, std::max(0.0f, l.second + w)); csr_dirty_ = true; return; }
|
| 148 |
+
if (w > 0.0f) {
|
| 149 |
+
lanes.emplace_back(b, w);
|
| 150 |
+
csr_dirty_ = true;
|
| 151 |
+
if (lanes.size() > cfg_.lane_cap) { // evict weakest lane
|
| 152 |
+
auto weakest = std::min_element(lanes.begin(), lanes.end(),
|
| 153 |
+
[](const auto& x, const auto& y){ return x.second < y.second; });
|
| 154 |
+
lanes.erase(weakest);
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
// subtract weight from a lane; a lane whose weight hits zero dissolves
|
| 160 |
+
void scale_lane(NodeId a, NodeId b, float dw) {
|
| 161 |
+
auto it = out_.find(a);
|
| 162 |
+
if (it == out_.end()) return;
|
| 163 |
+
auto& lanes = it->second;
|
| 164 |
+
for (std::size_t i = 0; i < lanes.size(); ++i)
|
| 165 |
+
if (lanes[i].first == b) {
|
| 166 |
+
lanes[i].second = std::max(0.0f, lanes[i].second + dw);
|
| 167 |
+
if (lanes[i].second <= 0.0f) lanes.erase(lanes.begin() + static_cast<std::ptrdiff_t>(i));
|
| 168 |
+
csr_dirty_ = true;
|
| 169 |
+
return;
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
// -- INJECTION ------------------------------------------------------------
|
| 174 |
+
// Fresh tokens carry inject_energy each, damped by acoustic mass so that
|
| 175 |
+
// frequent concepts cannot flood the field.
|
| 176 |
+
void inject(const std::vector<std::string>& tokens, float energy = 0.0f) {
|
| 177 |
+
if (energy <= 0.0f) energy = cfg_.inject_energy;
|
| 178 |
+
for (const auto& t : tokens) {
|
| 179 |
+
if (!has(t)) continue; // unknown concepts stay dark
|
| 180 |
+
NodeId id = find(t);
|
| 181 |
+
Node& n = nodes_[id];
|
| 182 |
+
float mass_damp = 1.0f / std::sqrt(n.mass); // heavy => less per-token
|
| 183 |
+
n.energy += energy * mass_damp;
|
| 184 |
+
n.salience = 1.0f; // TSDA: spike to ceiling on touch
|
| 185 |
+
state_hash_ = state_hash_ * 1099511628211ull
|
| 186 |
+
+ static_cast<std::uint64_t>(fnv1a_hash(t)); // decision fingerprint
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
// salience of a concept (SI integrator state; diagnostic + test surface)
|
| 191 |
+
float node_salience(const std::string& c) const {
|
| 192 |
+
auto it = index_.find(c);
|
| 193 |
+
return it == index_.end() ? 0.0f : nodes_[it->second].salience;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
// the source cap actually used by the last settle() (sampled value when
|
| 197 |
+
// miller_window is on; otherwise always config().source_cap)
|
| 198 |
+
float last_source_cap() const { return last_cap_; }
|
| 199 |
+
|
| 200 |
+
// -- SETTLE ---------------------------------------------------------------
|
| 201 |
+
// One pass = dissipative diffusion along lanes + source gating.
|
| 202 |
+
// Energy is CONSERVED per pass up to decay: each node retains
|
| 203 |
+
// (1 - diffusion) of its (decayed) energy and flows `diffusion` out along
|
| 204 |
+
// its lanes, split proportionally to lane weight. The source cap GATES
|
| 205 |
+
// propagation: only the top-`cap` active nodes send energy each pass —
|
| 206 |
+
// ranked by energy by default, or by salience (motion history) when
|
| 207 |
+
// salience_gating is on. Gated nodes keep their energy (readout-visible)
|
| 208 |
+
// but stay silent as sources — bounded working set, nothing is
|
| 209 |
+
// annihilated. Salience itself integrates every pass exactly as the SI
|
| 210 |
+
// cavity physics does: s = tanh(s·decay + gain·|ΔE|); a node at rest is
|
| 211 |
+
// an exact fixed point (tanh(0) = 0), mirroring SI's sparsity guard.
|
| 212 |
+
void settle() {
|
| 213 |
+
std::vector<float> next(nodes_.size(), 0.0f);
|
| 214 |
+
std::vector<std::size_t> active;
|
| 215 |
+
|
| 216 |
+
// M5: build/refresh the CSR mirror if the fabric moved. The build is
|
| 217 |
+
// order-preserving (per-source vector copied verbatim), so switching
|
| 218 |
+
// between map iteration and CSR iteration cannot change a single float.
|
| 219 |
+
if (csr_dirty_) build_csr();
|
| 220 |
+
|
| 221 |
+
// M5: parallel-settle buffers. Allocated once per call, reused across
|
| 222 |
+
// passes. Determinism contract: static schedule partitions sources
|
| 223 |
+
// into contiguous ascending chunks; per-thread scatter buffers are
|
| 224 |
+
// combined in ascending thread order; therefore every next[i]
|
| 225 |
+
// accumulates contributions in ascending SOURCE order — exactly the
|
| 226 |
+
// sequential order. Bit-identical, test-verified.
|
| 227 |
+
int nthreads = 1;
|
| 228 |
+
#if defined(_OPENMP)
|
| 229 |
+
if (parallel_settle_) nthreads = omp_get_max_threads();
|
| 230 |
+
if (nthreads > static_cast<int>(nodes_.size())) nthreads = nodes_.size() > 0 ? static_cast<int>(nodes_.size()) : 1;
|
| 231 |
+
#endif
|
| 232 |
+
std::vector<std::vector<float>> thread_bufs(
|
| 233 |
+
static_cast<std::size_t>(nthreads > 1 ? nthreads : 0),
|
| 234 |
+
std::vector<float>(nodes_.size(), 0.0f)); // each buffer is n floats, zeroed
|
| 235 |
+
|
| 236 |
+
// Live source cap (TSDA live_cap lineage): when miller_window is on,
|
| 237 |
+
// the working set is drawn from [source_cap-4, source_cap] each
|
| 238 |
+
// decision instead of being pinned — narrow focus some decisions,
|
| 239 |
+
// broad others. SI samples a seeded mt19937 per tick; SyFox derives
|
| 240 |
+
// the draw from the decision's state hash, so reproducibility holds:
|
| 241 |
+
// same state -> same cap -> same field, bit for bit.
|
| 242 |
+
float cap = cfg_.source_cap;
|
| 243 |
+
if (cfg_.miller_window) {
|
| 244 |
+
std::uint32_t hi = static_cast<std::uint32_t>(std::max(1.0f, cfg_.source_cap));
|
| 245 |
+
std::uint32_t lo = (hi >= 5) ? hi - 4 : 1;
|
| 246 |
+
cap = static_cast<float>(lo + (state_hash_ % (hi - lo + 1)));
|
| 247 |
+
}
|
| 248 |
+
last_cap_ = cap;
|
| 249 |
+
const std::size_t cap_n = static_cast<std::size_t>(cap);
|
| 250 |
+
const std::size_t n = nodes_.size();
|
| 251 |
+
for (int pass = 0; pass < cfg_.k_settle; ++pass) {
|
| 252 |
+
float total_before = 0.0f;
|
| 253 |
+
for (const auto& nd : nodes_) total_before += nd.energy;
|
| 254 |
+
if (total_before <= 0.0f) return; // nothing to settle
|
| 255 |
+
|
| 256 |
+
std::fill(next.begin(), next.end(), 0.0f);
|
| 257 |
+
for (auto& tb : thread_bufs) std::fill(tb.begin(), tb.end(), 0.0f);
|
| 258 |
+
active.clear();
|
| 259 |
+
for (std::size_t i = 0; i < n; ++i)
|
| 260 |
+
if (nodes_[i].energy > 1e-7f) active.push_back(i);
|
| 261 |
+
|
| 262 |
+
// source gating: at most `cap` sources per pass (ties break by
|
| 263 |
+
// vocabulary order — deterministic)
|
| 264 |
+
if (active.size() > cap_n) {
|
| 265 |
+
std::nth_element(active.begin(),
|
| 266 |
+
active.begin() + static_cast<std::ptrdiff_t>(cap_n),
|
| 267 |
+
active.end(), [&](std::size_t a, std::size_t b){
|
| 268 |
+
return cfg_.salience_gating
|
| 269 |
+
? nodes_[a].salience > nodes_[b].salience
|
| 270 |
+
: nodes_[a].energy > nodes_[b].energy; });
|
| 271 |
+
active.resize(cap_n);
|
| 272 |
+
}
|
| 273 |
+
std::vector<char> is_source(n, 0);
|
| 274 |
+
for (std::size_t i : active) is_source[i] = 1;
|
| 275 |
+
|
| 276 |
+
// -- diffusion pass (CSR slices; optional deterministic OMP) ----
|
| 277 |
+
#if defined(_OPENMP)
|
| 278 |
+
#pragma omp parallel if (nthreads > 1) num_threads(nthreads)
|
| 279 |
+
#endif
|
| 280 |
+
{
|
| 281 |
+
float* mybuf = nullptr;
|
| 282 |
+
#if defined(_OPENMP)
|
| 283 |
+
const int tid = omp_get_thread_num();
|
| 284 |
+
if (nthreads > 1) mybuf = thread_bufs[static_cast<std::size_t>(tid)].data();
|
| 285 |
+
#pragma omp for schedule(static)
|
| 286 |
+
#endif
|
| 287 |
+
for (std::ptrdiff_t ii = 0; ii < static_cast<std::ptrdiff_t>(n); ++ii) {
|
| 288 |
+
const std::size_t i = static_cast<std::size_t>(ii);
|
| 289 |
+
const Node& nd = nodes_[i];
|
| 290 |
+
if (nd.energy <= 0.0f) continue;
|
| 291 |
+
float* scatter = mybuf ? mybuf : next.data();
|
| 292 |
+
if (!is_source[i]) { scatter[i] += nd.energy * cfg_.decay; continue; } // gated: decay only
|
| 293 |
+
const std::size_t b = csr_off_[i], e = csr_off_[i + 1];
|
| 294 |
+
float out_w = 0.0f;
|
| 295 |
+
for (std::size_t k = b; k < e; ++k) out_w += csr_w_[k];
|
| 296 |
+
float retained = (out_w > 0.0f) ? (1.0f - cfg_.diffusion) : 1.0f;
|
| 297 |
+
scatter[i] += nd.energy * cfg_.decay * retained; // damped self-retention
|
| 298 |
+
if (out_w > 0.0f) {
|
| 299 |
+
const float flow = nd.energy * cfg_.decay * cfg_.diffusion;
|
| 300 |
+
for (std::size_t k = b; k < e; ++k)
|
| 301 |
+
scatter[csr_dst_[k]] += flow * (csr_w_[k] / out_w);
|
| 302 |
+
}
|
| 303 |
+
}
|
| 304 |
+
}
|
| 305 |
+
if (nthreads > 1) { // fixed thread-order combine
|
| 306 |
+
for (const auto& tb : thread_bufs)
|
| 307 |
+
for (std::size_t i = 0; i < n; ++i) next[i] += tb[i];
|
| 308 |
+
}
|
| 309 |
+
// SI cavity salience integrator: s = tanh(s·decay + gain·|ΔE|).
|
| 310 |
+
// Motion proxy is how much energy moved through the node this
|
| 311 |
+
// pass. Updated before the energies are committed, so the next
|
| 312 |
+
// pass's source ranking sees it. Element-wise (no accumulation):
|
| 313 |
+
// parallel-safe without touching the determinism contract.
|
| 314 |
+
#if defined(_OPENMP)
|
| 315 |
+
#pragma omp parallel for schedule(static) if (nthreads > 1)
|
| 316 |
+
#endif
|
| 317 |
+
for (std::ptrdiff_t ii = 0; ii < static_cast<std::ptrdiff_t>(n); ++ii) {
|
| 318 |
+
const std::size_t i = static_cast<std::size_t>(ii);
|
| 319 |
+
if (nodes_[i].energy <= 0.0f && next[i] <= 0.0f) continue;
|
| 320 |
+
const float motion = std::fabs(next[i] - nodes_[i].energy);
|
| 321 |
+
nodes_[i].salience = std::tanh(nodes_[i].salience * cfg_.salience_decay
|
| 322 |
+
+ cfg_.salience_gain * motion);
|
| 323 |
+
}
|
| 324 |
+
#if defined(_OPENMP)
|
| 325 |
+
#pragma omp parallel for schedule(static) if (nthreads > 1)
|
| 326 |
+
#endif
|
| 327 |
+
for (std::ptrdiff_t ii = 0; ii < static_cast<std::ptrdiff_t>(n); ++ii)
|
| 328 |
+
nodes_[ii].energy = next[ii];
|
| 329 |
+
|
| 330 |
+
float total_after = 0.0f;
|
| 331 |
+
for (const auto& nd : nodes_) total_after += nd.energy;
|
| 332 |
+
if (total_before - total_after < cfg_.eps) break; // relaxed
|
| 333 |
+
}
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
// -- READOUT (resonance sweep, two lanes) -----------------------------------
|
| 337 |
+
// Both lanes are field measurements — no weights fitted, no classes exist.
|
| 338 |
+
//
|
| 339 |
+
// SPECIFIC — "mean lane support": rewards precise coupling. A node bound
|
| 340 |
+
// diffusely to half the vocabulary must not read hotter than a node
|
| 341 |
+
// bound exactly to this state's concepts. Used for Choice/Score where
|
| 342 |
+
// the engine must pick THE best-matching option.
|
| 343 |
+
//
|
| 344 |
+
// SUPPORT — "active lane mass": rewards breadth of corroboration. A
|
| 345 |
+
// statement (Noul) may be supported by many partial lanes; what matters
|
| 346 |
+
// is how much lane-connected energy the field offers it. Used for Noul.
|
| 347 |
+
enum class ReadoutMode { Specific, Support };
|
| 348 |
+
|
| 349 |
+
float readout(const std::vector<std::string>& probe,
|
| 350 |
+
ReadoutMode mode = ReadoutMode::Specific) const {
|
| 351 |
+
float r = 0.0f;
|
| 352 |
+
for (const auto& t : probe) {
|
| 353 |
+
auto it = index_.find(t);
|
| 354 |
+
if (it == index_.end()) continue;
|
| 355 |
+
const Node& n = nodes_[it->second];
|
| 356 |
+
r += n.energy;
|
| 357 |
+
const auto lane_it = out_.find(it->second);
|
| 358 |
+
if (lane_it == out_.end() || lane_it->second.empty()) continue;
|
| 359 |
+
if (mode == ReadoutMode::Specific) {
|
| 360 |
+
float wsum = 0.0f, flow = 0.0f;
|
| 361 |
+
for (const auto& lane : lane_it->second) {
|
| 362 |
+
wsum += lane.second;
|
| 363 |
+
flow += lane.second * nodes_[lane.first].energy;
|
| 364 |
+
}
|
| 365 |
+
if (wsum > 0.0f) r += cfg_.hop_coupling * flow / wsum;
|
| 366 |
+
} else { // Support: active lane mass
|
| 367 |
+
for (const auto& lane : lane_it->second)
|
| 368 |
+
r += cfg_.hop_coupling * lane.second * nodes_[lane.first].energy;
|
| 369 |
+
}
|
| 370 |
+
}
|
| 371 |
+
return r;
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
float total_energy() const {
|
| 375 |
+
float s = 0.0f;
|
| 376 |
+
for (const auto& n : nodes_) s += n.energy;
|
| 377 |
+
return s;
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
float node_energy(NodeId id) const {
|
| 381 |
+
return id < nodes_.size() ? nodes_[id].energy : 0.0f;
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
// acoustic mass (occurrence count); derivation uses the same 1/sqrt(mass)
|
| 385 |
+
// damping law the field applies at its use sites, so hub-mediated
|
| 386 |
+
// composition is suppressed exactly like hub-mediated energy flow
|
| 387 |
+
float node_mass(NodeId id) const {
|
| 388 |
+
return id < nodes_.size() ? nodes_[id].mass : 1.0f;
|
| 389 |
+
}
|
| 390 |
+
|
| 391 |
+
bool silent() const { return total_energy() < cfg_.silence_floor; }
|
| 392 |
+
|
| 393 |
+
// -- HONEST SILENCE reset ---------------------------------------------------
|
| 394 |
+
void reset_field() {
|
| 395 |
+
for (auto& n : nodes_) { n.energy = 0.0f; n.salience = 0.0f; }
|
| 396 |
+
state_hash_ = 0;
|
| 397 |
+
}
|
| 398 |
+
|
| 399 |
+
// -- ANTI-HEBBIAN WEAKENING --------------------------------------------------
|
| 400 |
+
// Counter-evidence: unbind lanes between active concepts and an outcome
|
| 401 |
+
// (used for Noul "false" lessons so disconfirming routes fade).
|
| 402 |
+
void weaken(const std::vector<std::string>& active_state,
|
| 403 |
+
const std::vector<std::string>& outcome, float eta_scale = 1.0f) {
|
| 404 |
+
for (const auto& ta : active_state) {
|
| 405 |
+
if (!has(ta)) continue;
|
| 406 |
+
for (const auto& tb : outcome) {
|
| 407 |
+
if (!has(tb)) continue;
|
| 408 |
+
NodeId a = find(ta), b = find(tb);
|
| 409 |
+
scale_lane(a, b, -cfg_.learn_eta * eta_scale);
|
| 410 |
+
scale_lane(b, a, -cfg_.learn_eta * eta_scale);
|
| 411 |
+
}
|
| 412 |
+
}
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
// -- HEBBIAN LESSON ----------------------------------------------------------
|
| 416 |
+
// Strengthen lanes between currently-active state concepts and the
|
| 417 |
+
// concepts of a rewarded outcome; decay every lane slightly so unused
|
| 418 |
+
// routes fade. This is how SyFox learns: substrate rewiring, not fitting.
|
| 419 |
+
void hebbian_lesson(const std::vector<std::string>& active_state,
|
| 420 |
+
const std::vector<std::string>& outcome,
|
| 421 |
+
float eta_scale = 1.0f) {
|
| 422 |
+
std::vector<NodeId> s_ids, o_ids;
|
| 423 |
+
for (const auto& t : active_state)
|
| 424 |
+
if (has(t)) s_ids.push_back(find(t));
|
| 425 |
+
for (const auto& t : outcome) {
|
| 426 |
+
intern(t); // outcome concepts join the field
|
| 427 |
+
o_ids.push_back(find(t));
|
| 428 |
+
}
|
| 429 |
+
for (NodeId a : s_ids)
|
| 430 |
+
for (NodeId b : o_ids) {
|
| 431 |
+
float wa = 1.0f / std::sqrt(nodes_[a].mass);
|
| 432 |
+
float wb = 1.0f / std::sqrt(nodes_[b].mass);
|
| 433 |
+
bind(a, b, cfg_.learn_eta * eta_scale * (wa + wb));
|
| 434 |
+
}
|
| 435 |
+
enforce_lane_decay();
|
| 436 |
+
}
|
| 437 |
+
|
| 438 |
+
// -- LANE EVIDENCE LEDGER (v3 Milestone 3; bookkeeping, not physics) ------
|
| 439 |
+
// record_support / record_counter: called by the ENGINE around its teach
|
| 440 |
+
// events. seq = the engine's monotonic teach counter; context = engine tag.
|
| 441 |
+
void record_support(NodeId a, NodeId b, std::uint64_t seq, const std::string& context) {
|
| 442 |
+
LaneEvidence& e = lane_evidence_[lane_key(a, b)];
|
| 443 |
+
++e.support_events;
|
| 444 |
+
e.last_seq = seq;
|
| 445 |
+
if (e.first_seq == 0) e.first_seq = seq;
|
| 446 |
+
e.context = context;
|
| 447 |
+
}
|
| 448 |
+
void record_counter(NodeId a, NodeId b, std::uint64_t seq, const std::string& context) {
|
| 449 |
+
LaneEvidence& e = lane_evidence_[lane_key(a, b)];
|
| 450 |
+
++e.counter_events;
|
| 451 |
+
e.last_seq = seq;
|
| 452 |
+
if (e.first_seq == 0) e.first_seq = seq;
|
| 453 |
+
e.context = context;
|
| 454 |
+
}
|
| 455 |
+
bool evidence_of(NodeId a, NodeId b, LaneEvidence& out) const {
|
| 456 |
+
auto it = lane_evidence_.find(lane_key(a, b));
|
| 457 |
+
if (it == lane_evidence_.end()) return false;
|
| 458 |
+
out = it->second;
|
| 459 |
+
return true;
|
| 460 |
+
}
|
| 461 |
+
std::size_t evidence_count() const { return lane_evidence_.size(); }
|
| 462 |
+
|
| 463 |
+
// -- persistence (binary, deterministic) -------------------------------------
|
| 464 |
+
void save(const std::string& path) const {
|
| 465 |
+
std::ofstream f(path, std::ios::binary);
|
| 466 |
+
std::uint32_t n = static_cast<std::uint32_t>(nodes_.size());
|
| 467 |
+
f.write(reinterpret_cast<const char*>(&n), 4);
|
| 468 |
+
for (const auto& node : nodes_) {
|
| 469 |
+
std::uint32_t len = static_cast<std::uint32_t>(node.concept.size());
|
| 470 |
+
f.write(reinterpret_cast<const char*>(&len), 4);
|
| 471 |
+
f.write(node.concept.data(), len);
|
| 472 |
+
f.write(reinterpret_cast<const char*>(&node.mass), 4);
|
| 473 |
+
}
|
| 474 |
+
std::uint32_t lanes = 0;
|
| 475 |
+
for (const auto& kv : out_) lanes += static_cast<std::uint32_t>(kv.second.size());
|
| 476 |
+
f.write(reinterpret_cast<const char*>(&lanes), 4);
|
| 477 |
+
for (const auto& kv : out_)
|
| 478 |
+
for (const auto& l : kv.second) {
|
| 479 |
+
f.write(reinterpret_cast<const char*>(&kv.first), 4);
|
| 480 |
+
f.write(reinterpret_cast<const char*>(&l.first), 4);
|
| 481 |
+
f.write(reinterpret_cast<const char*>(&l.second), 4);
|
| 482 |
+
}
|
| 483 |
+
// v2 provenance tail — old (v1) files simply end here; load() detects EOF.
|
| 484 |
+
std::uint32_t dc = static_cast<std::uint32_t>(derived_gen_.size());
|
| 485 |
+
f.write(reinterpret_cast<const char*>(&dc), 4);
|
| 486 |
+
for (const auto& kv : derived_gen_) {
|
| 487 |
+
std::uint32_t a = static_cast<std::uint32_t>(kv.first >> 32);
|
| 488 |
+
std::uint32_t b = static_cast<std::uint32_t>(kv.first & 0xffffffffull);
|
| 489 |
+
f.write(reinterpret_cast<const char*>(&a), 4);
|
| 490 |
+
f.write(reinterpret_cast<const char*>(&b), 4);
|
| 491 |
+
f.write(reinterpret_cast<const char*>(&kv.second), 4);
|
| 492 |
+
}
|
| 493 |
+
// v3 evidence tail — v2 files end here; load() detects EOF.
|
| 494 |
+
std::uint32_t ec = static_cast<std::uint32_t>(lane_evidence_.size());
|
| 495 |
+
f.write(reinterpret_cast<const char*>(&ec), 4);
|
| 496 |
+
for (const auto& kv : lane_evidence_) {
|
| 497 |
+
std::uint32_t a = static_cast<std::uint32_t>(kv.first >> 32);
|
| 498 |
+
std::uint32_t b = static_cast<std::uint32_t>(kv.first & 0xffffffffull);
|
| 499 |
+
f.write(reinterpret_cast<const char*>(&a), 4);
|
| 500 |
+
f.write(reinterpret_cast<const char*>(&b), 4);
|
| 501 |
+
f.write(reinterpret_cast<const char*>(&kv.second.support_events), 4);
|
| 502 |
+
f.write(reinterpret_cast<const char*>(&kv.second.counter_events), 4);
|
| 503 |
+
f.write(reinterpret_cast<const char*>(&kv.second.first_seq), 8);
|
| 504 |
+
f.write(reinterpret_cast<const char*>(&kv.second.last_seq), 8);
|
| 505 |
+
std::uint32_t clen = static_cast<std::uint32_t>(kv.second.context.size());
|
| 506 |
+
f.write(reinterpret_cast<const char*>(&clen), 4);
|
| 507 |
+
if (clen) f.write(kv.second.context.data(), clen);
|
| 508 |
+
}
|
| 509 |
+
}
|
| 510 |
+
|
| 511 |
+
void load(const std::string& path) {
|
| 512 |
+
std::ifstream f(path, std::ios::binary);
|
| 513 |
+
if (!f) return;
|
| 514 |
+
nodes_.clear(); index_.clear(); out_.clear();
|
| 515 |
+
csr_dirty_ = true;
|
| 516 |
+
std::uint32_t n = 0; f.read(reinterpret_cast<char*>(&n), 4);
|
| 517 |
+
nodes_.reserve(n);
|
| 518 |
+
for (std::uint32_t i = 0; i < n; ++i) {
|
| 519 |
+
std::uint32_t len = 0; f.read(reinterpret_cast<char*>(&len), 4);
|
| 520 |
+
std::string c(len, '\0'); f.read(c.data(), len);
|
| 521 |
+
float mass = 0; f.read(reinterpret_cast<char*>(&mass), 4);
|
| 522 |
+
index_.emplace(c, static_cast<NodeId>(nodes_.size()));
|
| 523 |
+
nodes_.push_back(Node{c, mass, 0.0f, 0.0f});
|
| 524 |
+
}
|
| 525 |
+
std::uint32_t lanes = 0; f.read(reinterpret_cast<char*>(&lanes), 4);
|
| 526 |
+
for (std::uint32_t i = 0; i < lanes; ++i) {
|
| 527 |
+
NodeId a = 0, b = 0; float w = 0;
|
| 528 |
+
f.read(reinterpret_cast<char*>(&a), 4);
|
| 529 |
+
f.read(reinterpret_cast<char*>(&b), 4);
|
| 530 |
+
f.read(reinterpret_cast<char*>(&w), 4);
|
| 531 |
+
out_[a].emplace_back(b, w);
|
| 532 |
+
}
|
| 533 |
+
// v2 provenance tail (optional): v1 files hit EOF here and stay clean.
|
| 534 |
+
std::uint32_t dc = 0;
|
| 535 |
+
if (f.read(reinterpret_cast<char*>(&dc), 4)) {
|
| 536 |
+
for (std::uint32_t i = 0; i < dc; ++i) {
|
| 537 |
+
std::uint32_t a = 0, b = 0, g = 0;
|
| 538 |
+
if (!f.read(reinterpret_cast<char*>(&a), 4)) break;
|
| 539 |
+
if (!f.read(reinterpret_cast<char*>(&b), 4)) break;
|
| 540 |
+
if (!f.read(reinterpret_cast<char*>(&g), 4)) break;
|
| 541 |
+
derived_gen_.emplace(lane_key(static_cast<NodeId>(a), static_cast<NodeId>(b)), g);
|
| 542 |
+
}
|
| 543 |
+
}
|
| 544 |
+
// v3 evidence tail (optional): v2 files hit EOF here and stay clean.
|
| 545 |
+
std::uint32_t ec = 0;
|
| 546 |
+
if (f.read(reinterpret_cast<char*>(&ec), 4)) {
|
| 547 |
+
for (std::uint32_t i = 0; i < ec; ++i) {
|
| 548 |
+
std::uint32_t a = 0, b = 0, sup = 0, cnt = 0, clen = 0;
|
| 549 |
+
std::uint64_t fs = 0, ls = 0;
|
| 550 |
+
if (!f.read(reinterpret_cast<char*>(&a), 4)) break;
|
| 551 |
+
if (!f.read(reinterpret_cast<char*>(&b), 4)) break;
|
| 552 |
+
if (!f.read(reinterpret_cast<char*>(&sup), 4)) break;
|
| 553 |
+
if (!f.read(reinterpret_cast<char*>(&cnt), 4)) break;
|
| 554 |
+
if (!f.read(reinterpret_cast<char*>(&fs), 8)) break;
|
| 555 |
+
if (!f.read(reinterpret_cast<char*>(&ls), 8)) break;
|
| 556 |
+
if (!f.read(reinterpret_cast<char*>(&clen), 4)) break;
|
| 557 |
+
std::string ctx(clen, '\0');
|
| 558 |
+
if (clen && !f.read(ctx.data(), clen)) break;
|
| 559 |
+
LaneEvidence e;
|
| 560 |
+
e.support_events = sup; e.counter_events = cnt;
|
| 561 |
+
e.first_seq = fs; e.last_seq = ls; e.context = ctx;
|
| 562 |
+
lane_evidence_[lane_key(static_cast<NodeId>(a), static_cast<NodeId>(b))] = e;
|
| 563 |
+
}
|
| 564 |
+
}
|
| 565 |
+
}
|
| 566 |
+
|
| 567 |
+
const SubstrateConfig& config() const { return cfg_; }
|
| 568 |
+
|
| 569 |
+
// -- LANE PROVENANCE + SURGERY (derivation-layer surface, see derive.hpp) --
|
| 570 |
+
// Derived lanes are laid by rule composition over existing fabric, not by
|
| 571 |
+
// direct experience. They carry a generation counter: observed (Hebbian /
|
| 572 |
+
// human-promoted) lanes are premise-grade (generation 0) and never lose
|
| 573 |
+
// that grade; each composition step adds one generation. The generation
|
| 574 |
+
// cap and use-time re-verification live in derive.hpp.
|
| 575 |
+
void bind_derived(NodeId a, NodeId b, float w, std::uint32_t gen) {
|
| 576 |
+
if (a == b || w <= 0.0f) return;
|
| 577 |
+
set_lane_derived(a, b, w, gen);
|
| 578 |
+
set_lane_derived(b, a, w, gen);
|
| 579 |
+
}
|
| 580 |
+
|
| 581 |
+
// Verifier-side weight set: assign exactly (down too), dissolve at zero.
|
| 582 |
+
// Only meaningful for derived lanes; observed lanes are never touched by
|
| 583 |
+
// callers (composition uses bind_derived, which is set-never-weaken).
|
| 584 |
+
void set_derived_weight(NodeId a, NodeId b, float w) {
|
| 585 |
+
auto it = out_.find(a);
|
| 586 |
+
if (it == out_.end()) return;
|
| 587 |
+
for (auto& l : it->second) {
|
| 588 |
+
if (l.first == b) {
|
| 589 |
+
if (w <= 0.0f) { dissolve_lane(a, b); return; }
|
| 590 |
+
l.second = std::min(4.0f, w);
|
| 591 |
+
csr_dirty_ = true;
|
| 592 |
+
// keep symmetry: the mirror lane tracks the same evidence
|
| 593 |
+
auto mit = out_.find(b);
|
| 594 |
+
if (mit != out_.end())
|
| 595 |
+
for (auto& ml : mit->second)
|
| 596 |
+
if (ml.first == a) { ml.second = l.second; break; }
|
| 597 |
+
return;
|
| 598 |
+
}
|
| 599 |
+
}
|
| 600 |
+
}
|
| 601 |
+
|
| 602 |
+
// Remove a lane (both directions) and its provenance.
|
| 603 |
+
void dissolve_lane(NodeId a, NodeId b) {
|
| 604 |
+
auto erase_one = [](std::vector<std::pair<NodeId, float>>& lanes, NodeId t) {
|
| 605 |
+
for (std::size_t i = 0; i < lanes.size(); ++i)
|
| 606 |
+
if (lanes[i].first == t) { lanes.erase(lanes.begin() + static_cast<std::ptrdiff_t>(i)); return; }
|
| 607 |
+
};
|
| 608 |
+
auto it = out_.find(a);
|
| 609 |
+
if (it != out_.end()) erase_one(it->second, b);
|
| 610 |
+
auto mit = out_.find(b);
|
| 611 |
+
if (mit != out_.end()) erase_one(mit->second, a);
|
| 612 |
+
derived_gen_.erase(lane_key(a, b));
|
| 613 |
+
derived_gen_.erase(lane_key(b, a));
|
| 614 |
+
csr_dirty_ = true;
|
| 615 |
+
}
|
| 616 |
+
|
| 617 |
+
std::uint32_t generation_of(NodeId a, NodeId b) const {
|
| 618 |
+
auto it = derived_gen_.find(lane_key(a, b));
|
| 619 |
+
return it == derived_gen_.end() ? 0u : it->second;
|
| 620 |
+
}
|
| 621 |
+
|
| 622 |
+
float lane_weight(NodeId a, NodeId b) const {
|
| 623 |
+
auto it = out_.find(a);
|
| 624 |
+
if (it == out_.end()) return 0.0f;
|
| 625 |
+
for (const auto& l : it->second) if (l.first == b) return l.second;
|
| 626 |
+
return 0.0f;
|
| 627 |
+
}
|
| 628 |
+
|
| 629 |
+
const std::string& concept_of(NodeId id) const { return nodes_[id].concept; }
|
| 630 |
+
|
| 631 |
+
// Visitor over every lane (a -> b, weight). Directional view of the
|
| 632 |
+
// symmetric fabric: each direction is visited once, like the save format.
|
| 633 |
+
template <class F>
|
| 634 |
+
void for_each_lane(F&& f) const {
|
| 635 |
+
for (const auto& kv : out_)
|
| 636 |
+
for (const auto& l : kv.second) f(kv.first, l.first, l.second);
|
| 637 |
+
}
|
| 638 |
+
|
| 639 |
+
// -- FABRIC SNAPSHOT (transactional derivation surface, see gate.hpp) ------
|
| 640 |
+
// Exact, order-preserving capture of the lane fabric. settle() sums over
|
| 641 |
+
// each node's lane vector in insertion order, so a faithful restore must
|
| 642 |
+
// reproduce that order bit-for-bit: a (a,b,w) set is NOT enough, the
|
| 643 |
+
// per-node vector sequences are the state. Used by the no-regression gate
|
| 644 |
+
// to guarantee "revert" means "decide() output is byte-identical again".
|
| 645 |
+
struct FabricSnapshot {
|
| 646 |
+
std::vector<std::vector<std::pair<NodeId, float>>> adj; // per node, exact order
|
| 647 |
+
std::unordered_map<std::uint64_t, std::uint32_t> gen; // lane_key -> generation
|
| 648 |
+
std::size_t lanes = 0;
|
| 649 |
+
};
|
| 650 |
+
|
| 651 |
+
FabricSnapshot snapshot_fabric() const {
|
| 652 |
+
FabricSnapshot snap;
|
| 653 |
+
snap.adj.resize(nodes_.size());
|
| 654 |
+
for (const auto& kv : out_) {
|
| 655 |
+
if (kv.first >= snap.adj.size()) continue;
|
| 656 |
+
snap.adj[kv.first] = kv.second;
|
| 657 |
+
snap.lanes += kv.second.size();
|
| 658 |
+
}
|
| 659 |
+
snap.gen = derived_gen_;
|
| 660 |
+
return snap;
|
| 661 |
+
}
|
| 662 |
+
|
| 663 |
+
void restore_fabric(const FabricSnapshot& snap) {
|
| 664 |
+
out_.clear();
|
| 665 |
+
for (std::size_t a = 0; a < snap.adj.size(); ++a)
|
| 666 |
+
if (!snap.adj[a].empty()) out_[static_cast<NodeId>(a)] = snap.adj[a];
|
| 667 |
+
derived_gen_ = snap.gen;
|
| 668 |
+
csr_dirty_ = true;
|
| 669 |
+
}
|
| 670 |
+
|
| 671 |
+
void lanes_of(NodeId a, std::vector<std::pair<NodeId, float>>& out_lanes) const {
|
| 672 |
+
auto it = out_.find(a);
|
| 673 |
+
if (it == out_.end()) return;
|
| 674 |
+
out_lanes = it->second;
|
| 675 |
+
}
|
| 676 |
+
|
| 677 |
+
// node-energy injection by id (dreamer probing; no decision fingerprint)
|
| 678 |
+
void inject_energy(NodeId id, float energy) {
|
| 679 |
+
if (id >= nodes_.size() || energy <= 0.0f) return;
|
| 680 |
+
Node& n = nodes_[id];
|
| 681 |
+
n.energy += energy / std::sqrt(n.mass);
|
| 682 |
+
n.salience = 1.0f; // TSDA: spike to ceiling on touch
|
| 683 |
+
}
|
| 684 |
+
|
| 685 |
+
// Runtime selection-mode overrides (CLI surface for the SI-faithful modes).
|
| 686 |
+
// Physics constants stay fixed; only the two gating/window modes are
|
| 687 |
+
// settable, and neither is persisted into substrate.bin — the saved model
|
| 688 |
+
// is mode-neutral, so every binary can replay it under any mode.
|
| 689 |
+
void set_source_modes(bool salience_gating_mode, bool miller_window_mode) {
|
| 690 |
+
cfg_.salience_gating = salience_gating_mode;
|
| 691 |
+
cfg_.miller_window = miller_window_mode;
|
| 692 |
+
}
|
| 693 |
+
|
| 694 |
+
private:
|
| 695 |
+
struct Node { std::string concept; float mass; float energy; float salience; };
|
| 696 |
+
|
| 697 |
+
static std::uint64_t lane_key(NodeId a, NodeId b) {
|
| 698 |
+
return (static_cast<std::uint64_t>(a) << 32) | static_cast<std::uint32_t>(b);
|
| 699 |
+
}
|
| 700 |
+
|
| 701 |
+
// Composition-time lane write: raise-only (never weakens existing fabric),
|
| 702 |
+
// and provenance is recorded once — a lane already premise-grade (laid by
|
| 703 |
+
// experience) keeps generation 0; experience dominates derivation.
|
| 704 |
+
void set_lane_derived(NodeId a, NodeId b, float w, std::uint32_t gen) {
|
| 705 |
+
auto& lanes = out_[a];
|
| 706 |
+
for (auto& l : lanes) {
|
| 707 |
+
if (l.first == b) {
|
| 708 |
+
if (w > l.second) { l.second = std::min(4.0f, w); csr_dirty_ = true; }
|
| 709 |
+
derived_gen_.emplace(lane_key(a, b), gen); // keep first (lowest) grade
|
| 710 |
+
return;
|
| 711 |
+
}
|
| 712 |
+
}
|
| 713 |
+
lanes.emplace_back(b, w);
|
| 714 |
+
csr_dirty_ = true;
|
| 715 |
+
derived_gen_.emplace(lane_key(a, b), gen);
|
| 716 |
+
if (lanes.size() > cfg_.lane_cap) { // evict weakest lane
|
| 717 |
+
auto weakest = std::min_element(lanes.begin(), lanes.end(),
|
| 718 |
+
[](const auto& x, const auto& y){ return x.second < y.second; });
|
| 719 |
+
derived_gen_.erase(lane_key(a, weakest->first));
|
| 720 |
+
lanes.erase(weakest);
|
| 721 |
+
}
|
| 722 |
+
}
|
| 723 |
+
|
| 724 |
+
void enforce_lane_decay() {
|
| 725 |
+
for (auto& kv : out_)
|
| 726 |
+
for (auto& l : kv.second) l.second *= cfg_.lane_decay;
|
| 727 |
+
csr_dirty_ = true;
|
| 728 |
+
}
|
| 729 |
+
|
| 730 |
+
SubstrateConfig cfg_;
|
| 731 |
+
std::unordered_map<std::string, NodeId> index_;
|
| 732 |
+
std::vector<Node> nodes_;
|
| 733 |
+
std::unordered_map<NodeId, std::vector<std::pair<NodeId, float>>> out_;
|
| 734 |
+
// Derivation provenance: lane key -> generation (sparse; observed lanes absent = 0)
|
| 735 |
+
std::unordered_map<std::uint64_t, std::uint32_t> derived_gen_;
|
| 736 |
+
// v3 Milestone 3: audit ledger (support/counter events, provenance window)
|
| 737 |
+
std::unordered_map<std::uint64_t, LaneEvidence> lane_evidence_;
|
| 738 |
+
std::uint64_t state_hash_ = 0; // decision fingerprint for Miller sampling
|
| 739 |
+
float last_cap_ = 0.0f; // cap used by the last settle()
|
| 740 |
+
|
| 741 |
+
// -- M5: CSR MIRROR of the out-lane fabric (settle hot path) -------------
|
| 742 |
+
// Flattened contiguous buffers (offsets + targets + weights) built lazily
|
| 743 |
+
// from out_ and invalidated by every lane/node mutation above. The build
|
| 744 |
+
// copies each source's lane vector VERBATIM, so per-source iteration order
|
| 745 |
+
// is exactly the map order settle() used before: every float sum keeps its
|
| 746 |
+
// exact operand order and results stay bit-identical. This is the
|
| 747 |
+
// cache-friendly layout the GPU design generalizes (ARCHITECTURE.md S15).
|
| 748 |
+
// mutable: a lazy cache — logically const rebuild inside const settle paths.
|
| 749 |
+
mutable std::vector<std::size_t> csr_off_; // nodes_.size()+1
|
| 750 |
+
mutable std::vector<NodeId> csr_dst_;
|
| 751 |
+
mutable std::vector<float> csr_w_;
|
| 752 |
+
mutable bool csr_dirty_ = true;
|
| 753 |
+
bool parallel_settle_ = true; // OMP builds honor this; sequential builds ignore it
|
| 754 |
+
|
| 755 |
+
void build_csr() const {
|
| 756 |
+
const std::size_t n = nodes_.size();
|
| 757 |
+
csr_off_.assign(n + 1, 0);
|
| 758 |
+
for (std::size_t i = 0; i < n; ++i) {
|
| 759 |
+
auto it = out_.find(static_cast<NodeId>(i));
|
| 760 |
+
csr_off_[i + 1] = csr_off_[i] + (it == out_.end() ? 0 : it->second.size());
|
| 761 |
+
}
|
| 762 |
+
csr_dst_.resize(csr_off_[n]);
|
| 763 |
+
csr_w_.resize(csr_off_[n]);
|
| 764 |
+
for (std::size_t i = 0; i < n; ++i) {
|
| 765 |
+
auto it = out_.find(static_cast<NodeId>(i));
|
| 766 |
+
if (it == out_.end()) continue;
|
| 767 |
+
std::size_t k = csr_off_[i];
|
| 768 |
+
for (const auto& lane : it->second) {
|
| 769 |
+
csr_dst_[k] = lane.first;
|
| 770 |
+
csr_w_[k] = lane.second;
|
| 771 |
+
++k;
|
| 772 |
+
}
|
| 773 |
+
}
|
| 774 |
+
csr_dirty_ = false;
|
| 775 |
+
}
|
| 776 |
+
|
| 777 |
+
public:
|
| 778 |
+
// parallel settle toggle (M5): on OMP builds, >1 threads use per-thread
|
| 779 |
+
// scatter buffers combined in fixed thread order — bit-identical to the
|
| 780 |
+
// sequential path (test-verified). Off builds always run sequential.
|
| 781 |
+
void set_parallel_settle(bool on) { parallel_settle_ = on; }
|
| 782 |
+
bool parallel_settle_enabled() const {
|
| 783 |
+
#if defined(_OPENMP)
|
| 784 |
+
return parallel_settle_;
|
| 785 |
+
#else
|
| 786 |
+
return false;
|
| 787 |
+
#endif
|
| 788 |
+
}
|
| 789 |
+
// fabric density for the GPU-gate report (M5): edges / possible directed
|
| 790 |
+
// edges, plus mean out-degree. Pure measurements, no claims.
|
| 791 |
+
double fabric_density() const {
|
| 792 |
+
const double n = static_cast<double>(nodes_.size());
|
| 793 |
+
if (n < 2.0) return 0.0;
|
| 794 |
+
return static_cast<double>(lane_count()) / (n * (n - 1.0));
|
| 795 |
+
}
|
| 796 |
+
double mean_out_degree() const {
|
| 797 |
+
const double n = static_cast<double>(nodes_.size());
|
| 798 |
+
return n > 0.0 ? static_cast<double>(lane_count()) / n : 0.0;
|
| 799 |
+
}
|
| 800 |
+
};
|
| 801 |
+
|
| 802 |
+
// ---------------------------------------------------------------------------
|
| 803 |
+
// Tokenizer — plain lexical split (I/O concern, not pattern matching):
|
| 804 |
+
// lowercase, split on non-alphanumeric, keep tokens of length 2..24.
|
| 805 |
+
// ---------------------------------------------------------------------------
|
| 806 |
+
// Light deterministic lexical folding (string normalization, not ML):
|
| 807 |
+
// plurals: "refunds"->"refund", "invoices"->"invoice" (len>=4, not "ss")
|
| 808 |
+
// past/verb: "charged"->"charg", "charge"->"charg" (len>=5)
|
| 809 |
+
// gerund: "billing"->"bill", "running"->"runn" (len>=6)
|
| 810 |
+
// Consistency matters, not linguistic truth: the same fold applies to state,
|
| 811 |
+
// options, and instructions, so matched forms always meet.
|
| 812 |
+
inline std::string fold(const std::string& w) {
|
| 813 |
+
std::string s = w;
|
| 814 |
+
if (s.size() >= 4 && s.compare(s.size() - 2, 2, "ss") != 0 && s.back() == 's') s.pop_back();
|
| 815 |
+
if (s.size() >= 6 && s.compare(s.size() - 3, 3, "ing") == 0) { s.erase(s.size() - 3); return s; }
|
| 816 |
+
if (s.size() >= 5 && s.compare(s.size() - 2, 2, "ed") == 0) s.erase(s.size() - 2);
|
| 817 |
+
if (s.size() >= 5 && s.back() == 'e') s.pop_back();
|
| 818 |
+
return s;
|
| 819 |
+
}
|
| 820 |
+
|
| 821 |
+
inline std::vector<std::string> tokenize(const std::string& text) {
|
| 822 |
+
std::vector<std::string> out;
|
| 823 |
+
std::string cur;
|
| 824 |
+
auto emit = [&]() {
|
| 825 |
+
if (cur.size() >= 2 && cur.size() <= 24) out.push_back(fold(cur));
|
| 826 |
+
cur.clear();
|
| 827 |
+
};
|
| 828 |
+
for (char raw : text) {
|
| 829 |
+
unsigned char c = static_cast<unsigned char>(raw);
|
| 830 |
+
if (std::isalnum(c)) cur.push_back(static_cast<char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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// SyFox — syfox.hpp
|
| 3 |
+
// The System One layer: turns SI substrate field dynamics into typed
|
| 4 |
+
// decisions (Choice / Score / Noul) with a Jev-compatible call shape.
|
| 5 |
+
//
|
| 6 |
+
// Layering contract:
|
| 7 |
+
// * CORE (si::Substrate) = SI physics only. Injection, settle, resonance
|
| 8 |
+
// sweep readout, Hebbian lanes, honest silence. No classifiers, no
|
| 9 |
+
// transformers, no pattern-matching algorithms.
|
| 10 |
+
// * THIS LAYER = typed question plumbing + persistence +
|
| 11 |
+
// a calibration TOOL that post-processes readout energies into
|
| 12 |
+
// probabilities (allowed as an external tool; it never rewrites the core).
|
| 13 |
+
//
|
| 14 |
+
// All questions are evaluated against ONE settled field, in isolation —
|
| 15 |
+
// adding questions does not re-settle the substrate (Jev's flat-latency
|
| 16 |
+
// property, inherited structurally).
|
| 17 |
+
// ============================================================================
|
| 18 |
+
#pragma once
|
| 19 |
+
#include "json.hpp"
|
| 20 |
+
#include "si_substrate.hpp"
|
| 21 |
+
#include "normalize.hpp"
|
| 22 |
+
#include "ngram.hpp"
|
| 23 |
+
|
| 24 |
+
#include <algorithm>
|
| 25 |
+
#include <cmath>
|
| 26 |
+
#include <cstdio>
|
| 27 |
+
#include <fstream>
|
| 28 |
+
#include <map>
|
| 29 |
+
#include <set>
|
| 30 |
+
#include <string>
|
| 31 |
+
#include <unordered_set>
|
| 32 |
+
#include <vector>
|
| 33 |
+
|
| 34 |
+
namespace syfox {
|
| 35 |
+
|
| 36 |
+
inline const char* VERSION = "3.1.2";
|
| 37 |
+
|
| 38 |
+
// ---------------------------------------------------------------------------
|
| 39 |
+
// v2.2 boundary injection protocol — sub-word bridges for corrupted forms.
|
| 40 |
+
// Words inject at the substrate's own inject_energy; the trigram bridges of
|
| 41 |
+
// an unknown word inject ONLY when that word passes the sub-word traction
|
| 42 |
+
// gate below (a corrupted form of something taught). A boundary protocol,
|
| 43 |
+
// not core physics: si_substrate.hpp is untouched.
|
| 44 |
+
// ---------------------------------------------------------------------------
|
| 45 |
+
inline constexpr float kBridgeEnergy = 1.0f;
|
| 46 |
+
|
| 47 |
+
// Sub-word traction gate: an UNKNOWN word earns trigram bridges only when a
|
| 48 |
+
// meaningful fraction of its trigrams already exist in the fabric — the
|
| 49 |
+
// signature of a CORRUPTED FORM of something taught ("refnd" keeps g3:ref
|
| 50 |
+
// of "refund"). A legitimate unseen word ("webhook" never taught) shares
|
| 51 |
+
// nothing and stays fully dark: honest silence, no manufactured evidence.
|
| 52 |
+
// Measured (v2.2 A/B, README): ungated bridges regress clean heldout
|
| 53 |
+
// (tickets 1.000 -> 0.833/0.500 depending on bridge level) because unseen
|
| 54 |
+
//-but-relevant words bridge into unrelated labels; with this gate, clean
|
| 55 |
+
// behavior returns to baseline while typo routing is retained.
|
| 56 |
+
inline bool subword_traction(const si::Substrate& s, const std::string& w) {
|
| 57 |
+
const auto grams = si::norm::expand_ngrams({w});
|
| 58 |
+
if (grams.empty()) return false;
|
| 59 |
+
std::size_t known = 0;
|
| 60 |
+
for (const auto& g : grams) if (s.has(g)) ++known;
|
| 61 |
+
return known * 4 >= grams.size(); // >= 25% of trigrams known
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
// ---------------------------------------------------------------------------
|
| 65 |
+
// v3 Milestone 2 — the distinct-experience policy (boundary layer, flag-gated).
|
| 66 |
+
// Measured twice (v2.1 paraphrases, v2.2 variants): re-teaching near-
|
| 67 |
+
// duplicate lessons REGRESSED held-out accuracy, while distinct experience
|
| 68 |
+
// scales (the v3 dose-response probe: tickets hidden 0.603@250 -> 0.825@8400).
|
| 69 |
+
// The fix lives in the TEACHING dose, not in the physics:
|
| 70 |
+
// * dedup — an exact duplicate lesson (same normalized token stream,
|
| 71 |
+
// same outcome) carries ZERO new information: skip it.
|
| 72 |
+
// * novelty — a lesson's Hebbian dose scales with how much of its state
|
| 73 |
+
// vocabulary the fabric has never seen: eta_scale =
|
| 74 |
+
// floor + (1-floor) * n_new_words / n_words. A fresh sentence
|
| 75 |
+
// binds at full strength; a rephrasing of known words binds
|
| 76 |
+
// at 25% — enough to track drift, not enough to smear lanes.
|
| 77 |
+
// ---------------------------------------------------------------------------
|
| 78 |
+
struct LearnPolicy {
|
| 79 |
+
bool dedup = false;
|
| 80 |
+
bool novelty = false;
|
| 81 |
+
float novelty_floor = 0.25f;
|
| 82 |
+
};
|
| 83 |
+
|
| 84 |
+
// ---------------------------------------------------------------------------
|
| 85 |
+
struct Answer {
|
| 86 |
+
std::string qid;
|
| 87 |
+
std::string type; // "choice" | "score" | "noul"
|
| 88 |
+
std::string choice; // choice only
|
| 89 |
+
float value = 0.0f; // score only (weighted level)
|
| 90 |
+
float probability = 0.0f; // noul only
|
| 91 |
+
std::vector<std::pair<std::string, float>> probabilities; // choice/score
|
| 92 |
+
float confidence = 0.0f;
|
| 93 |
+
bool deferred = false;
|
| 94 |
+
std::string reason; // honest-silence reasons
|
| 95 |
+
};
|
| 96 |
+
|
| 97 |
+
struct Usage {
|
| 98 |
+
std::size_t state_tokens = 0;
|
| 99 |
+
std::size_t vocabulary = 0;
|
| 100 |
+
std::size_t lanes = 0;
|
| 101 |
+
int settle_passes = 0;
|
| 102 |
+
float settled_energy = 0.0f;
|
| 103 |
+
bool calibrated = false;
|
| 104 |
+
};
|
| 105 |
+
|
| 106 |
+
struct Calibration {
|
| 107 |
+
float choice_temperature = 1.0f;
|
| 108 |
+
float score_temperature = 1.0f;
|
| 109 |
+
float noul_a = 6.0f; // p = sigmoid(a*support + b)
|
| 110 |
+
float noul_b = -3.0f;
|
| 111 |
+
bool fitted = false;
|
| 112 |
+
std::size_t rows = 0;
|
| 113 |
+
|
| 114 |
+
sfx::JV to_json() const {
|
| 115 |
+
return sfx::JV(sfx::JVObj{
|
| 116 |
+
{"choice_temperature", choice_temperature},
|
| 117 |
+
{"score_temperature", score_temperature},
|
| 118 |
+
{"noul_a", noul_a}, {"noul_b", noul_b},
|
| 119 |
+
{"fitted", fitted}, {"rows", static_cast<double>(rows)}});
|
| 120 |
+
}
|
| 121 |
+
static Calibration from_json(const sfx::JV& j) {
|
| 122 |
+
Calibration c;
|
| 123 |
+
c.choice_temperature = static_cast<float>(j.at("choice_temperature").as_num(1.0));
|
| 124 |
+
c.score_temperature = static_cast<float>(j.at("score_temperature").as_num(1.0));
|
| 125 |
+
c.noul_a = static_cast<float>(j.at("noul_a").as_num(6.0));
|
| 126 |
+
c.noul_b = static_cast<float>(j.at("noul_b").as_num(-3.0));
|
| 127 |
+
c.fitted = j.at("fitted").is_bool() && j.at("fitted").b;
|
| 128 |
+
c.rows = static_cast<std::size_t>(j.at("rows").as_num(0));
|
| 129 |
+
return c;
|
| 130 |
+
}
|
| 131 |
+
};
|
| 132 |
+
|
| 133 |
+
// ---------------------------------------------------------------------------
|
| 134 |
+
class Engine {
|
| 135 |
+
public:
|
| 136 |
+
explicit Engine(si::SubstrateConfig cfg = {}) : si_(cfg) {}
|
| 137 |
+
|
| 138 |
+
si::Substrate& substrate() { return si_; }
|
| 139 |
+
const si::Substrate& substrate() const { return si_; }
|
| 140 |
+
Calibration& calibration() { return calib_; }
|
| 141 |
+
|
| 142 |
+
// -- v3 Milestone 1: decide-side energy normalization (boundary GAIN knob) --
|
| 143 |
+
// At seed scale (tens of lessons) acoustic mass is small and a state's
|
| 144 |
+
// settled field sits comfortably above the silence floor. At corpus scale
|
| 145 |
+
// (8,400 lessons) common words carry mass in the hundreds, the damping law
|
| 146 |
+
// energy/sqrt(mass) whispers, and honest silence (absolute floor 0.05)
|
| 147 |
+
// defers most states — coverage collapses to the rows that happen to
|
| 148 |
+
// contain rare tokens (measured: 33/40 hidden rows deferred).
|
| 149 |
+
// The fix is a measurement gain, NOT a physics change: the injection dose
|
| 150 |
+
// is scaled by the mean sqrt(mass) of the state's KNOWN tokens, which
|
| 151 |
+
// preserves the damping law's per-token ratios exactly (uniform mass m
|
| 152 |
+
// reproduces the seed-scale total n*inject_energy bit-for-bit up to the
|
| 153 |
+
// scale factor). si_substrate.hpp is untouched; the silence floor stays
|
| 154 |
+
// absolute; unknown vocabulary still injects nothing and still defers.
|
| 155 |
+
// Off by default: every v2.1/v2.2 number reproduces unchanged.
|
| 156 |
+
void set_energy_norm(bool on) { energy_norm_ = on; }
|
| 157 |
+
bool energy_norm() const { return energy_norm_; }
|
| 158 |
+
|
| 159 |
+
// -- model persistence ----------------------------------------------------
|
| 160 |
+
void save_model(const std::string& dir) const {
|
| 161 |
+
std::string cmd_mkdir = "mkdir -p '" + dir + "'";
|
| 162 |
+
(void)std::system(cmd_mkdir.c_str());
|
| 163 |
+
si_.save(dir + "/substrate.bin");
|
| 164 |
+
std::ofstream cf(dir + "/calibration.json");
|
| 165 |
+
cf << calib_.to_json().dump();
|
| 166 |
+
std::ofstream mf(dir + "/meta.json");
|
| 167 |
+
mf << sfx::JV(sfx::JVObj{
|
| 168 |
+
{"engine", "syfox"}, {"version", VERSION},
|
| 169 |
+
{"core", "si-substrate"}, {"nodes", static_cast<double>(si_.node_count())},
|
| 170 |
+
{"lanes", static_cast<double>(si_.lane_count())},
|
| 171 |
+
{"evidence_records", static_cast<double>(si_.evidence_count())},
|
| 172 |
+
{"teach_events", static_cast<double>(teach_seq_)},
|
| 173 |
+
{"contradictions", static_cast<double>(conflicts_.size())}}).dump();
|
| 174 |
+
// v3 Milestone 3: the audit trail. conflicts.jsonl = every detected
|
| 175 |
+
// contradiction; lessons_index.jsonl = state-hash -> outcome index
|
| 176 |
+
// (so a LATER learn invocation still detects contradictions against
|
| 177 |
+
// every lesson ever taught, not just this process's).
|
| 178 |
+
{
|
| 179 |
+
std::ofstream of(dir + "/conflicts.jsonl");
|
| 180 |
+
for (const auto& c : conflicts_) of << c.dump() << "\n";
|
| 181 |
+
}
|
| 182 |
+
{
|
| 183 |
+
std::ofstream of(dir + "/lessons_index.jsonl");
|
| 184 |
+
for (const auto& kv : taught_outcomes_)
|
| 185 |
+
of << sfx::JV(sfx::JVObj{
|
| 186 |
+
{"state_hash_hex", sfx::JV(hex64(kv.first))},
|
| 187 |
+
{"seq", static_cast<double>(kv.second.seq)},
|
| 188 |
+
{"outcome", sfx::JV(kv.second.outcome)}}).dump() << "\n";
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
void load_model(const std::string& dir) {
|
| 193 |
+
si_.load(dir + "/substrate.bin");
|
| 194 |
+
std::ifstream cf(dir + "/calibration.json");
|
| 195 |
+
if (cf) { std::string buf((std::istreambuf_iterator<char>(cf)), std::istreambuf_iterator<char>());
|
| 196 |
+
calib_ = Calibration::from_json(sfx::JV::parse(buf)); }
|
| 197 |
+
// v3 audit trail (optional files; a v2 model dir simply lacks them)
|
| 198 |
+
{
|
| 199 |
+
std::ifstream f(dir + "/conflicts.jsonl");
|
| 200 |
+
if (f) {
|
| 201 |
+
std::string line;
|
| 202 |
+
while (std::getline(f, line))
|
| 203 |
+
if (!line.empty()) {
|
| 204 |
+
sfx::JV c = sfx::JV::parse(line);
|
| 205 |
+
conflicts_.push_back(c);
|
| 206 |
+
if (c.has("state_hash_hex"))
|
| 207 |
+
conflicts_by_state_[hex_to_u64(c.at("state_hash_hex").as_str())]
|
| 208 |
+
.push_back(conflicts_.size() - 1);
|
| 209 |
+
}
|
| 210 |
+
}
|
| 211 |
+
}
|
| 212 |
+
{
|
| 213 |
+
std::ifstream f(dir + "/lessons_index.jsonl");
|
| 214 |
+
if (f) {
|
| 215 |
+
std::string line;
|
| 216 |
+
while (std::getline(f, line)) {
|
| 217 |
+
if (line.empty()) continue;
|
| 218 |
+
sfx::JV r = sfx::JV::parse(line);
|
| 219 |
+
Taught t;
|
| 220 |
+
t.seq = static_cast<std::uint64_t>(r.at("seq").as_num(0));
|
| 221 |
+
t.outcome = r.at("outcome").as_str();
|
| 222 |
+
taught_outcomes_[hex_to_u64(r.at("state_hash_hex").as_str())] = t;
|
| 223 |
+
if (t.seq > teach_seq_) teach_seq_ = t.seq;
|
| 224 |
+
}
|
| 225 |
+
}
|
| 226 |
+
}
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
// set the audit context tag recorded into the lane evidence ledger
|
| 230 |
+
void set_context(const std::string& c) { context_ = c; }
|
| 231 |
+
std::uint64_t teach_events() const { return teach_seq_; }
|
| 232 |
+
const std::vector<sfx::JV>& conflicts() const { return conflicts_; }
|
| 233 |
+
|
| 234 |
+
// -- HEBBIAN LESSON (learning = substrate rewiring) -------------------------
|
| 235 |
+
// One labelled experience: state text + question + rewarded outcome.
|
| 236 |
+
// 1. all concepts join the vocabulary (intern; fresh nodes are light)
|
| 237 |
+
// 2. adjacent state tokens bind (co-occurrence fabric for diffusion)
|
| 238 |
+
// 3. state -> outcome lanes strengthen (fire together, wire together)
|
| 239 |
+
//
|
| 240 |
+
// v2.2: (a) the STATE side carries character trigram lanes (ngram.hpp;
|
| 241 |
+
// state_tokens()) so typos and sub-word fragments reach the fabric —
|
| 242 |
+
// outcome/label side stays gram-free. (b) augment=true is the mass-
|
| 243 |
+
// guarded re-teach used by paraphrase/variant lessons: concepts already
|
| 244 |
+
// in the vocabulary are NOT intern()ed again, so re-exposure does not
|
| 245 |
+
// raise acoustic mass (the v2.1 dose-response artifact: re-taught
|
| 246 |
+
// near-duplicates re-weighted the field by 1/sqrt(mass) damping and
|
| 247 |
+
// REGRESSED held-out accuracy). With the guard, a variant lesson only
|
| 248 |
+
// lays/strengthens LANES (coverage), it never re-deposits mass.
|
| 249 |
+
void learn_example(const std::string& state_text, const std::string& instructions,
|
| 250 |
+
const std::string& outcome_text, bool augment = false,
|
| 251 |
+
const LearnPolicy& lp = LearnPolicy{}, bool* learned = nullptr) {
|
| 252 |
+
const bool grams = si::norm::grams_enabled();
|
| 253 |
+
const std::vector<std::string> words =
|
| 254 |
+
si::norm::normalize(state_text + " " + instructions);
|
| 255 |
+
std::vector<std::string> state = si::norm::state_tokens(words, grams);
|
| 256 |
+
const std::size_t n_words = words.size();
|
| 257 |
+
std::vector<std::string> outcome = si::norm::normalize(outcome_text);
|
| 258 |
+
// Milestone 2: novelty is measured BEFORE interning (a word the fabric
|
| 259 |
+
// has not seen yet is exactly the new information this lesson carries).
|
| 260 |
+
float eta = 1.0f;
|
| 261 |
+
if (lp.novelty && n_words > 0) {
|
| 262 |
+
std::size_t fresh = 0;
|
| 263 |
+
for (const auto& w : words) if (!si_.has(w)) ++fresh;
|
| 264 |
+
eta = lp.novelty_floor
|
| 265 |
+
+ (1.0f - lp.novelty_floor) * (static_cast<float>(fresh) / static_cast<float>(n_words));
|
| 266 |
+
}
|
| 267 |
+
// Milestone 2: exact-duplicate lessons are skipped outright.
|
| 268 |
+
if (lp.dedup) {
|
| 269 |
+
std::uint64_t h = 1469598103934665603ull;
|
| 270 |
+
// cast! fnv1a_hash returns float; an uncast + would promote the
|
| 271 |
+
// whole chain to float (24-bit mantissa) and collapse every
|
| 272 |
+
// lesson onto one hash (measured: 25111/25200 false duplicates).
|
| 273 |
+
for (const auto& w : words) { h = h * 1099511628211ull + static_cast<std::uint64_t>(si::fnv1a_hash(w)); }
|
| 274 |
+
for (const auto& w : outcome) { h = h * 1099511628211ull + static_cast<std::uint64_t>(si::fnv1a_hash(w)); }
|
| 275 |
+
if (!lesson_hashes_.insert(h).second) {
|
| 276 |
+
if (learned) *learned = false;
|
| 277 |
+
return;
|
| 278 |
+
}
|
| 279 |
+
}
|
| 280 |
+
// Milestone 3: contradiction check. Same (state + question) taught
|
| 281 |
+
// with a DIFFERENT outcome is a contradiction — it must surface in
|
| 282 |
+
// the audit trail, never silently override (or be silently ignored).
|
| 283 |
+
const std::uint64_t shash = stream_hash(words);
|
| 284 |
+
const std::uint64_t seq = ++teach_seq_;
|
| 285 |
+
auto prev = taught_outcomes_.find(shash);
|
| 286 |
+
if (prev != taught_outcomes_.end() && prev->second.outcome != outcome_text) {
|
| 287 |
+
sfx::JV c(sfx::JVObj{
|
| 288 |
+
{"type", sfx::JV("contradiction")},
|
| 289 |
+
{"state", sfx::JV(state_text)}, {"state_hash_hex", sfx::JV(hex64(stream_hash(si::norm::normalize(state_text))))},
|
| 290 |
+
{"instructions", sfx::JV(instructions)},
|
| 291 |
+
{"outcome_old", sfx::JV(prev->second.outcome)},
|
| 292 |
+
{"outcome_new", sfx::JV(outcome_text)},
|
| 293 |
+
{"seq_old", static_cast<double>(prev->second.seq)},
|
| 294 |
+
{"seq_new", static_cast<double>(seq)},
|
| 295 |
+
{"context", sfx::JV(context_)}});
|
| 296 |
+
conflicts_by_state_[stream_hash(si::norm::normalize(state_text))].push_back(conflicts_.size());
|
| 297 |
+
conflicts_.push_back(c);
|
| 298 |
+
// the new lesson is COUNTER-EVIDENCE for the old binding's lanes:
|
| 299 |
+
// mark every old lane reachable from this state's words.
|
| 300 |
+
mark_counter_lanes(words, prev->second.outcome, seq);
|
| 301 |
+
}
|
| 302 |
+
taught_outcomes_[shash] = Taught{seq, outcome_text};
|
| 303 |
+
for (const auto& t : state)
|
| 304 |
+
if (!(augment && si_.has(t))) si_.intern(t);
|
| 305 |
+
for (const auto& t : outcome)
|
| 306 |
+
if (!(augment && si_.has(t))) si_.intern(t);
|
| 307 |
+
for (std::size_t i = 1; i < n_words; ++i) // co-occurrence fabric
|
| 308 |
+
si_.bind(si_.find(words[i - 1]), si_.find(words[i]), si_.config().learn_eta * 0.5f * eta);
|
| 309 |
+
if (grams) // word<->its own trigrams fabric
|
| 310 |
+
for (const auto& w : words)
|
| 311 |
+
for (const auto& g : si::norm::expand_ngrams({w}))
|
| 312 |
+
if (si_.has(g))
|
| 313 |
+
si_.bind(si_.find(w), si_.find(g), si_.config().learn_eta * 0.5f * eta);
|
| 314 |
+
si_.hebbian_lesson(state, outcome, eta);
|
| 315 |
+
// Milestone 3: record the support evidence for every state->outcome
|
| 316 |
+
// lane this lesson just strengthened (bookkeeping; the ledger never
|
| 317 |
+
// feeds back into the field).
|
| 318 |
+
for (const auto& a : state)
|
| 319 |
+
if (si_.has(a))
|
| 320 |
+
for (const auto& b : outcome)
|
| 321 |
+
if (si_.has(b)) si_.record_support(si_.find(a), si_.find(b), seq, context_);
|
| 322 |
+
if (learned) *learned = true;
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
// -- CALIBRATION TOOL (external post-processor, not core physics) ----------
|
| 326 |
+
// Fits temperature (choice/score) and Platt (noul) on collected rows.
|
| 327 |
+
// v2.1: a choice/score row carries the FULL candidate energy vector plus
|
| 328 |
+
// the gold label, so the fit sees the same multi-class softmax the decide
|
| 329 |
+
// path reports. The old {e_correct, worst e_wrong} pairwise view was
|
| 330 |
+
// structurally blind to argmax errors on near-ties (a wrong-but-tied row
|
| 331 |
+
// stays p=0.5 under ANY temperature), which let the optimizer drive T to
|
| 332 |
+
// its floor and manufacture confidence on wrong answers.
|
| 333 |
+
struct CalibRow {
|
| 334 |
+
std::string type;
|
| 335 |
+
std::string label; // gold candidate key
|
| 336 |
+
std::vector<std::pair<std::string, float>> energies; // full candidate vector
|
| 337 |
+
float support = 0.0f; // noul: support readout
|
| 338 |
+
int y = 0; // noul: gold target
|
| 339 |
+
};
|
| 340 |
+
|
| 341 |
+
void fit_calibration(const std::vector<CalibRow>& rows) {
|
| 342 |
+
// v2.1 adoption guard: the NLL optimum is the textbook temperature,
|
| 343 |
+
// but on tiny heldout sets with an unavoidable argmax error it can
|
| 344 |
+
// WORSEN ECE (sharpening raises the wrong answer's confidence too).
|
| 345 |
+
// So the fit is a selection between exactly two honest candidates —
|
| 346 |
+
// T = 1 and the NLL optimum — decided by measured multi-class ECE on
|
| 347 |
+
// the fit rows (1 bit per question type; argmax never moves). The
|
| 348 |
+
// calibrate report shows before/after either way.
|
| 349 |
+
struct Cand { float T; };
|
| 350 |
+
auto adopt_temp = [&](const std::string& type, float& slot) {
|
| 351 |
+
float cand = slot;
|
| 352 |
+
fit_temperature(rows, type, cand);
|
| 353 |
+
const double e1 = calibration_ece(rows, type, 1.0f, 0, 0);
|
| 354 |
+
const double e2 = calibration_ece(rows, type, cand, 0, 0);
|
| 355 |
+
slot = (e2 < e1) ? cand : 1.0f;
|
| 356 |
+
};
|
| 357 |
+
adopt_temp("choice", calib_.choice_temperature);
|
| 358 |
+
adopt_temp("score", calib_.score_temperature);
|
| 359 |
+
// Platt: same 1-bit selection for the noul map
|
| 360 |
+
const float a0 = calib_.noul_a, b0 = calib_.noul_b;
|
| 361 |
+
const double p1 = calibration_ece(rows, "noul", 1.0f, a0, b0);
|
| 362 |
+
fit_platt(rows);
|
| 363 |
+
const double p2 = calibration_ece(rows, "noul", 1.0f, calib_.noul_a, calib_.noul_b);
|
| 364 |
+
if (!(p2 < p1)) { calib_.noul_a = a0; calib_.noul_b = b0; }
|
| 365 |
+
calib_.fitted = true;
|
| 366 |
+
calib_.rows = rows.size();
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
// Multi-class expected calibration error over collected rows (10 equal-
|
| 370 |
+
// width bins on top-probability confidence, argmax-correctness for
|
| 371 |
+
// choice/score; Platt sigmoid + 0.5 threshold for noul). Same definition
|
| 372 |
+
// the bench reports, so calibrate's before/after and bench's ECE agree.
|
| 373 |
+
static double calibration_ece(const std::vector<CalibRow>& rows,
|
| 374 |
+
const std::string& type, float T,
|
| 375 |
+
float noul_a, float noul_b) {
|
| 376 |
+
long bins[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
| 377 |
+
long corr[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
| 378 |
+
double confs[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
| 379 |
+
const float Ts = std::max(1e-6f, T);
|
| 380 |
+
for (const auto& r : rows) {
|
| 381 |
+
if (r.type != type) continue;
|
| 382 |
+
float conf = 0.0f; bool correct = false;
|
| 383 |
+
if (r.type == "noul") {
|
| 384 |
+
const float p = 1.0f / (1.0f + std::exp(-(noul_a * r.support + noul_b)));
|
| 385 |
+
conf = std::max(p, 1.0f - p);
|
| 386 |
+
correct = (p >= 0.5f) == (r.y == 1);
|
| 387 |
+
} else {
|
| 388 |
+
if (r.energies.empty()) continue;
|
| 389 |
+
float maxe = -1e30f;
|
| 390 |
+
for (const auto& kv : r.energies) maxe = std::max(maxe, kv.second);
|
| 391 |
+
float z = 0.0f, top = -1.0f; std::string amax;
|
| 392 |
+
for (const auto& kv : r.energies) {
|
| 393 |
+
const float v = std::exp((kv.second - maxe) / Ts);
|
| 394 |
+
z += v;
|
| 395 |
+
if (v > top) { top = v; amax = kv.first; }
|
| 396 |
+
}
|
| 397 |
+
conf = top / z;
|
| 398 |
+
correct = amax == r.label;
|
| 399 |
+
}
|
| 400 |
+
const int b = std::min(9, std::max(0, static_cast<int>(conf * 10.0f)));
|
| 401 |
+
++bins[b]; corr[b] += correct ? 1 : 0; confs[b] += conf;
|
| 402 |
+
}
|
| 403 |
+
long total = 0;
|
| 404 |
+
for (int i = 0; i < 10; ++i) total += bins[i];
|
| 405 |
+
if (total == 0) return 0.0;
|
| 406 |
+
double e = 0.0;
|
| 407 |
+
for (int i = 0; i < 10; ++i) {
|
| 408 |
+
if (!bins[i]) continue;
|
| 409 |
+
e += (static_cast<double>(bins[i]) / total)
|
| 410 |
+
* std::fabs(static_cast<double>(corr[i]) / bins[i]
|
| 411 |
+
- confs[i] / bins[i]);
|
| 412 |
+
}
|
| 413 |
+
return e;
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
// -- Noul lesson (valence-aware) ------------------------------------------
|
| 417 |
+
// y=true : Hebbian bind state concepts <-> instruction concepts
|
| 418 |
+
// (supporting evidence wires the route)
|
| 419 |
+
// y=false : anti-Hebbian weaken the same routes (disconfirming evidence
|
| 420 |
+
// dissolves them), so the field discriminates, not accumulates.
|
| 421 |
+
void learn_noul(const std::string& state_text, const std::string& instructions, bool y,
|
| 422 |
+
bool augment = false, const LearnPolicy& lp = LearnPolicy{},
|
| 423 |
+
bool* learned = nullptr) {
|
| 424 |
+
const bool grams = si::norm::grams_enabled();
|
| 425 |
+
const std::vector<std::string> words = si::norm::normalize(state_text);
|
| 426 |
+
std::vector<std::string> state = si::norm::state_tokens(words, grams);
|
| 427 |
+
std::vector<std::string> instr = si::norm::normalize(instructions); // gram-free
|
| 428 |
+
float eta = 1.0f;
|
| 429 |
+
if (lp.novelty && !words.empty()) {
|
| 430 |
+
std::size_t fresh = 0;
|
| 431 |
+
for (const auto& w : words) if (!si_.has(w)) ++fresh;
|
| 432 |
+
eta = lp.novelty_floor
|
| 433 |
+
+ (1.0f - lp.novelty_floor) * (static_cast<float>(fresh) / static_cast<float>(words.size()));
|
| 434 |
+
}
|
| 435 |
+
if (lp.dedup) {
|
| 436 |
+
std::uint64_t h = 1469598103934665603ull;
|
| 437 |
+
for (const auto& w : words) { h = h * 1099511628211ull + static_cast<std::uint64_t>(si::fnv1a_hash(w)); }
|
| 438 |
+
for (const auto& w : instr) { h = h * 1099511628211ull + static_cast<std::uint64_t>(si::fnv1a_hash(w)); }
|
| 439 |
+
h = h * 1099511628211ull + (y ? 0x9E3779B9ull : 0x85EBCA6Bull);
|
| 440 |
+
if (!lesson_hashes_.insert(h).second) {
|
| 441 |
+
if (learned) *learned = false;
|
| 442 |
+
return;
|
| 443 |
+
}
|
| 444 |
+
}
|
| 445 |
+
// Milestone 3: noul contradictions — same (state + instruction) taught
|
| 446 |
+
// with the opposite valence (true vs false) is a contradiction too.
|
| 447 |
+
const std::string outcome_text = y ? "true" : "false";
|
| 448 |
+
const std::uint64_t shash = stream_hash(words);
|
| 449 |
+
const std::uint64_t seq = ++teach_seq_;
|
| 450 |
+
auto prev = taught_outcomes_.find(shash);
|
| 451 |
+
if (prev != taught_outcomes_.end() && prev->second.outcome != outcome_text) {
|
| 452 |
+
sfx::JV c(sfx::JVObj{
|
| 453 |
+
{"type", sfx::JV("contradiction")},
|
| 454 |
+
{"state", sfx::JV(state_text)}, {"state_hash_hex", sfx::JV(hex64(stream_hash(si::norm::normalize(state_text))))},
|
| 455 |
+
{"instructions", sfx::JV(instructions)},
|
| 456 |
+
{"outcome_old", sfx::JV(prev->second.outcome)},
|
| 457 |
+
{"outcome_new", sfx::JV(outcome_text)},
|
| 458 |
+
{"seq_old", static_cast<double>(prev->second.seq)},
|
| 459 |
+
{"seq_new", static_cast<double>(seq)},
|
| 460 |
+
{"context", sfx::JV(context_)}});
|
| 461 |
+
conflicts_by_state_[stream_hash(si::norm::normalize(state_text))].push_back(conflicts_.size());
|
| 462 |
+
conflicts_.push_back(c);
|
| 463 |
+
mark_counter_lanes(words, prev->second.outcome, seq);
|
| 464 |
+
}
|
| 465 |
+
taught_outcomes_[shash] = Taught{seq, outcome_text};
|
| 466 |
+
for (const auto& t : state)
|
| 467 |
+
if (!(augment && si_.has(t))) si_.intern(t);
|
| 468 |
+
for (const auto& t : instr)
|
| 469 |
+
if (!(augment && si_.has(t))) si_.intern(t);
|
| 470 |
+
if (grams)
|
| 471 |
+
for (const auto& w : words)
|
| 472 |
+
for (const auto& g : si::norm::expand_ngrams({w}))
|
| 473 |
+
if (si_.has(g))
|
| 474 |
+
si_.bind(si_.find(w), si_.find(g), si_.config().learn_eta * 0.5f * eta);
|
| 475 |
+
if (y) {
|
| 476 |
+
si_.hebbian_lesson(state, instr, 2.0f * eta); // supporting evidence binds hard
|
| 477 |
+
for (const auto& a : state)
|
| 478 |
+
if (si_.has(a))
|
| 479 |
+
for (const auto& b : instr)
|
| 480 |
+
if (si_.has(b)) si_.record_support(si_.find(a), si_.find(b), seq, context_);
|
| 481 |
+
} else {
|
| 482 |
+
si_.weaken(state, instr, eta); // disconfirming evidence dissolves
|
| 483 |
+
for (const auto& a : state)
|
| 484 |
+
if (si_.has(a))
|
| 485 |
+
for (const auto& b : instr)
|
| 486 |
+
if (si_.has(b)) si_.record_counter(si_.find(a), si_.find(b), seq, context_);
|
| 487 |
+
}
|
| 488 |
+
if (learned) *learned = true;
|
| 489 |
+
}
|
| 490 |
+
|
| 491 |
+
// decide-side injection dose (Milestone-1 gain knob; see set_energy_norm)
|
| 492 |
+
float state_dose(const std::vector<std::string>& words) const {
|
| 493 |
+
if (!energy_norm_) return si_.config().inject_energy;
|
| 494 |
+
double sum_sqrt = 0.0;
|
| 495 |
+
int present = 0;
|
| 496 |
+
for (const auto& w : words)
|
| 497 |
+
if (si_.has(w)) {
|
| 498 |
+
sum_sqrt += std::sqrt(static_cast<double>(si_.node_mass(si_.find(w))));
|
| 499 |
+
++present;
|
| 500 |
+
}
|
| 501 |
+
if (present == 0 || sum_sqrt <= 0.0) return si_.config().inject_energy;
|
| 502 |
+
return si_.config().inject_energy
|
| 503 |
+
* static_cast<float>(sum_sqrt / present);
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
// -- DECISION ----------------------------------------------------------------
|
| 507 |
+
std::vector<Answer> decide(const std::string& state, const sfx::JV& questions, Usage& usage) {
|
| 508 |
+
usage = Usage{};
|
| 509 |
+
usage.vocabulary = si_.node_count();
|
| 510 |
+
usage.lanes = si_.lane_count();
|
| 511 |
+
|
| 512 |
+
std::vector<Answer> answers;
|
| 513 |
+
const std::vector<std::string> words = si::norm::normalize(state);
|
| 514 |
+
usage.state_tokens = words.size();
|
| 515 |
+
|
| 516 |
+
si_.reset_field();
|
| 517 |
+
si_.inject(words, state_dose(words)); // words at the (gained) substrate level
|
| 518 |
+
if (si::norm::grams_enabled()) { // bridges for corrupted forms, gated
|
| 519 |
+
std::vector<std::string> bridges;
|
| 520 |
+
for (const auto& w : words)
|
| 521 |
+
if (!si_.has(w) && subword_traction(si_, w))
|
| 522 |
+
for (const auto& g : si::norm::expand_ngrams({w}))
|
| 523 |
+
if (si_.has(g)) bridges.push_back(g);
|
| 524 |
+
si_.inject(bridges, kBridgeEnergy);
|
| 525 |
+
usage.state_tokens += bridges.size();
|
| 526 |
+
}
|
| 527 |
+
si_.settle();
|
| 528 |
+
usage.settled_energy = si_.total_energy();
|
| 529 |
+
|
| 530 |
+
// Honest silence: nothing settled => refuse to guess.
|
| 531 |
+
bool silent = usage.settled_energy < si_.config().silence_floor;
|
| 532 |
+
for (const auto& qkv : questions.obj) {
|
| 533 |
+
const sfx::JV& q = qkv.second;
|
| 534 |
+
Answer a;
|
| 535 |
+
a.qid = qkv.first;
|
| 536 |
+
a.type = q.at("type").as_str();
|
| 537 |
+
if (silent) {
|
| 538 |
+
a.deferred = true;
|
| 539 |
+
a.reason = words.empty() ? "empty_state"
|
| 540 |
+
: (usage.settled_energy <= 0.0f ? "unknown_vocabulary" : "honest_silence");
|
| 541 |
+
answers.push_back(a);
|
| 542 |
+
continue;
|
| 543 |
+
}
|
| 544 |
+
if (a.type == "choice") decide_choice(q, a);
|
| 545 |
+
else if (a.type == "score") decide_score(q, a);
|
| 546 |
+
else if (a.type == "noul") decide_noul(q, a);
|
| 547 |
+
answers.push_back(a);
|
| 548 |
+
}
|
| 549 |
+
return answers;
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
// Harvest calibration rows from labelled examples (tool side).
|
| 553 |
+
std::vector<CalibRow> harvest_rows(const std::vector<sfx::JV>& examples) {
|
| 554 |
+
std::vector<CalibRow> rows;
|
| 555 |
+
for (const auto& ex : examples) {
|
| 556 |
+
std::string state = ex.at("state").as_str();
|
| 557 |
+
const sfx::JV& qs = ex.has("questions") ? ex.at("questions") : sfx::JV(sfx::JVObj{});
|
| 558 |
+
if (!qs.is_obj()) continue;
|
| 559 |
+
si_.reset_field();
|
| 560 |
+
{
|
| 561 |
+
const std::vector<std::string> hw = si::norm::normalize(state);
|
| 562 |
+
si_.inject(hw, state_dose(hw)); // gained dose (Milestone-1)
|
| 563 |
+
}
|
| 564 |
+
if (si::norm::grams_enabled()) {
|
| 565 |
+
const std::vector<std::string> words2 = si::norm::normalize(state);
|
| 566 |
+
std::vector<std::string> bridges;
|
| 567 |
+
for (const auto& w : words2)
|
| 568 |
+
if (!si_.has(w) && subword_traction(si_, w))
|
| 569 |
+
for (const auto& g : si::norm::expand_ngrams({w}))
|
| 570 |
+
if (si_.has(g)) bridges.push_back(g);
|
| 571 |
+
si_.inject(bridges, kBridgeEnergy);
|
| 572 |
+
}
|
| 573 |
+
si_.settle();
|
| 574 |
+
if (si_.silent()) continue;
|
| 575 |
+
for (const auto& qkv : qs.obj) {
|
| 576 |
+
const sfx::JV& q = qkv.second;
|
| 577 |
+
std::string type = q.at("type").as_str();
|
| 578 |
+
std::string label = ex.at("labels").at(qkv.first).as_str(); // correct label / level / "true"/"false"
|
| 579 |
+
if (type == "choice" || type == "score") {
|
| 580 |
+
const sfx::JV& crit = q.at("criteria");
|
| 581 |
+
std::vector<std::pair<std::string, float>> energies;
|
| 582 |
+
if (crit.is_obj())
|
| 583 |
+
for (const auto& kv : crit.obj)
|
| 584 |
+
energies.emplace_back(kv.first, probe_energy(kv.first, kv.second.as_str()));
|
| 585 |
+
else if (crit.is_arr())
|
| 586 |
+
for (std::size_t i = 0; i < crit.arr.size(); ++i)
|
| 587 |
+
energies.emplace_back(crit.arr[i].as_str(), probe_energy(crit.arr[i].as_str(), ""));
|
| 588 |
+
// resolve the gold label to a candidate KEY: for array
|
| 589 |
+
// criteria the stored label may be the level INDEX ("0",
|
| 590 |
+
// "1", ...) — the old code compared it to the level text
|
| 591 |
+
// and silently dropped every score row from the fit
|
| 592 |
+
std::string gold = label;
|
| 593 |
+
if (crit.is_arr()) {
|
| 594 |
+
bool is_text = false;
|
| 595 |
+
for (const auto& v : crit.arr) if (v.as_str() == label) { is_text = true; break; }
|
| 596 |
+
if (!is_text) {
|
| 597 |
+
long idx = std::strtol(label.c_str(), nullptr, 10);
|
| 598 |
+
if (idx >= 0 && idx < static_cast<long>(crit.arr.size()))
|
| 599 |
+
gold = crit.arr[static_cast<std::size_t>(idx)].as_str();
|
| 600 |
+
}
|
| 601 |
+
}
|
| 602 |
+
CalibRow r; r.type = type; r.label = gold; r.energies = energies;
|
| 603 |
+
rows.push_back(r);
|
| 604 |
+
} else if (type == "noul") {
|
| 605 |
+
float support = noul_support(q.at("instructions").as_str());
|
| 606 |
+
CalibRow r; r.type = "noul";
|
| 607 |
+
r.support = support;
|
| 608 |
+
r.y = (label == "true") ? 1 : 0;
|
| 609 |
+
rows.push_back(r);
|
| 610 |
+
}
|
| 611 |
+
}
|
| 612 |
+
}
|
| 613 |
+
return rows;
|
| 614 |
+
}
|
| 615 |
+
|
| 616 |
+
private:
|
| 617 |
+
// -- Milestone 3 audit internals -------------------------------------------
|
| 618 |
+
struct Taught { std::uint64_t seq; std::string outcome; };
|
| 619 |
+
|
| 620 |
+
// 64-bit hashes travel as HEX STRINGS in JSON: the house dump is %.6g and
|
| 621 |
+
// doubles lose integer precision past 2^53 — a numeric hash silently
|
| 622 |
+
// corrupts on every save/load round-trip (measured: reloaded conflict
|
| 623 |
+
// keys no longer matched the decide-side hash).
|
| 624 |
+
static std::string hex64(std::uint64_t v) {
|
| 625 |
+
char buf[17];
|
| 626 |
+
std::snprintf(buf, sizeof(buf), "%016llx", static_cast<unsigned long long>(v));
|
| 627 |
+
return buf;
|
| 628 |
+
}
|
| 629 |
+
static std::uint64_t hex_to_u64(const std::string& s) {
|
| 630 |
+
return std::stoull(s, nullptr, 16);
|
| 631 |
+
}
|
| 632 |
+
|
| 633 |
+
static std::uint64_t stream_hash(const std::vector<std::string>& ws) {
|
| 634 |
+
std::uint64_t h = 1469598103934665603ull;
|
| 635 |
+
for (const auto& w : ws) h = h * 1099511628211ull + static_cast<std::uint64_t>(si::fnv1a_hash(w));
|
| 636 |
+
return h;
|
| 637 |
+
}
|
| 638 |
+
|
| 639 |
+
// A contradicting lesson is COUNTER-EVIDENCE for the binding it disputes:
|
| 640 |
+
// mark every existing lane from this state's words into the OLD outcome's
|
| 641 |
+
// token set. Bookkeeping only — the physics is untouched.
|
| 642 |
+
void mark_counter_lanes(const std::vector<std::string>& words,
|
| 643 |
+
const std::string& old_outcome, std::uint64_t seq) {
|
| 644 |
+
std::vector<std::string> old_toks = si::norm::normalize(old_outcome);
|
| 645 |
+
for (const auto& w : words) {
|
| 646 |
+
if (!si_.has(w)) continue;
|
| 647 |
+
const si::NodeId a = si_.find(w);
|
| 648 |
+
std::vector<std::pair<si::NodeId, float>> lanes;
|
| 649 |
+
si_.lanes_of(a, lanes);
|
| 650 |
+
for (const auto& l : lanes)
|
| 651 |
+
for (const auto& t : old_toks)
|
| 652 |
+
if (si_.has(t) && si_.find(t) == l.first)
|
| 653 |
+
si_.record_counter(a, l.first, seq, context_);
|
| 654 |
+
}
|
| 655 |
+
}
|
| 656 |
+
|
| 657 |
+
// -- readout helpers --------------------------------------------------------
|
| 658 |
+
float probe_energy(const std::string& label, const std::string& desc) const {
|
| 659 |
+
return si_.readout(si::norm::normalize(label + " " + desc));
|
| 660 |
+
}
|
| 661 |
+
|
| 662 |
+
float noul_support(const std::string& instructions) const {
|
| 663 |
+
// Noul uses the SUPPORT readout lane: breadth of corroboration.
|
| 664 |
+
float e = si_.readout(si::norm::normalize(instructions), si::Substrate::ReadoutMode::Support);
|
| 665 |
+
float total = si_.total_energy();
|
| 666 |
+
if (total <= 0.0f) return 0.0f;
|
| 667 |
+
float support = e / (total * 1.5f); // ratio in ~[0,1+]
|
| 668 |
+
return std::min(1.5f, support);
|
| 669 |
+
}
|
| 670 |
+
|
| 671 |
+
public:
|
| 672 |
+
// debug/eval accessor (read-only)
|
| 673 |
+
float noul_support_public(const std::string& instructions) const { return noul_support(instructions); }
|
| 674 |
+
|
| 675 |
+
public:
|
| 676 |
+
// -- Milestone 3: machine-auditable evidence for a decision ------------------
|
| 677 |
+
// Built AFTER decide(): per question, the winning candidate's supporting
|
| 678 |
+
// lanes (weight, generation, support/counter events, provenance window,
|
| 679 |
+
// context) and any contradiction records for this exact state. Read-only.
|
| 680 |
+
sfx::JV evidence_json(const std::string& state, const sfx::JV& questions,
|
| 681 |
+
const std::vector<Answer>& answers) const {
|
| 682 |
+
const std::vector<std::string> words = si::norm::normalize(state);
|
| 683 |
+
const std::uint64_t shash = stream_hash(words);
|
| 684 |
+
sfx::JVArr contr;
|
| 685 |
+
auto cit = conflicts_by_state_.find(shash);
|
| 686 |
+
if (cit != conflicts_by_state_.end())
|
| 687 |
+
for (std::size_t idx : cit->second)
|
| 688 |
+
if (idx < conflicts_.size()) contr.push_back(conflicts_[idx]);
|
| 689 |
+
|
| 690 |
+
sfx::JVObj qout;
|
| 691 |
+
std::size_t ai = 0;
|
| 692 |
+
for (const auto& qkv : questions.obj) {
|
| 693 |
+
const sfx::JV& q = qkv.second;
|
| 694 |
+
if (ai >= answers.size()) break;
|
| 695 |
+
const Answer& a = answers[ai++];
|
| 696 |
+
sfx::JVObj qe;
|
| 697 |
+
qe["type"] = sfx::JV(a.type);
|
| 698 |
+
qe["deferred"] = sfx::JV(a.deferred);
|
| 699 |
+
if (a.deferred) { qe["reason"] = sfx::JV(a.reason); qout[qkv.first] = sfx::JV(qe); continue; }
|
| 700 |
+
|
| 701 |
+
std::string argmax;
|
| 702 |
+
if (a.type == "choice") argmax = a.choice;
|
| 703 |
+
else if (a.type == "score") {
|
| 704 |
+
float top = -1.0f;
|
| 705 |
+
for (const auto& kv : a.probabilities) if (kv.second > top) { top = kv.second; argmax = kv.first; }
|
| 706 |
+
} else {
|
| 707 |
+
argmax = a.probability >= 0.5f ? "true" : "false";
|
| 708 |
+
qe["probability"] = std::round(a.probability * 1000.0f) / 1000.0f;
|
| 709 |
+
}
|
| 710 |
+
qe["argmax"] = sfx::JV(argmax);
|
| 711 |
+
|
| 712 |
+
// the probe tokens the readout actually measured for the winner
|
| 713 |
+
std::string probe_text = argmax;
|
| 714 |
+
if (q.has("criteria")) {
|
| 715 |
+
const sfx::JV& crit = q.at("criteria");
|
| 716 |
+
if (crit.is_obj() && crit.has(argmax)) probe_text = argmax + " " + crit.at(argmax).as_str();
|
| 717 |
+
else if (crit.is_arr())
|
| 718 |
+
for (const auto& v : crit.arr) if (v.as_str() == argmax) probe_text = argmax;
|
| 719 |
+
}
|
| 720 |
+
const std::vector<std::string> probe = si::norm::normalize(probe_text);
|
| 721 |
+
|
| 722 |
+
struct Sup { std::string lane; float w; si::LaneEvidence e; std::uint32_t gen; };
|
| 723 |
+
std::vector<Sup> sups;
|
| 724 |
+
for (const auto& w : words) {
|
| 725 |
+
if (!si_.has(w)) continue;
|
| 726 |
+
const si::NodeId a = si_.find(w);
|
| 727 |
+
if (si_.node_energy(a) <= 0.0f) continue;
|
| 728 |
+
for (const auto& p : probe) {
|
| 729 |
+
if (!si_.has(p)) continue;
|
| 730 |
+
const si::NodeId b = si_.find(p);
|
| 731 |
+
const float lw = si_.lane_weight(a, b);
|
| 732 |
+
if (lw <= 0.0f) continue;
|
| 733 |
+
Sup s; s.lane = w + " -> " + p; s.w = lw;
|
| 734 |
+
s.gen = si_.generation_of(a, b);
|
| 735 |
+
si_.evidence_of(a, b, s.e);
|
| 736 |
+
sups.push_back(s);
|
| 737 |
+
}
|
| 738 |
+
}
|
| 739 |
+
std::sort(sups.begin(), sups.end(),
|
| 740 |
+
[](const Sup& x, const Sup& y) { return x.w > y.w; });
|
| 741 |
+
sfx::JVArr lanes;
|
| 742 |
+
for (std::size_t i = 0; i < sups.size() && i < 8; ++i)
|
| 743 |
+
lanes.push_back(sfx::JV(sfx::JVObj{
|
| 744 |
+
{"lane", sfx::JV(sups[i].lane)},
|
| 745 |
+
{"weight", std::round(sups[i].w * 10000.0f) / 10000.0f},
|
| 746 |
+
{"generation", static_cast<double>(sups[i].gen)},
|
| 747 |
+
{"support_events", static_cast<double>(sups[i].e.support_events)},
|
| 748 |
+
{"counter_events", static_cast<double>(sups[i].e.counter_events)},
|
| 749 |
+
{"first_seq", static_cast<double>(sups[i].e.first_seq)},
|
| 750 |
+
{"last_seq", static_cast<double>(sups[i].e.last_seq)},
|
| 751 |
+
{"context", sfx::JV(sups[i].e.context)}}));
|
| 752 |
+
qe["supporting_lanes"] = sfx::JV(lanes);
|
| 753 |
+
qe["supporting_lane_total"] = static_cast<double>(sups.size());
|
| 754 |
+
qout[qkv.first] = sfx::JV(qe);
|
| 755 |
+
}
|
| 756 |
+
return sfx::JV(sfx::JVObj{
|
| 757 |
+
{"state_hash_hex", sfx::JV(hex64(shash))},
|
| 758 |
+
{"contested", sfx::JV(!contr.empty())},
|
| 759 |
+
{"contradictions", sfx::JV(contr)},
|
| 760 |
+
{"questions", sfx::JV(qout)},
|
| 761 |
+
{"note", sfx::JV("evidence is a read-only ledger view; lane weights drive the field, the ledger never does")}});
|
| 762 |
+
}
|
| 763 |
+
|
| 764 |
+
private:
|
| 765 |
+
|
| 766 |
+
static float softmax_ps(const std::vector<float>& e, std::vector<float>& p, float T) {
|
| 767 |
+
float maxe = *std::max_element(e.begin(), e.end());
|
| 768 |
+
float z = 0.0f;
|
| 769 |
+
p.assign(e.size(), 0.0f);
|
| 770 |
+
// v2.1: honor the fitted temperature down to its search floor — the
|
| 771 |
+
// old 0.005 clamp silently discarded a fitted T below it (fitted
|
| 772 |
+
// confidences were computed at 0.005 no matter what calibration.json
|
| 773 |
+
// said). exp((e - maxe)/T) <= 1 for any T > 0: overflow impossible.
|
| 774 |
+
const float Ts = std::max(1e-6f, T);
|
| 775 |
+
for (std::size_t i = 0; i < e.size(); ++i) { p[i] = std::exp((e[i] - maxe) / Ts); z += p[i]; }
|
| 776 |
+
for (auto& v : p) v /= z;
|
| 777 |
+
return maxe;
|
| 778 |
+
}
|
| 779 |
+
|
| 780 |
+
static float entropy_confidence(const std::vector<float>& p) {
|
| 781 |
+
if (p.size() < 2) return 0.5f;
|
| 782 |
+
float h = 0.0f;
|
| 783 |
+
for (float v : p) if (v > 1e-9f) h -= v * std::log(v);
|
| 784 |
+
float conf = 1.0f - static_cast<float>(h / std::log(static_cast<double>(p.size())));
|
| 785 |
+
return std::max(0.0f, std::min(1.0f, conf));
|
| 786 |
+
}
|
| 787 |
+
|
| 788 |
+
void decide_choice(const sfx::JV& q, Answer& a) {
|
| 789 |
+
const sfx::JV& crit = q.at("criteria");
|
| 790 |
+
std::vector<std::string> labels; std::vector<float> energies;
|
| 791 |
+
if (crit.is_obj())
|
| 792 |
+
for (const auto& kv : crit.obj) {
|
| 793 |
+
labels.push_back(kv.first);
|
| 794 |
+
energies.push_back(probe_energy(kv.first, kv.second.as_str()));
|
| 795 |
+
}
|
| 796 |
+
else if (crit.is_arr())
|
| 797 |
+
for (const auto& v : crit.arr) {
|
| 798 |
+
labels.push_back(v.as_str());
|
| 799 |
+
energies.push_back(probe_energy(v.as_str(), ""));
|
| 800 |
+
}
|
| 801 |
+
if (labels.empty()) { a.deferred = true; a.reason = "no_options"; return; }
|
| 802 |
+
std::vector<float> p;
|
| 803 |
+
softmax_ps(energies, p, calib_.choice_temperature);
|
| 804 |
+
std::size_t best = std::max_element(p.begin(), p.end()) - p.begin();
|
| 805 |
+
a.choice = labels[best];
|
| 806 |
+
for (std::size_t i = 0; i < labels.size(); ++i)
|
| 807 |
+
a.probabilities.emplace_back(labels[i], p[i]);
|
| 808 |
+
a.confidence = entropy_confidence(p);
|
| 809 |
+
}
|
| 810 |
+
|
| 811 |
+
void decide_score(const sfx::JV& q, Answer& a) {
|
| 812 |
+
const sfx::JV& crit = q.at("criteria");
|
| 813 |
+
std::vector<std::string> labels; std::vector<float> energies;
|
| 814 |
+
if (crit.is_arr())
|
| 815 |
+
for (const auto& v : crit.arr) { labels.push_back(v.as_str()); energies.push_back(probe_energy(v.as_str(), "")); }
|
| 816 |
+
else if (crit.is_obj())
|
| 817 |
+
for (const auto& kv : crit.obj) { labels.push_back(kv.first); energies.push_back(probe_energy(kv.first, kv.second.as_str())); }
|
| 818 |
+
if (labels.empty()) { a.deferred = true; a.reason = "no_levels"; return; }
|
| 819 |
+
std::vector<float> p;
|
| 820 |
+
softmax_ps(energies, p, calib_.score_temperature);
|
| 821 |
+
float val = 0.0f;
|
| 822 |
+
for (std::size_t i = 0; i < labels.size(); ++i) {
|
| 823 |
+
a.probabilities.emplace_back(labels[i], p[i]);
|
| 824 |
+
val += p[i] * static_cast<float>(i);
|
| 825 |
+
}
|
| 826 |
+
a.value = val;
|
| 827 |
+
a.confidence = entropy_confidence(p);
|
| 828 |
+
}
|
| 829 |
+
|
| 830 |
+
void decide_noul(const sfx::JV& q, Answer& a) {
|
| 831 |
+
float s = noul_support(q.at("instructions").as_str());
|
| 832 |
+
a.probability = 1.0f / (1.0f + std::exp(-(calib_.noul_a * s + calib_.noul_b)));
|
| 833 |
+
a.confidence = std::fabs(a.probability - 0.5f) * 2.0f;
|
| 834 |
+
}
|
| 835 |
+
|
| 836 |
+
// -- calibration fitting (tool-side numerical search, no core changes) ------
|
| 837 |
+
static float nll_temperature(const std::vector<CalibRow>& rows, const std::string& type, float T) {
|
| 838 |
+
// v2.1: multi-class NLL over the FULL candidate vector — the textbook
|
| 839 |
+
// temperature-scaling objective (Guo et al. 2017). Every candidate
|
| 840 |
+
// participates, so a wrong-but-tied gold label keeps p_gold ~ 1/nk
|
| 841 |
+
// under ANY temperature and properly punishes over-sharpening.
|
| 842 |
+
float nll = 0.0f; std::size_t n = 0;
|
| 843 |
+
// NO floor clamp here beyond positivity: the max-subtracted softmax
|
| 844 |
+
// is overflow-safe for any T > 0 (exponents are <= 0; deep negatives
|
| 845 |
+
// just underflow to 0). A 0.005 floor made NLL flat below 0.005 and
|
| 846 |
+
// hid the true optimum from the search.
|
| 847 |
+
const float Ts = std::max(1e-6f, T);
|
| 848 |
+
for (const auto& r : rows) {
|
| 849 |
+
if (r.type != type || r.energies.empty()) continue;
|
| 850 |
+
++n;
|
| 851 |
+
float maxe = -1e30f;
|
| 852 |
+
for (const auto& kv : r.energies) maxe = std::max(maxe, kv.second);
|
| 853 |
+
float z = 0.0f, pl = 0.0f;
|
| 854 |
+
for (const auto& kv : r.energies) {
|
| 855 |
+
const float v = std::exp((kv.second - maxe) / Ts);
|
| 856 |
+
z += v;
|
| 857 |
+
if (kv.first == r.label) pl = v;
|
| 858 |
+
}
|
| 859 |
+
nll -= std::log(std::max(pl, 1e-9f) / std::max(z, 1e-9f));
|
| 860 |
+
}
|
| 861 |
+
return n > 0 ? nll / static_cast<float>(n) : 0.0f;
|
| 862 |
+
}
|
| 863 |
+
|
| 864 |
+
static void fit_temperature(const std::vector<CalibRow>& rows, const std::string& type, float& T) {
|
| 865 |
+
// Bounds span the substrate's OWN energy-gap scale: readout gaps on
|
| 866 |
+
// unfamiliar states are O(0.001..0.05), so a temperature floor of
|
| 867 |
+
// 0.005 capped achievable sharpness at exp(gap/0.005) and left
|
| 868 |
+
// correct answers under-confident. 0.0005 covers gaps down to
|
| 869 |
+
// ~0.003; the max-subtracted softmax is numerically stable all the
|
| 870 |
+
// way down (exp(-large) simply underflows to 0). The multi-class NLL
|
| 871 |
+
// guards the fit itself: with any argmax-wrong row in the fit set
|
| 872 |
+
// the optimum stays off the floor (sharpening a wrong answer costs
|
| 873 |
+
// NLL), which is exactly the safeguard the pairwise view lacked.
|
| 874 |
+
const float lo = 0.0005f, hi = 20.0f;
|
| 875 |
+
float a = lo, b = hi;
|
| 876 |
+
for (int it = 0; it < 60; ++it) { // golden-section on NLL
|
| 877 |
+
float m1 = a + (b - a) / 3.0f, m2 = b - (b - a) / 3.0f;
|
| 878 |
+
if (nll_temperature(rows, type, m1) < nll_temperature(rows, type, m2)) b = m2; else a = m1;
|
| 879 |
+
}
|
| 880 |
+
const float cand = (a + b) / 2.0f;
|
| 881 |
+
if (nll_temperature(rows, type, cand) < nll_temperature(rows, type, 1.0f))
|
| 882 |
+
T = cand;
|
| 883 |
+
}
|
| 884 |
+
|
| 885 |
+
void fit_platt(const std::vector<CalibRow>& rows) {
|
| 886 |
+
std::vector<std::pair<float, int>> pts;
|
| 887 |
+
for (const auto& r : rows) if (r.type == "noul") pts.emplace_back(r.support, r.y);
|
| 888 |
+
if (pts.size() < 4) return;
|
| 889 |
+
float a = std::max(10.0f, calib_.noul_a), b = calib_.noul_b;
|
| 890 |
+
float lr = 0.5f; // decaying lr, long run:
|
| 891 |
+
for (int it = 0; it < 4000; ++it) { // separable data needs a
|
| 892 |
+
float ga = 0.0f, gb = 0.0f; // steep slope to converge
|
| 893 |
+
for (const auto& pt : pts) {
|
| 894 |
+
float p = 1.0f / (1.0f + std::exp(-(a * pt.first + b)));
|
| 895 |
+
float err = static_cast<float>(pt.second) - p;
|
| 896 |
+
ga += err * pt.first; gb += err;
|
| 897 |
+
}
|
| 898 |
+
ga /= static_cast<float>(pts.size()); gb /= static_cast<float>(pts.size());
|
| 899 |
+
a += lr * ga; b += lr * gb;
|
| 900 |
+
lr *= 0.999f;
|
| 901 |
+
}
|
| 902 |
+
a = std::max(0.5f, std::min(40.0f, a));
|
| 903 |
+
b = std::max(-15.0f, std::min(2.0f, b));
|
| 904 |
+
calib_.noul_a = a; calib_.noul_b = b;
|
| 905 |
+
}
|
| 906 |
+
|
| 907 |
+
si::Substrate si_;
|
| 908 |
+
Calibration calib_;
|
| 909 |
+
bool energy_norm_ = false; // Milestone-1 gain knob (default off)
|
| 910 |
+
std::unordered_set<std::uint64_t> lesson_hashes_; // Milestone-2 dedup memory
|
| 911 |
+
// Milestone-3 audit state
|
| 912 |
+
std::string context_ = "default";
|
| 913 |
+
std::uint64_t teach_seq_ = 0;
|
| 914 |
+
std::map<std::uint64_t, Taught> taught_outcomes_; // state-stream hash -> out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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// SyFox CLI — learn / calibrate / decide / demo
|
| 3 |
+
// (thin tooling around the SI substrate core; no logic lives here)
|
| 4 |
+
// ============================================================================
|
| 5 |
+
#include "core/syfox.hpp"
|
| 6 |
+
#include "core/derive.hpp"
|
| 7 |
+
#include "core/bench.hpp"
|
| 8 |
+
#include "core/gate.hpp"
|
| 9 |
+
#include "core/recall.hpp"
|
| 10 |
+
#include "core/firewall.hpp"
|
| 11 |
+
|
| 12 |
+
#include <cmath>
|
| 13 |
+
#include <chrono>
|
| 14 |
+
#include <cstdio>
|
| 15 |
+
#include <cstring>
|
| 16 |
+
#include <fstream>
|
| 17 |
+
#include <iostream>
|
| 18 |
+
#include <map>
|
| 19 |
+
#include <sstream>
|
| 20 |
+
#include <string>
|
| 21 |
+
#include <thread>
|
| 22 |
+
#include <vector>
|
| 23 |
+
#if defined(_OPENMP)
|
| 24 |
+
#include <omp.h>
|
| 25 |
+
#endif
|
| 26 |
+
|
| 27 |
+
namespace {
|
| 28 |
+
|
| 29 |
+
void usage_exit();
|
| 30 |
+
|
| 31 |
+
struct Args {
|
| 32 |
+
std::string model = "model";
|
| 33 |
+
std::string examples;
|
| 34 |
+
std::string state;
|
| 35 |
+
std::string questions;
|
| 36 |
+
std::string domain;
|
| 37 |
+
std::string concept;
|
| 38 |
+
long steps = 64; // dream steps
|
| 39 |
+
unsigned long long seed = 0x5EED5EEDull; // dream seed (deterministic by default)
|
| 40 |
+
std::string eval; // bench eval rows (defaults to --examples)
|
| 41 |
+
std::string gate; // derivation gate rows (no-regression replay)
|
| 42 |
+
std::string memories; // recall memory store (jsonl)
|
| 43 |
+
long topk = 5; // recall top-k
|
| 44 |
+
std::string split; // bench --split train|heldout (P1 eval split)
|
| 45 |
+
bool coverage_curve = false; // bench --coverage-curve (P2 headline metric)
|
| 46 |
+
std::string synonyms; // synonym table path (default data/synonyms.txt)
|
| 47 |
+
// v2.2 multilingual + active-learning surface
|
| 48 |
+
std::string lang; // --lang auto|<slug>: route to <model>-<script>; empty = off
|
| 49 |
+
int ngrams_mode = 0; // --ngrams on|off: 1/-1 explicit; 0 = policy default
|
| 50 |
+
bool augment = false; // learn --augment: mass-guarded variant lessons
|
| 51 |
+
float typos = 0; // bench --typos P: deterministic corruption sweep (0..100)
|
| 52 |
+
std::string deferrals; // decide --log-deferrals FILE.jsonl (active-learning loop)
|
| 53 |
+
std::string out; // active --out FILE.jsonl (labeling worksheet)
|
| 54 |
+
long min_count = 1; // active --min-count N
|
| 55 |
+
bool dedup = false; // learn --dedup: skip exact duplicate lessons (M2)
|
| 56 |
+
bool novelty = false; // learn --novelty: per-lesson dose by novelty (M2)
|
| 57 |
+
float novelty_floor = 0.25f; // learn --novelty-floor F (A/B knob)
|
| 58 |
+
bool energy_norm = false; // decide-side energy gain for big-corpus fabrics (M1)
|
| 59 |
+
float defer_margin = 0; // decide --defer-margin P: defer when p1-p2 < P
|
| 60 |
+
// (honest uncertainty at the decision layer; the
|
| 61 |
+
// physics still decided — this is a disclosure knob)
|
| 62 |
+
bool evidence = false; // decide --evidence: machine-auditable evidence JSON (M3)
|
| 63 |
+
bool adversarial = false; // bench --adversarial: M4 stress suite (read-only)
|
| 64 |
+
std::string mix; // bench --mix FILE: cross-domain vocabulary source (M4)
|
| 65 |
+
long threads = 0; // --threads N: OMP settle threads (1 = sequential; 0 = default)
|
| 66 |
+
long throughput = 0; // bench --throughput N: batched multicore decisions/sec (M5)
|
| 67 |
+
long epochs = 1; // learn --epochs N: consolidation passes (see lane_decay)
|
| 68 |
+
long latency_reps = 20; // bench --latency-reps N (timing repeats per probe)
|
| 69 |
+
long replays = 2; // bench --replays N (determinism double-run count)
|
| 70 |
+
bool state_file = false, questions_file = false;
|
| 71 |
+
// SI-faithful selection modes (off by default; never persisted into the model)
|
| 72 |
+
bool salience_gating = false, miller_window = false;
|
| 73 |
+
};
|
| 74 |
+
|
| 75 |
+
// Apply the CLI mode overrides after load_model(). Mode-neutral by design:
|
| 76 |
+
// substrate.bin stays untouched, flags live only for this process.
|
| 77 |
+
void apply_modes(syfox::Engine& eng, const Args& a) {
|
| 78 |
+
eng.substrate().set_source_modes(a.salience_gating, a.miller_window);
|
| 79 |
+
// v3 Milestone 5: --threads N controls deterministic parallel settle on
|
| 80 |
+
// OMP builds (bit-identical to sequential; test-verified). N=1 forces the
|
| 81 |
+
// sequential path; N=0 leaves the default. Non-OMP builds ignore it.
|
| 82 |
+
if (a.threads > 0) {
|
| 83 |
+
#if defined(_OPENMP)
|
| 84 |
+
omp_set_num_threads(static_cast<int>(a.threads));
|
| 85 |
+
#endif
|
| 86 |
+
eng.substrate().set_parallel_settle(a.threads != 1);
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
std::string read_file(const std::string& path) {
|
| 91 |
+
std::ifstream f(path);
|
| 92 |
+
if (!f) { std::cerr << "syfox: cannot open " << path << "\n"; std::exit(2); }
|
| 93 |
+
std::string buf((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
| 94 |
+
return buf;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
std::vector<sfx::JV> load_jsonl(const std::string& path) {
|
| 98 |
+
std::vector<sfx::JV> rows;
|
| 99 |
+
std::ifstream f(path);
|
| 100 |
+
if (!f) { std::cerr << "syfox: cannot open " << path << "\n"; std::exit(2); }
|
| 101 |
+
std::string line;
|
| 102 |
+
while (std::getline(f, line)) {
|
| 103 |
+
if (line.empty() || line[0] == '#' || line[0] == '/') continue;
|
| 104 |
+
try { rows.push_back(sfx::JV::parse(line)); }
|
| 105 |
+
catch (const std::exception& e) { std::cerr << "syfox: " << path << ": " << e.what() << "\n"; std::exit(2); }
|
| 106 |
+
}
|
| 107 |
+
return rows;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
// The label's own description text inside criteria (for choice/score outcomes).
|
| 111 |
+
// For array criteria the label is the level INDEX ("0","1","2") or the level text.
|
| 112 |
+
std::string outcome_text(const sfx::JV& q, const std::string& label) {
|
| 113 |
+
const sfx::JV& crit = q.at("criteria");
|
| 114 |
+
if (crit.is_obj() && crit.has(label)) return label + " " + crit.at(label).as_str();
|
| 115 |
+
if (crit.is_arr()) {
|
| 116 |
+
for (const auto& v : crit.arr)
|
| 117 |
+
if (v.as_str() == label) return label; // label is the level text
|
| 118 |
+
long idx = std::strtol(label.c_str(), nullptr, 10);
|
| 119 |
+
if (idx >= 0 && idx < static_cast<long>(crit.arr.size()))
|
| 120 |
+
return crit.arr[static_cast<std::size_t>(idx)].as_str(); // label is the index
|
| 121 |
+
}
|
| 122 |
+
return label;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
// -- multilingual routing (v2.2) -------------------------------------------
|
| 126 |
+
// --lang empty : v2.1 behavior — whatever --model says, no detection (off)
|
| 127 |
+
// --lang auto : detect the script of the text, use <model>-<script-slug>
|
| 128 |
+
// --lang slug : force a script family (latin, bengali, devanagari, ...)
|
| 129 |
+
// Read commands (decide/bench/calibrate/recall) fall back to the base model
|
| 130 |
+
// with an honest note when the routed substrate is missing; learn CREATES
|
| 131 |
+
// the routed substrate (that is how per-script fabrics grow).
|
| 132 |
+
//
|
| 133 |
+
// Trigram policy: when the user did not pass --ngrams explicitly, sub-word
|
| 134 |
+
// bridges ACTIVATE automatically whenever the routed substrate is non-Latin
|
| 135 |
+
// (the script barrier and tiny vocabularies make them load-bearing there);
|
| 136 |
+
// Latin keeps the word-level stream that reproduces the v2.1 baselines.
|
| 137 |
+
std::string route_model(const Args& a, const std::string& state_text,
|
| 138 |
+
std::string& note, bool for_learning) {
|
| 139 |
+
note.clear();
|
| 140 |
+
if (a.lang.empty()) return a.model;
|
| 141 |
+
const si::script::Script sc = (a.lang == "auto")
|
| 142 |
+
? si::script::detect_script(state_text)
|
| 143 |
+
: si::script::from_slug(a.lang);
|
| 144 |
+
if (sc == si::script::Script::Unknown) {
|
| 145 |
+
note = "script=unknown; using base model";
|
| 146 |
+
return a.model;
|
| 147 |
+
}
|
| 148 |
+
if (a.ngrams_mode == 0) // policy default (explicit flag wins)
|
| 149 |
+
si::norm::grams_enabled() = (sc != si::script::Script::Latin);
|
| 150 |
+
const std::string suffix = std::string("-") + si::script::slug(sc);
|
| 151 |
+
if (a.model.size() > suffix.size() &&
|
| 152 |
+
a.model.compare(a.model.size() - suffix.size(), suffix.size(), suffix) == 0)
|
| 153 |
+
return a.model; // already the routed substrate
|
| 154 |
+
const std::string routed = a.model + suffix;
|
| 155 |
+
if (!for_learning) {
|
| 156 |
+
std::ifstream probe(routed + "/substrate.bin");
|
| 157 |
+
if (!probe) {
|
| 158 |
+
note = "no " + routed + " substrate trained; falling back to " + a.model
|
| 159 |
+
+ " (honest silence still guards untaught vocabulary)";
|
| 160 |
+
return a.model;
|
| 161 |
+
}
|
| 162 |
+
}
|
| 163 |
+
note = "script=" + std::string(si::script::slug(sc)) + " -> " + routed;
|
| 164 |
+
return routed;
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
void cmd_learn(const Args& a) {
|
| 168 |
+
// Milestone-1 firewall: hidden/calibration splits never teach the fabric.
|
| 169 |
+
if (!syfox::firewall::learn_may_read(a.examples)) {
|
| 170 |
+
std::cerr << "syfox: firewall: " << a.examples << " is a "
|
| 171 |
+
<< syfox::firewall::role_name(syfox::firewall::role_of_path(a.examples))
|
| 172 |
+
<< " split — learn is refused (hidden rows never train, calibrate, "
|
| 173 |
+
"derive, or select models)\n";
|
| 174 |
+
std::exit(2);
|
| 175 |
+
}
|
| 176 |
+
auto rows = load_jsonl(a.examples);
|
| 177 |
+
const syfox::LearnPolicy lp{a.dedup, a.novelty, a.novelty_floor};
|
| 178 |
+
long lessons = 0, skipped = 0;
|
| 179 |
+
// v3: consolidation passes. The substrate's own forgetting law decays
|
| 180 |
+
// every lane 0.995x per lesson, so a 25k-lesson SINGLE pass is
|
| 181 |
+
// recency-truncated (early lanes are decayed away before training ends).
|
| 182 |
+
// --epochs N re-teaches the same distinct lessons N times — measured on
|
| 183 |
+
// game/guard hidden tests this recovers early knowledge (deterministically,
|
| 184 |
+
// unlike accidental incremental accumulation). Distinctness still rules
|
| 185 |
+
// per lesson: see the Milestone-2 A/B.
|
| 186 |
+
const std::vector<const sfx::JV*> epoch_rows = [&]() {
|
| 187 |
+
std::vector<const sfx::JV*> v;
|
| 188 |
+
for (long e = 0; e < a.epochs; ++e)
|
| 189 |
+
for (const auto& r : rows) v.push_back(&r);
|
| 190 |
+
return v;
|
| 191 |
+
}();
|
| 192 |
+
if (!a.lang.empty()) {
|
| 193 |
+
// v2.2 --lang: route every lesson by its script family into a
|
| 194 |
+
// per-script substrate (<model>-<slug>). Latin gets its own substrate
|
| 195 |
+
// like every other family — one fabric per script is the isolation the
|
| 196 |
+
// routing contract promises. Group order is std::map order: deterministic.
|
| 197 |
+
std::map<std::string, std::vector<const sfx::JV*>> groups;
|
| 198 |
+
for (const auto& ex : rows) {
|
| 199 |
+
const si::script::Script sc = (a.lang == "auto")
|
| 200 |
+
? si::script::detect_script(ex.at("state").as_str())
|
| 201 |
+
: si::script::from_slug(a.lang);
|
| 202 |
+
groups[si::script::slug(sc)].push_back(&ex);
|
| 203 |
+
}
|
| 204 |
+
sfx::JVArr routed;
|
| 205 |
+
for (auto& g : groups) {
|
| 206 |
+
const std::string dir = a.model + "-" + g.first;
|
| 207 |
+
// trigram policy per script group (explicit --ngrams wins)
|
| 208 |
+
si::norm::grams_enabled() = (a.ngrams_mode != 0)
|
| 209 |
+
? (a.ngrams_mode == 1) : (g.first != "latin");
|
| 210 |
+
syfox::Engine eng;
|
| 211 |
+
eng.load_model(dir); // incremental if exists
|
| 212 |
+
eng.set_context(dir); // audit context tag (M3)
|
| 213 |
+
for (const auto* exp : epoch_rows) {
|
| 214 |
+
const sfx::JV& qs = exp->at("questions");
|
| 215 |
+
const sfx::JV& labels = exp->at("labels");
|
| 216 |
+
const std::string state = exp->at("state").as_str();
|
| 217 |
+
for (const auto& qkv : qs.obj) {
|
| 218 |
+
const sfx::JV& q = qkv.second;
|
| 219 |
+
std::string type = q.at("type").as_str();
|
| 220 |
+
std::string label = labels.at(qkv.first).as_str();
|
| 221 |
+
bool learned = false;
|
| 222 |
+
if (type == "choice" || type == "score")
|
| 223 |
+
eng.learn_example(state, q.at("instructions").as_str(),
|
| 224 |
+
outcome_text(q, label), a.augment, lp, &learned);
|
| 225 |
+
else if (type == "noul")
|
| 226 |
+
eng.learn_noul(state, q.at("instructions").as_str(),
|
| 227 |
+
label == "true", a.augment, lp, &learned);
|
| 228 |
+
++lessons;
|
| 229 |
+
if (!learned) ++skipped;
|
| 230 |
+
}
|
| 231 |
+
}
|
| 232 |
+
eng.save_model(dir);
|
| 233 |
+
routed.push_back(sfx::JV(sfx::JVObj{
|
| 234 |
+
{"script", sfx::JV(g.first)}, {"model", sfx::JV(dir)},
|
| 235 |
+
{"lessons", static_cast<double>(g.second.size())},
|
| 236 |
+
{"dedup_skipped", static_cast<double>(0)},
|
| 237 |
+
{"contradictions", static_cast<double>(eng.conflicts().size())},
|
| 238 |
+
{"nodes", static_cast<double>(eng.substrate().node_count())},
|
| 239 |
+
{"lanes", static_cast<double>(eng.substrate().lane_count())}}));
|
| 240 |
+
}
|
| 241 |
+
std::cout << sfx::JV(sfx::JVObj{
|
| 242 |
+
{"command", sfx::JV("learn")}, {"examples", sfx::JV(a.examples)},
|
| 243 |
+
{"lang", sfx::JV(a.lang)}, {"augment", sfx::JV(a.augment)},
|
| 244 |
+
{"dedup", sfx::JV(a.dedup)}, {"novelty", sfx::JV(a.novelty)},
|
| 245 |
+
{"epochs", static_cast<double>(a.epochs)},
|
| 246 |
+
{"lessons", static_cast<double>(lessons)},
|
| 247 |
+
{"dedup_skipped", static_cast<double>(skipped)},
|
| 248 |
+
{"routed", sfx::JV(routed)},
|
| 249 |
+
{"note", sfx::JV("lessons routed per script family: one SI substrate per script")}}).dump() << "\n";
|
| 250 |
+
return;
|
| 251 |
+
}
|
| 252 |
+
syfox::Engine eng;
|
| 253 |
+
eng.load_model(a.model); // incremental if model exists
|
| 254 |
+
eng.set_context(a.model); // audit context tag (M3)
|
| 255 |
+
for (const auto* exp : epoch_rows) {
|
| 256 |
+
std::string state = exp->at("state").as_str();
|
| 257 |
+
const sfx::JV& qs = exp->at("questions");
|
| 258 |
+
const sfx::JV& labels = exp->at("labels");
|
| 259 |
+
for (const auto& qkv : qs.obj) {
|
| 260 |
+
const sfx::JV& q = qkv.second;
|
| 261 |
+
std::string type = q.at("type").as_str();
|
| 262 |
+
std::string label = labels.at(qkv.first).as_str();
|
| 263 |
+
bool learned = false;
|
| 264 |
+
if (type == "choice" || type == "score")
|
| 265 |
+
eng.learn_example(state, q.at("instructions").as_str(),
|
| 266 |
+
outcome_text(q, label), a.augment, lp, &learned);
|
| 267 |
+
else if (type == "noul")
|
| 268 |
+
eng.learn_noul(state, q.at("instructions").as_str(),
|
| 269 |
+
label == "true", a.augment, lp, &learned);
|
| 270 |
+
++lessons;
|
| 271 |
+
if (!learned) ++skipped;
|
| 272 |
+
}
|
| 273 |
+
}
|
| 274 |
+
eng.save_model(a.model);
|
| 275 |
+
std::cout << sfx::JV(sfx::JVObj{
|
| 276 |
+
{"command", sfx::JV("learn")}, {"examples", sfx::JV(a.examples)},
|
| 277 |
+
{"model", sfx::JV(a.model)}, {"augment", sfx::JV(a.augment)},
|
| 278 |
+
{"dedup", sfx::JV(a.dedup)}, {"novelty", sfx::JV(a.novelty)},
|
| 279 |
+
{"epochs", static_cast<double>(a.epochs)},
|
| 280 |
+
{"lessons", static_cast<double>(lessons)},
|
| 281 |
+
{"dedup_skipped", static_cast<double>(skipped)},
|
| 282 |
+
{"nodes", static_cast<double>(eng.substrate().node_count())},
|
| 283 |
+
{"lanes", static_cast<double>(eng.substrate().lane_count())},
|
| 284 |
+
{"contradictions", static_cast<double>(eng.conflicts().size())},
|
| 285 |
+
{"note", sfx::JV(a.dedup
|
| 286 |
+
? "exact duplicate lessons skipped (Milestone-2 distinct-experience policy)"
|
| 287 |
+
: "every lesson taught (legacy behavior)")}}).dump() << "\n";
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
void cmd_calibrate(const Args& a) {
|
| 291 |
+
// Milestone-1 firewall: the hidden test never sets a calibration scalar.
|
| 292 |
+
if (!syfox::firewall::calibrate_may_read(a.examples)) {
|
| 293 |
+
std::cerr << "syfox: firewall: " << a.examples << " is a HIDDEN test split"
|
| 294 |
+
<< " — calibrate is refused (hidden rows never participate in "
|
| 295 |
+
"calibration, training, derivation, or model selection)\n";
|
| 296 |
+
std::exit(2);
|
| 297 |
+
}
|
| 298 |
+
// v2.2 --lang: calibrate the substrate the examples route to (fitting a
|
| 299 |
+
// different script's substrate would set scalars on a fabric that never
|
| 300 |
+
// saw the rows — meaningless). Dominant script over the file's states.
|
| 301 |
+
std::string lang_note;
|
| 302 |
+
std::string model_dir = a.model;
|
| 303 |
+
if (!a.lang.empty()) {
|
| 304 |
+
auto probe_rows = load_jsonl(a.examples);
|
| 305 |
+
std::string agg;
|
| 306 |
+
for (const auto& r : probe_rows) if (r.has("state")) agg += r.at("state").as_str() + "\n";
|
| 307 |
+
model_dir = route_model(a, agg, lang_note, false);
|
| 308 |
+
}
|
| 309 |
+
syfox::Engine eng;
|
| 310 |
+
eng.load_model(model_dir);
|
| 311 |
+
if (a.energy_norm) eng.set_energy_norm(true);
|
| 312 |
+
auto rows = load_jsonl(a.examples);
|
| 313 |
+
auto calib_rows = eng.harvest_rows(rows);
|
| 314 |
+
// v2.1 (P6): report calibration honestly — MULTI-CLASS ECE on the fit
|
| 315 |
+
// rows BEFORE (T=1 / default Platt) and AFTER (whatever fit_calibration
|
| 316 |
+
// adopted; its 1-bit ECE guard may keep T=1). Same helper the fit uses,
|
| 317 |
+
// same definition bench reports.
|
| 318 |
+
eng.fit_calibration(calib_rows);
|
| 319 |
+
eng.save_model(model_dir);
|
| 320 |
+
const auto& c = eng.calibration();
|
| 321 |
+
const auto r4 = [](double v) { return std::round(v * 10000.0) / 10000.0; };
|
| 322 |
+
sfx::JVObj o;
|
| 323 |
+
o["command"] = sfx::JV("calibrate");
|
| 324 |
+
o["model"] = sfx::JV(model_dir);
|
| 325 |
+
if (!lang_note.empty()) o["lang_note"] = sfx::JV(lang_note);
|
| 326 |
+
o["fit_rows"] = sfx::JV(static_cast<double>(calib_rows.size()));
|
| 327 |
+
o["fit_source"] = sfx::JV(a.examples);
|
| 328 |
+
o["choice_temperature"] = std::round(c.choice_temperature * 10000.0) / 10000.0;
|
| 329 |
+
o["score_temperature"] = std::round(c.score_temperature * 10000.0) / 10000.0;
|
| 330 |
+
o["noul_a"] = std::round(c.noul_a * 10000.0) / 10000.0;
|
| 331 |
+
o["noul_b"] = std::round(c.noul_b * 10000.0) / 10000.0;
|
| 332 |
+
o["multiclass_ece_before"] = sfx::JV(sfx::JVObj{ // T = 1, default Platt
|
| 333 |
+
{"choice", r4(syfox::Engine::calibration_ece(calib_rows, "choice", 1.0f, 6.0f, -3.0f))},
|
| 334 |
+
{"score", r4(syfox::Engine::calibration_ece(calib_rows, "score", 1.0f, 6.0f, -3.0f))},
|
| 335 |
+
{"noul", r4(syfox::Engine::calibration_ece(calib_rows, "noul", 1.0f, 6.0f, -3.0f))}});
|
| 336 |
+
o["multiclass_ece_after"] = sfx::JV(sfx::JVObj{ // adopted parameters
|
| 337 |
+
{"choice", r4(syfox::Engine::calibration_ece(calib_rows, "choice", c.choice_temperature, c.noul_a, c.noul_b))},
|
| 338 |
+
{"score", r4(syfox::Engine::calibration_ece(calib_rows, "score", c.score_temperature, c.noul_a, c.noul_b))},
|
| 339 |
+
{"noul", r4(syfox::Engine::calibration_ece(calib_rows, "noul", 1.0f, c.noul_a, c.noul_b))}});
|
| 340 |
+
o["note"] = sfx::JV("fit rows supply energies only; if this is the held-out "
|
| 341 |
+
"split, the fabric itself never learned from them — the "
|
| 342 |
+
"fit sets 2-3 scalars (temperature/Platt), and argmax is "
|
| 343 |
+
"unaffected (temperature is monotone)");
|
| 344 |
+
std::cout << sfx::JV(o).dump() << "\n";
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
sfx::JV answers_to_json(const std::vector<syfox::Answer>& ans, const syfox::Usage& u) {
|
| 348 |
+
sfx::JVObj out;
|
| 349 |
+
for (const auto& a : ans) {
|
| 350 |
+
sfx::JVObj o;
|
| 351 |
+
if (a.type == "choice") {
|
| 352 |
+
o["choice"] = sfx::JV(a.choice);
|
| 353 |
+
sfx::JVObj probs;
|
| 354 |
+
for (const auto& p : a.probabilities) probs[p.first] = sfx::JV(std::round(p.second * 1000.0f) / 1000.0f);
|
| 355 |
+
o["probabilities"] = sfx::JV(probs);
|
| 356 |
+
o["confidence"] = sfx::JV(std::round(a.confidence * 1000.0f) / 1000.0f);
|
| 357 |
+
} else if (a.type == "score") {
|
| 358 |
+
o["score"] = sfx::JV(std::round(a.value * 1000.0f) / 1000.0f);
|
| 359 |
+
sfx::JVObj probs;
|
| 360 |
+
for (const auto& p : a.probabilities) probs[p.first] = sfx::JV(std::round(p.second * 1000.0f) / 1000.0f);
|
| 361 |
+
o["probabilities"] = sfx::JV(probs);
|
| 362 |
+
o["confidence"] = sfx::JV(std::round(a.confidence * 1000.0f) / 1000.0f);
|
| 363 |
+
} else if (a.type == "noul") {
|
| 364 |
+
o["noul"] = sfx::JV(std::round(a.probability * 1000.0f) / 1000.0f);
|
| 365 |
+
o["confidence"] = sfx::JV(std::round(a.confidence * 1000.0f) / 1000.0f);
|
| 366 |
+
}
|
| 367 |
+
o["deferred"] = sfx::JV(a.deferred);
|
| 368 |
+
if (!a.reason.empty()) o["reason"] = sfx::JV(a.reason);
|
| 369 |
+
out[a.qid] = sfx::JV(o);
|
| 370 |
+
}
|
| 371 |
+
sfx::JVObj usage{
|
| 372 |
+
{"state_tokens", static_cast<double>(u.state_tokens)},
|
| 373 |
+
{"vocabulary", static_cast<double>(u.vocabulary)},
|
| 374 |
+
{"lanes", static_cast<double>(u.lanes)},
|
| 375 |
+
{"settled_energy", std::round(u.settled_energy * 1000.0f) / 1000.0f},
|
| 376 |
+
{"calibrated", sfx::JV(u.calibrated)},
|
| 377 |
+
{"engine", std::string("syfox-") + syfox::VERSION},
|
| 378 |
+
{"core", "si-substrate"},
|
| 379 |
+
};
|
| 380 |
+
return sfx::JV(sfx::JVObj{{"answers", sfx::JV(out)}, {"usage", sfx::JV(usage)}});
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
void cmd_decide(const Args& a) {
|
| 384 |
+
std::string state = a.state_file ? read_file(a.state) : a.state;
|
| 385 |
+
std::string qtext = a.questions_file ? read_file(a.questions) : a.questions;
|
| 386 |
+
sfx::JV questions = sfx::JV::parse(qtext);
|
| 387 |
+
if (!questions.is_obj()) { std::cerr << "syfox: questions must be a JSON object\n"; std::exit(2); }
|
| 388 |
+
std::string lang_note;
|
| 389 |
+
const std::string model_dir = route_model(a, state, lang_note, false);
|
| 390 |
+
syfox::Engine eng;
|
| 391 |
+
eng.load_model(model_dir);
|
| 392 |
+
apply_modes(eng, a);
|
| 393 |
+
if (a.energy_norm) eng.set_energy_norm(true); // Milestone-1 gain knob
|
| 394 |
+
syfox::Usage u;
|
| 395 |
+
auto answers = eng.decide(state, questions, u);
|
| 396 |
+
u.calibrated = eng.calibration().fitted; // decide() resets Usage; set after
|
| 397 |
+
// --defer-margin P: the substrate still decides (physics untouched); a
|
| 398 |
+
// margin below P is DISCLOSED as a deferral instead of a confident-looking
|
| 399 |
+
// label. Measured motivation: reworded probe criteria can decide at
|
| 400 |
+
// |p1-p2| ~ 0.01-0.05 with confidence 0 — honest silence should extend
|
| 401 |
+
// to tied candidates, not only to a dark field.
|
| 402 |
+
if (a.defer_margin > 0) {
|
| 403 |
+
for (auto& ans : answers) {
|
| 404 |
+
if (ans.deferred || ans.probabilities.size() < 2) continue;
|
| 405 |
+
float p1 = 0, p2 = 0;
|
| 406 |
+
for (const auto& pr : ans.probabilities) {
|
| 407 |
+
if (pr.second > p1) { p2 = p1; p1 = pr.second; }
|
| 408 |
+
else if (pr.second > p2) p2 = pr.second;
|
| 409 |
+
}
|
| 410 |
+
if (p1 - p2 < a.defer_margin) {
|
| 411 |
+
ans.deferred = true;
|
| 412 |
+
ans.reason = "low_margin";
|
| 413 |
+
}
|
| 414 |
+
}
|
| 415 |
+
}
|
| 416 |
+
sfx::JV out = answers_to_json(answers, u);
|
| 417 |
+
if (!lang_note.empty()) out.obj["lang_note"] = sfx::JV(lang_note);
|
| 418 |
+
// v3 Milestone 3: machine-auditable evidence — supporting lanes with
|
| 419 |
+
// provenance, plus any contradiction records for this exact state.
|
| 420 |
+
if (a.evidence)
|
| 421 |
+
out.obj["evidence"] = eng.evidence_json(state, questions, answers);
|
| 422 |
+
// v2.2 active-learning loop, step 1: log deferrals for human labeling.
|
| 423 |
+
// Each row carries the state + the FULL question schema, so a labeled
|
| 424 |
+
// row is directly teachable with `syfox learn` — no reconstruction step.
|
| 425 |
+
if (!a.deferrals.empty()) {
|
| 426 |
+
bool any = false;
|
| 427 |
+
sfx::JVArr def;
|
| 428 |
+
for (const auto& ans : answers)
|
| 429 |
+
if (ans.deferred)
|
| 430 |
+
def.push_back(sfx::JV(sfx::JVObj{
|
| 431 |
+
{"qid", sfx::JV(ans.qid)}, {"reason", sfx::JV(ans.reason)}}));
|
| 432 |
+
if ((any = !def.empty())) {
|
| 433 |
+
std::ofstream log(a.deferrals, std::ios::app);
|
| 434 |
+
if (log)
|
| 435 |
+
log << sfx::JV(sfx::JVObj{
|
| 436 |
+
{"state", sfx::JV(state)},
|
| 437 |
+
{"questions", questions},
|
| 438 |
+
{"deferred", sfx::JV(def)},
|
| 439 |
+
{"settled_energy", std::round(u.settled_energy * 1000.0f) / 1000.0f}}).dump() << "\n";
|
| 440 |
+
out.obj["deferrals_logged"] = sfx::JV(static_cast<double>(def.size()));
|
| 441 |
+
}
|
| 442 |
+
}
|
| 443 |
+
std::cout << out.dump() << "\n";
|
| 444 |
+
}
|
| 445 |
+
|
| 446 |
+
// ---------------------------------------------------------------------------
|
| 447 |
+
// Built-in demos. No hand-coded decision rules anywhere: every answer comes
|
| 448 |
+
// out of the settled field of the SI substrate.
|
| 449 |
+
// ---------------------------------------------------------------------------
|
| 450 |
+
struct Demo { std::string name, state, questions; };
|
| 451 |
+
|
| 452 |
+
const std::vector<Demo>& demos_for(const std::string& domain) {
|
| 453 |
+
static const std::vector<Demo> tickets = {
|
| 454 |
+
{"stripe broken, losing sales",
|
| 455 |
+
"Hi, I've been trying to connect my stripe account for 3 days and it keeps failing. I'm losing sales. Please help ASAP.",
|
| 456 |
+
R"({"department":{"type":"choice","instructions":"Which team should handle this","criteria":{"billing":"payment or subscription issues","technical":"bugs or integration problems","sales":"pricing or account questions"}},"frustration":{"type":"score","instructions":"How frustrated the customer appears","criteria":["calm just stating facts","frustrated but civil","very angry strong language"]},"is_urgent":{"type":"noul","instructions":"the message conveys urgency or time sensitivity"}})"},
|
| 457 |
+
{"double charge refund",
|
| 458 |
+
"You charged me twice for the same invoice this month. Please refund the extra payment.",
|
| 459 |
+
R"({"department":{"type":"choice","instructions":"Which team should handle this","criteria":{"billing":"payment or subscription issues","technical":"bugs or integration problems","sales":"pricing or account questions"}},"frustration":{"type":"score","instructions":"How frustrated the customer appears","criteria":["calm just stating facts","frustrated but civil","very angry strong language"]},"is_urgent":{"type":"noul","instructions":"the message conveys urgency or time sensitivity"}})"},
|
| 460 |
+
{"team plan pricing",
|
| 461 |
+
"We want to upgrade to the team plan for twenty seats. Can you send the pricing?",
|
| 462 |
+
R"({"department":{"type":"choice","instructions":"Which team should handle this","criteria":{"billing":"payment or subscription issues","technical":"bugs or integration problems","sales":"pricing or account questions"}},"frustration":{"type":"score","instructions":"How frustrated the customer appears","criteria":["calm just stating facts","frustrated but civil","very angry strong language"]},"is_urgent":{"type":"noul","instructions":"the message conveys urgency or time sensitivity"}})"},
|
| 463 |
+
};
|
| 464 |
+
static const std::vector<Demo> game = {
|
| 465 |
+
{"zombies at night",
|
| 466 |
+
"Night. Zombies are spawning near the player. Health is dropping fast.",
|
| 467 |
+
R"({"action":{"type":"choice","instructions":"What should the bot do next","criteria":{"flee":"run away escape avoid danger retreat safe","fight":"attack combat weapon sword strike","dig_in":"hide wait build shelter fortify safe"}}})"},
|
| 468 |
+
{"calm day, build mode",
|
| 469 |
+
"Daytime. No threats nearby. The player wants a safehouse and materials are available.",
|
| 470 |
+
R"({"action":{"type":"choice","instructions":"What should the bot do next","criteria":{"flee":"run away escape avoid danger retreat safe","fight":"attack combat weapon sword strike","dig_in":"hide wait build shelter fortify safe"}}})"},
|
| 471 |
+
{"sword vs one zombie",
|
| 472 |
+
"A single zombie at close range. Full health. The player holds an iron sword.",
|
| 473 |
+
R"({"action":{"type":"choice","instructions":"What should the bot do next","criteria":{"flee":"run away escape avoid danger retreat safe","fight":"attack combat weapon sword strike","dig_in":"hide wait build shelter fortify safe"}}})"},
|
| 474 |
+
};
|
| 475 |
+
static const std::vector<Demo> guard = {
|
| 476 |
+
{"rm -rf on a coding task",
|
| 477 |
+
"task: add a column to the users table. plan: run the sql migration. command: rm -rf build/",
|
| 478 |
+
R"({"irreversible":{"type":"noul","instructions":"the command is irreversible or destructive"},"off_task":{"type":"noul","instructions":"the command is off task and unrelated to the goal"},"scope":{"type":"choice","instructions":"what does the command touch","criteria":{"none":"no changes at all","read":"only reads lists shows","write":"modifies project files or data","global":"system wide destructive or irreversible"}}})"},
|
| 479 |
+
{"intended db reset",
|
| 480 |
+
"task: reset the database. plan: restore from seed. command: make db-reset",
|
| 481 |
+
R"({"irreversible":{"type":"noul","instructions":"the command is irreversible or destructive"},"off_task":{"type":"noul","instructions":"the command is off task and unrelated to the goal"},"scope":{"type":"choice","instructions":"what does the command touch","criteria":{"none":"no changes at all","read":"only reads lists shows","write":"modifies project files or data","global":"system wide destructive or irreversible"}}})"},
|
| 482 |
+
{"harmless read",
|
| 483 |
+
"task: list the open issues. plan: check the tracker. command: gh issue list",
|
| 484 |
+
R"({"irreversible":{"type":"noul","instructions":"the command is irreversible or destructive"},"off_task":{"type":"noul","instructions":"the command is off task and unrelated to the goal"},"scope":{"type":"choice","instructions":"what does the command touch","criteria":{"none":"no changes at all","read":"only reads lists shows","write":"modifies project files or data","global":"system wide destructive or irreversible"}}})"},
|
| 485 |
+
};
|
| 486 |
+
if (domain == "game") return game;
|
| 487 |
+
if (domain == "guard") return guard;
|
| 488 |
+
return tickets;
|
| 489 |
+
}
|
| 490 |
+
|
| 491 |
+
void cmd_demo(const Args& a) {
|
| 492 |
+
syfox::Engine eng;
|
| 493 |
+
eng.load_model(a.model);
|
| 494 |
+
apply_modes(eng, a);
|
| 495 |
+
std::cout << "SyFox demo — domain: " << (a.domain.empty() ? "tickets" : a.domain)
|
| 496 |
+
<< " | core: si-substrate (no transformer, no classifier)\n";
|
| 497 |
+
for (const auto& d : demos_for(a.domain)) {
|
| 498 |
+
std::cout << "\n== " << d.name << " ==\n";
|
| 499 |
+
syfox::Usage u;
|
| 500 |
+
auto answers = eng.decide(d.state, sfx::JV::parse(d.questions), u);
|
| 501 |
+
u.calibrated = eng.calibration().fitted; // decide() resets Usage; set after
|
| 502 |
+
std::cout << answers_to_json(answers, u).dump() << "\n";
|
| 503 |
+
}
|
| 504 |
+
}
|
| 505 |
+
|
| 506 |
+
void cmd_stats(const Args& a) {
|
| 507 |
+
syfox::Engine eng;
|
| 508 |
+
eng.load_model(a.model);
|
| 509 |
+
apply_modes(eng, a); // stats reflects the modes this process would run under
|
| 510 |
+
std::cout << sfx::JV(sfx::JVObj{
|
| 511 |
+
{"nodes", static_cast<double>(eng.substrate().node_count())},
|
| 512 |
+
{"lanes", static_cast<double>(eng.substrate().lane_count())},
|
| 513 |
+
{"fabric_density", std::round(eng.substrate().fabric_density() * 1e6) / 1e6},
|
| 514 |
+
{"mean_out_degree", std::round(eng.substrate().mean_out_degree() * 1e3) / 1e3},
|
| 515 |
+
{"parallel_settle", sfx::JV(eng.substrate().parallel_settle_enabled())},
|
| 516 |
+
{"calibrated", sfx::JV(eng.calibration().fitted)},
|
| 517 |
+
{"choice_temperature", eng.calibration().choice_temperature},
|
| 518 |
+
{"noul_a", eng.calibration().noul_a},
|
| 519 |
+
{"noul_b", eng.calibration().noul_b},
|
| 520 |
+
{"salience_gating", sfx::JV(eng.substrate().config().salience_gating)},
|
| 521 |
+
{"miller_window", sfx::JV(eng.substrate().config().miller_window)}}).dump() << "\n";
|
| 522 |
+
}
|
| 523 |
+
|
| 524 |
+
// ---------------------------------------------------------------------------
|
| 525 |
+
// Jev-parity benchmark. Read-only; measures the axes the System One model
|
| 526 |
+
// class is judged on (accuracy, calibration, honesty, guardrail, latency,
|
| 527 |
+
// determinism). See core/bench.hpp for the axis-by-axis lineage.
|
| 528 |
+
//
|
| 529 |
+
// v2.1 eval-split honesty (P1): --split heldout scores the rows the fabric
|
| 530 |
+
// never learned from; the default train file is IN-SAMPLE and labelled as
|
| 531 |
+
// such in eval_source. --coverage-curve (P2) prints the coverage-vs-accuracy
|
| 532 |
+
// sweep — the headline metric, not top-1 accuracy.
|
| 533 |
+
// ---------------------------------------------------------------------------
|
| 534 |
+
void cmd_bench(const Args& a) {
|
| 535 |
+
syfox::Engine eng;
|
| 536 |
+
eng.load_model(a.model);
|
| 537 |
+
apply_modes(eng, a); // --threads (M5 OMP settle), SI modes
|
| 538 |
+
if (a.energy_norm) eng.set_energy_norm(true); // Milestone-1 gain knob
|
| 539 |
+
std::string eval_path = !a.eval.empty() ? a.eval : a.examples;
|
| 540 |
+
std::string split_note;
|
| 541 |
+
if (!a.split.empty()) {
|
| 542 |
+
if (!a.eval.empty()) {
|
| 543 |
+
std::cerr << "syfox: pass either --eval FILE or --split NAME, not both\n";
|
| 544 |
+
std::exit(2);
|
| 545 |
+
}
|
| 546 |
+
// domain name from the model dir: model-tickets -> data/tickets_<split>.jsonl
|
| 547 |
+
std::string dom = a.model;
|
| 548 |
+
const std::string pfx = "model-";
|
| 549 |
+
if (dom.rfind(pfx, 0) == 0) dom = dom.substr(pfx.size());
|
| 550 |
+
eval_path = "data/" + dom + "_" + a.split + ".jsonl";
|
| 551 |
+
std::ifstream probe(eval_path);
|
| 552 |
+
if (!probe) {
|
| 553 |
+
std::cerr << "syfox: --split " << a.split << " -> expected " << eval_path
|
| 554 |
+
<< " but it does not exist (run tools/split_data.py first, "
|
| 555 |
+
"or pass --eval FILE explicitly)\n";
|
| 556 |
+
std::exit(2);
|
| 557 |
+
}
|
| 558 |
+
split_note = a.split == "heldout"
|
| 559 |
+
? "held-out 30% split; fabric never taught from these rows"
|
| 560 |
+
: "train split; in-sample for the fabric";
|
| 561 |
+
} else if (eval_path.empty()) {
|
| 562 |
+
usage_exit();
|
| 563 |
+
} else if (!a.examples.empty() && eval_path == a.examples) {
|
| 564 |
+
split_note = "train split; in-sample for the fabric";
|
| 565 |
+
}
|
| 566 |
+
auto rows = load_jsonl(eval_path);
|
| 567 |
+
if (rows.empty()) { std::cerr << "syfox: no eval rows in " << eval_path << "\n"; std::exit(2); }
|
| 568 |
+
|
| 569 |
+
// v3 Milestone 5 --throughput N: batched multicore decisions over N worker
|
| 570 |
+
// threads, each owning a PRIVATE engine copy (decisions mutate the field,
|
| 571 |
+
// so workers never share a substrate). The metric is decisions/sec — a
|
| 572 |
+
// PERFORMANCE axis, not an accuracy headline: a checksum proves the work
|
| 573 |
+
// happened, argmaxes are not scored here. Determinism/accuracy numbers
|
| 574 |
+
// come only from the default sequential (or --threads OMP) runs.
|
| 575 |
+
if (a.throughput > 0) {
|
| 576 |
+
const std::size_t T = static_cast<std::size_t>(a.throughput);
|
| 577 |
+
auto probes = syfox::bench::eval_probes(rows);
|
| 578 |
+
if (probes.empty()) { std::cerr << "syfox: no probes for throughput\n"; std::exit(2); }
|
| 579 |
+
// single-thread in-process baseline (same probe order, same machine)
|
| 580 |
+
long base_count = 0;
|
| 581 |
+
double base_ck = 0.0;
|
| 582 |
+
const auto t0 = std::chrono::steady_clock::now();
|
| 583 |
+
for (const auto& p : probes) {
|
| 584 |
+
syfox::Usage u;
|
| 585 |
+
auto ans = eng.decide(p.state, p.questions, u);
|
| 586 |
+
base_ck += ans.empty() ? 0.0 : static_cast<double>(ans[0].confidence);
|
| 587 |
+
++base_count;
|
| 588 |
+
}
|
| 589 |
+
const auto t1 = std::chrono::steady_clock::now();
|
| 590 |
+
const double base_s = std::chrono::duration<double>(t1 - t0).count();
|
| 591 |
+
// T workers, round-robin probe assignment, private engine copies
|
| 592 |
+
std::vector<syfox::Engine> engines(T);
|
| 593 |
+
for (auto& e : engines) e = eng;
|
| 594 |
+
std::vector<long> counts(T, 0);
|
| 595 |
+
std::vector<double> checks(T, 0.0);
|
| 596 |
+
std::vector<std::thread> workers;
|
| 597 |
+
const auto p0 = std::chrono::steady_clock::now();
|
| 598 |
+
for (std::size_t t = 0; t < T; ++t) {
|
| 599 |
+
workers.emplace_back([&engines, &probes, &counts, &checks, t]() {
|
| 600 |
+
long c = 0; double ck = 0.0;
|
| 601 |
+
for (std::size_t i = t; i < probes.size(); i += engines.size()) {
|
| 602 |
+
syfox::Usage u;
|
| 603 |
+
auto ans = engines[t].decide(probes[i].state, probes[i].questions, u);
|
| 604 |
+
ck += ans.empty() ? 0.0 : static_cast<double>(ans[0].confidence);
|
| 605 |
+
++c;
|
| 606 |
+
}
|
| 607 |
+
counts[t] = c; checks[t] = ck;
|
| 608 |
+
});
|
| 609 |
+
}
|
| 610 |
+
for (auto& w : workers) w.join();
|
| 611 |
+
const auto p1 = std::chrono::steady_clock::now();
|
| 612 |
+
const double par_s = std::chrono::duration<double>(p1 - p0).count();
|
| 613 |
+
long total = 0; double ck = 0.0;
|
| 614 |
+
for (std::size_t t = 0; t < T; ++t) { total += counts[t]; ck += checks[t]; }
|
| 615 |
+
const double base_rate = base_s > 0 ? base_count / base_s : 0.0;
|
| 616 |
+
const double par_rate = par_s > 0 ? total / par_s : 0.0;
|
| 617 |
+
sfx::JVObj o;
|
| 618 |
+
o["command"] = sfx::JV("bench");
|
| 619 |
+
o["mode"] = sfx::JV("throughput");
|
| 620 |
+
o["model"] = sfx::JV(a.model);
|
| 621 |
+
o["eval_source"] = sfx::JV(eval_path);
|
| 622 |
+
o["rows"] = static_cast<double>(rows.size());
|
| 623 |
+
o["decisions"] = static_cast<double>(total);
|
| 624 |
+
o["workers"] = static_cast<double>(T);
|
| 625 |
+
o["sequential_decisions_per_sec"] = std::round(base_rate * 10.0) / 10.0;
|
| 626 |
+
o["batched_decisions_per_sec"] = std::round(par_rate * 10.0) / 10.0;
|
| 627 |
+
o["speedup"] = std::round((base_rate > 0 ? par_rate / base_rate : 0.0) * 1000.0) / 1000.0;
|
| 628 |
+
o["work_checksum"] = std::round(ck * 1e6) / 1e6;
|
| 629 |
+
o["note"] = sfx::JV("performance axis only: workers own private substrates, so "
|
| 630 |
+
"per-decision results are not comparable to the sequential "
|
| 631 |
+
"residue chain; accuracy headlines come from deterministic runs");
|
| 632 |
+
if (!a.lang.empty()) o["lang_note"] = sfx::JV("throughput runs the base model; --lang routing is a read-path concern");
|
| 633 |
+
std::cout << sfx::JV(o).dump() << "\n";
|
| 634 |
+
return;
|
| 635 |
+
}
|
| 636 |
+
// v2.2 --lang: route the WHOLE eval to the substrate its dominant script
|
| 637 |
+
// belongs to (per-row re-settling across engines would make the latency
|
| 638 |
+
// axis meaningless). One honest note carries the routing decision.
|
| 639 |
+
std::string lang_note;
|
| 640 |
+
if (!a.lang.empty()) {
|
| 641 |
+
std::string agg;
|
| 642 |
+
for (const auto& r : rows) if (r.has("state")) agg += r.at("state").as_str() + "\n";
|
| 643 |
+
const std::string model_dir = route_model(a, agg, lang_note, false);
|
| 644 |
+
if (model_dir != a.model) eng.load_model(model_dir);
|
| 645 |
+
}
|
| 646 |
+
// v3 Milestone 4 --adversarial: the stress suite over the eval rows.
|
| 647 |
+
// Read-only for the model under test; conflicts run on a throwaway copy.
|
| 648 |
+
if (a.adversarial) {
|
| 649 |
+
std::vector<sfx::JV> mix_rows;
|
| 650 |
+
if (!a.mix.empty()) {
|
| 651 |
+
mix_rows = load_jsonl(a.mix);
|
| 652 |
+
if (mix_rows.empty()) {
|
| 653 |
+
std::cerr << "syfox: no --mix rows in " << a.mix << "\n";
|
| 654 |
+
std::exit(2);
|
| 655 |
+
}
|
| 656 |
+
}
|
| 657 |
+
const std::string pool_src = a.mix.empty() ? a.model : a.mix;
|
| 658 |
+
// pool provenance is recorded: builtin per-domain words, or --mix rows
|
| 659 |
+
const std::vector<std::string> pool = a.mix.empty()
|
| 660 |
+
? syfox::bench::adv_builtin_pool(a.model)
|
| 661 |
+
: syfox::bench::adv_pool_from_rows(mix_rows);
|
| 662 |
+
auto rep = syfox::bench::adversarial_suite(eng, rows, pool);
|
| 663 |
+
auto j = rep.to_json();
|
| 664 |
+
j.obj["command"] = sfx::JV("bench");
|
| 665 |
+
j.obj["mode"] = sfx::JV("adversarial");
|
| 666 |
+
j.obj["model"] = sfx::JV(a.model);
|
| 667 |
+
j.obj["eval_source"] = sfx::JV(eval_path);
|
| 668 |
+
j.obj["rows"] = static_cast<double>(rows.size());
|
| 669 |
+
j.obj["pool_source"] = sfx::JV(pool_src);
|
| 670 |
+
j.obj["pool_words"] = static_cast<double>(pool.size());
|
| 671 |
+
if (!lang_note.empty()) j.obj["lang_note"] = sfx::JV(lang_note);
|
| 672 |
+
if (!split_note.empty()) j.obj["eval_split_note"] = sfx::JV(split_note);
|
| 673 |
+
j.obj["firewall_note"] = sfx::JV("eval rows may be a _hidden split: bench is the "
|
| 674 |
+
"only command allowed to read it, and it never teaches");
|
| 675 |
+
std::cout << j.dump() << "\n";
|
| 676 |
+
return;
|
| 677 |
+
}
|
| 678 |
+
// v2.2 --typos P: the measured typo-robustness claim. Same eval rows,
|
| 679 |
+
// same engine, states deterministically corrupted (deletion / swap /
|
| 680 |
+
// duplication chosen by word hash). Reports BOTH sides + the delta.
|
| 681 |
+
if (a.typos > 0.0f) {
|
| 682 |
+
std::vector<sfx::JV> corrupted = rows;
|
| 683 |
+
for (auto& r : corrupted)
|
| 684 |
+
if (r.is_obj() && r.has("state"))
|
| 685 |
+
r.obj["state"] = sfx::JV(syfox::bench::corrupt_state(r.at("state").as_str(), a.typos));
|
| 686 |
+
syfox::bench::BenchConfig bc;
|
| 687 |
+
bc.latency_reps = static_cast<int>(a.latency_reps);
|
| 688 |
+
bc.determinism_runs = static_cast<int>(a.replays);
|
| 689 |
+
auto rep_c = syfox::bench::run(eng, rows, eval_path, bc, a.model);
|
| 690 |
+
auto rep_t = syfox::bench::run(eng, corrupted, eval_path, bc, a.model);
|
| 691 |
+
sfx::JVObj o;
|
| 692 |
+
o["command"] = sfx::JV("bench");
|
| 693 |
+
o["model"] = sfx::JV(a.model);
|
| 694 |
+
o["eval_source"] = sfx::JV(eval_path);
|
| 695 |
+
if (!split_note.empty()) o["eval_split_note"] = sfx::JV(split_note);
|
| 696 |
+
if (!lang_note.empty()) o["lang_note"] = sfx::JV(lang_note);
|
| 697 |
+
o["typo_pct"] = sfx::JV(std::round(a.typos * 10.0f) / 10.0f);
|
| 698 |
+
o["choice_accuracy_clean"] = std::round(rep_c.choice_accuracy * 10000.0) / 10000.0;
|
| 699 |
+
o["choice_accuracy_typos"] = std::round(rep_t.choice_accuracy * 10000.0) / 10000.0;
|
| 700 |
+
o["choice_accuracy_delta"] = std::round((rep_c.choice_accuracy - rep_t.choice_accuracy) * 10000.0) / 10000.0;
|
| 701 |
+
o["clean"] = rep_c.to_json();
|
| 702 |
+
o["typo"] = rep_t.to_json();
|
| 703 |
+
o["note"] = sfx::JV("deterministic corruption: same word is corrupted the same way on every run — the sweep replays bit-identically");
|
| 704 |
+
std::cout << sfx::JV(o).dump() << "\n";
|
| 705 |
+
return;
|
| 706 |
+
}
|
| 707 |
+
|
| 708 |
+
if (a.coverage_curve) {
|
| 709 |
+
auto cr = syfox::bench::coverage_curve(eng, rows, 20);
|
| 710 |
+
std::cout << "coverage-vs-accuracy curve — " << a.model << " on " << eval_path
|
| 711 |
+
<< (split_note.empty() ? "" : " (" + split_note + ")") << "\n";
|
| 712 |
+
std::cout << " total labelled choice/score questions: " << cr.total << "\n\n";
|
| 713 |
+
std::cout << " tau emitted correct coverage acc-within\n";
|
| 714 |
+
for (const auto& p : cr.points)
|
| 715 |
+
std::printf(" %.2f %7ld %7ld %7.1f%% %9.1f%%\n",
|
| 716 |
+
p.threshold, p.emitted, p.correct,
|
| 717 |
+
p.coverage * 100.0, p.accuracy * 100.0);
|
| 718 |
+
std::cout << "\n" << syfox::bench::coverage_plot(cr);
|
| 719 |
+
auto op = [&](const char* name, const syfox::bench::OperatingPoint& o) {
|
| 720 |
+
std::printf(" op %-3s cov>=%.0f%%: ", name, o.target * 100.0);
|
| 721 |
+
if (o.feasible)
|
| 722 |
+
std::printf("tau=%.2f coverage=%.1f%% accuracy=%.1f%%\n",
|
| 723 |
+
o.threshold, o.coverage * 100.0, o.accuracy * 100.0);
|
| 724 |
+
else
|
| 725 |
+
std::printf("infeasible (best: coverage=%.1f%% at tau=0)\n",
|
| 726 |
+
o.coverage * 100.0);
|
| 727 |
+
};
|
| 728 |
+
op("50", cr.op50); op("70", cr.op70); op("90", cr.op90);
|
| 729 |
+
auto j = cr.to_json();
|
| 730 |
+
j.obj["model"] = sfx::JV(a.model);
|
| 731 |
+
j.obj["eval_source"] = sfx::JV(eval_path);
|
| 732 |
+
if (!split_note.empty()) j.obj["eval_split_note"] = sfx::JV(split_note);
|
| 733 |
+
std::cout << "\njson: " << j.dump() << "\n";
|
| 734 |
+
return;
|
| 735 |
+
}
|
| 736 |
+
|
| 737 |
+
syfox::bench::BenchConfig bc;
|
| 738 |
+
bc.latency_reps = static_cast<int>(a.latency_reps);
|
| 739 |
+
bc.determinism_runs = static_cast<int>(a.replays);
|
| 740 |
+
syfox::bench::BenchReport rep =
|
| 741 |
+
syfox::bench::run(eng, rows,
|
| 742 |
+
split_note.empty() ? eval_path
|
| 743 |
+
: eval_path + " (" + split_note + ")",
|
| 744 |
+
bc, a.model);
|
| 745 |
+
auto j = rep.to_json();
|
| 746 |
+
if (!a.split.empty()) j.obj["eval_split"] = sfx::JV(a.split);
|
| 747 |
+
if (!lang_note.empty()) j.obj["lang_note"] = sfx::JV(lang_note);
|
| 748 |
+
std::cout << j.dump() << "\n";
|
| 749 |
+
}
|
| 750 |
+
|
| 751 |
+
// ---------------------------------------------------------------------------
|
| 752 |
+
// Associative recall through field dynamics (Hopfield-style, similarity in
|
| 753 |
+
// settled-energy space; no token comparison, no pattern matching).
|
| 754 |
+
// ---------------------------------------------------------------------------
|
| 755 |
+
void cmd_recall(const Args& a) {
|
| 756 |
+
std::string lang_note;
|
| 757 |
+
const std::string model_dir = route_model(a, a.state, lang_note, false);
|
| 758 |
+
syfox::Engine eng;
|
| 759 |
+
eng.load_model(model_dir);
|
| 760 |
+
if (a.state.empty() || (a.memories.empty() && a.examples.empty())) usage_exit();
|
| 761 |
+
std::vector<syfox::recall::Memory> memories;
|
| 762 |
+
auto memory_from_row = [](const sfx::JV& r) -> syfox::recall::Memory {
|
| 763 |
+
// two accepted schemas: {"state","label"} or the examples schema
|
| 764 |
+
// {"state","labels"} (label = first label value, sorted-key order)
|
| 765 |
+
std::string label;
|
| 766 |
+
if (r.has("label")) label = r.at("label").as_str();
|
| 767 |
+
else if (r.has("labels") && r.at("labels").is_obj() && !r.at("labels").obj.empty())
|
| 768 |
+
label = r.at("labels").obj.begin()->second.as_str();
|
| 769 |
+
return {label, si::norm::normalize(r.at("state").as_str())};
|
| 770 |
+
};
|
| 771 |
+
if (!a.memories.empty()) {
|
| 772 |
+
for (const auto& r : load_jsonl(a.memories)) {
|
| 773 |
+
if (!r.has("state")) continue;
|
| 774 |
+
memories.push_back(memory_from_row(r));
|
| 775 |
+
}
|
| 776 |
+
} else {
|
| 777 |
+
for (const auto& r : load_jsonl(a.examples)) {
|
| 778 |
+
if (!r.has("state")) continue;
|
| 779 |
+
memories.push_back(memory_from_row(r));
|
| 780 |
+
}
|
| 781 |
+
}
|
| 782 |
+
auto hits = syfox::recall::recall(eng.substrate(), a.state, memories,
|
| 783 |
+
static_cast<int>(a.topk));
|
| 784 |
+
sfx::JVArr arr;
|
| 785 |
+
for (const auto& h : hits)
|
| 786 |
+
arr.push_back(sfx::JV(sfx::JVObj{
|
| 787 |
+
{"label", sfx::JV(h.label)},
|
| 788 |
+
{"resonance", std::round(h.resonance * 10000.0f) / 10000.0f},
|
| 789 |
+
{"memory_index", static_cast<double>(h.index)}}));
|
| 790 |
+
std::cout << sfx::JV(sfx::JVObj{
|
| 791 |
+
{"command", sfx::JV("recall")},
|
| 792 |
+
{"query", sfx::JV(a.state)},
|
| 793 |
+
{"memories", static_cast<double>(memories.size())},
|
| 794 |
+
{"hits", sfx::JV(arr)},
|
| 795 |
+
{"lang_note", sfx::JV(lang_note.empty() ? "routing off" : lang_note)},
|
| 796 |
+
{"note", sfx::JV("similarity measured in the settled-energy field; no token comparison, no pattern matching")}}).dump() << "\n";
|
| 797 |
+
}
|
| 798 |
+
|
| 799 |
+
// ---------------------------------------------------------------------------
|
| 800 |
+
// v2.2 Active Learning Loop — the deployment story for a substrate that can
|
| 801 |
+
// only know what it was taught. SyFox's honest silence is not a failure
|
| 802 |
+
// mode, it is a SIGNAL: every deferral is a state the fabric could not
|
| 803 |
+
// route. The loop: deploy with --log-deferrals -> collect the log ->
|
| 804 |
+
// `syfox active` dedups/ranks it into a labeling worksheet -> a human fills
|
| 805 |
+
// "labels" -> `syfox learn` re-teaches. Fine-tuning built from the
|
| 806 |
+
// substrate's own uncertainty instead of an external drift metric.
|
| 807 |
+
// ---------------------------------------------------------------------------
|
| 808 |
+
void cmd_active(const Args& a) {
|
| 809 |
+
if (a.deferrals.empty() || a.out.empty()) usage_exit();
|
| 810 |
+
std::map<std::string, long> counts; // state -> deferral count
|
| 811 |
+
std::map<std::string, sfx::JV> qs_of; // state -> question schema
|
| 812 |
+
for (const auto& r : load_jsonl(a.deferrals)) {
|
| 813 |
+
if (!r.is_obj() || !r.has("state") || !r.has("questions")) continue;
|
| 814 |
+
const std::string st = r.at("state").as_str();
|
| 815 |
+
++counts[st];
|
| 816 |
+
if (qs_of.find(st) == qs_of.end()) qs_of[st] = r.at("questions");
|
| 817 |
+
}
|
| 818 |
+
// rank: deferral count desc, then state text asc — deterministic
|
| 819 |
+
std::vector<std::pair<std::string, long>> ranked(counts.begin(), counts.end());
|
| 820 |
+
std::sort(ranked.begin(), ranked.end(),
|
| 821 |
+
[](const std::pair<std::string, long>& x, const std::pair<std::string, long>& y) {
|
| 822 |
+
if (x.second != y.second) return x.second > y.second;
|
| 823 |
+
return x.first < y.first;
|
| 824 |
+
});
|
| 825 |
+
std::ofstream out(a.out);
|
| 826 |
+
if (!out) { std::cerr << "syfox: cannot write " << a.out << "\n"; std::exit(2); }
|
| 827 |
+
long written = 0;
|
| 828 |
+
for (const auto& kv : ranked) {
|
| 829 |
+
if (kv.second < a.min_count) continue;
|
| 830 |
+
out << sfx::JV(sfx::JVObj{
|
| 831 |
+
{"state", sfx::JV(kv.first)},
|
| 832 |
+
{"questions", qs_of[kv.first]},
|
| 833 |
+
{"labels", sfx::JV(sfx::JVObj{})}, // <- the human fills this
|
| 834 |
+
{"defer_count", static_cast<double>(kv.second)}}).dump() << "\n";
|
| 835 |
+
++written;
|
| 836 |
+
}
|
| 837 |
+
std::cout << sfx::JV(sfx::JVObj{
|
| 838 |
+
{"command", sfx::JV("active")},
|
| 839 |
+
{"deferral_log", sfx::JV(a.deferrals)},
|
| 840 |
+
{"unique_deferred_states", static_cast<double>(counts.size())},
|
| 841 |
+
{"min_count", static_cast<double>(a.min_count)},
|
| 842 |
+
{"worksheet", sfx::JV(a.out)},
|
| 843 |
+
{"rows_written", static_cast<double>(written)},
|
| 844 |
+
{"note", sfx::JV("fill labels{} in the worksheet, then: syfox learn --model DIR --examples " + a.out)}}).dump() << "\n";
|
| 845 |
+
}
|
| 846 |
+
|
| 847 |
+
void cmd_derive(const Args& a) {
|
| 848 |
+
syfox::Engine eng;
|
| 849 |
+
eng.load_model(a.model);
|
| 850 |
+
// Derivation layer commands. All OFFLINE and EXPLICIT: decide() stays
|
| 851 |
+
// read-only; nothing here runs implicitly. Dreaming never touches the
|
| 852 |
+
// substrate — only a human-validated ledger line can become a lane.
|
| 853 |
+
if (!a.gate.empty()) {
|
| 854 |
+
// TRANSACTIONAL derivation: replay gate rows + close-call probes before
|
| 855 |
+
// and after; any argmax flip reverts the fabric bit-for-bit.
|
| 856 |
+
// v2.1 (P5): the gate rows are usually the HELD-OUT split, so the
|
| 857 |
+
// report also carries gold-labelled accuracy before/after derivation.
|
| 858 |
+
// Milestone-1 firewall: hidden rows never steer derivation.
|
| 859 |
+
if (!syfox::firewall::derive_gate_may_read(a.gate)) {
|
| 860 |
+
std::cerr << "syfox: firewall: " << a.gate << " is a HIDDEN test split"
|
| 861 |
+
<< " — derive --gate is refused (hidden rows never participate "
|
| 862 |
+
"in derivation or model selection)\n";
|
| 863 |
+
std::exit(2);
|
| 864 |
+
}
|
| 865 |
+
auto gate_rows = load_jsonl(a.gate);
|
| 866 |
+
const auto acc_before = syfox::bench::labelled_accuracy(eng, gate_rows);
|
| 867 |
+
std::vector<std::vector<std::string>> replay;
|
| 868 |
+
const std::string replay_src = !a.examples.empty() ? a.examples : a.gate;
|
| 869 |
+
for (const auto& ex : load_jsonl(replay_src))
|
| 870 |
+
replay.push_back(si::norm::normalize(ex.at("state").as_str()));
|
| 871 |
+
const std::string mode = !a.examples.empty() ? "harvest" : "compose";
|
| 872 |
+
syfox::gate::GateConfig gc;
|
| 873 |
+
// conservative derivation strength: the gate's recommended starting
|
| 874 |
+
// point; anything that still flips a taught row is reverted outright
|
| 875 |
+
auto rep = syfox::gate::gated_derive(eng, mode, gate_rows, replay, gc,
|
| 876 |
+
syfox::derive::HarvestConfig::conservative(),
|
| 877 |
+
syfox::derive::DeriveConfig::conservative());
|
| 878 |
+
bool saved = false;
|
| 879 |
+
const auto acc_after = rep.committed
|
| 880 |
+
? syfox::bench::labelled_accuracy(eng, gate_rows) : acc_before;
|
| 881 |
+
if (rep.committed) { eng.save_model(a.model); saved = true; }
|
| 882 |
+
std::string reason;
|
| 883 |
+
if (!rep.committed) {
|
| 884 |
+
if (rep.taught_flips > 0)
|
| 885 |
+
reason = std::to_string(rep.taught_flips) + " taught argmax flip(s)";
|
| 886 |
+
else if (rep.conf_inflated)
|
| 887 |
+
reason = "mixed-state mean confidence rose (manufactured certainty)";
|
| 888 |
+
else
|
| 889 |
+
reason = "no commit condition met";
|
| 890 |
+
}
|
| 891 |
+
std::cout << sfx::JV(sfx::JVObj{
|
| 892 |
+
{"command", sfx::JV("derive")},
|
| 893 |
+
{"mode", sfx::JV(mode)},
|
| 894 |
+
{"gated", sfx::JV(true)},
|
| 895 |
+
{"gate", rep.to_json()},
|
| 896 |
+
{"changed", static_cast<double>(rep.changed)},
|
| 897 |
+
{"removed", static_cast<double>(rep.removed)},
|
| 898 |
+
{"model_saved", sfx::JV(saved)},
|
| 899 |
+
{"gate_rows", static_cast<double>(gate_rows.size())},
|
| 900 |
+
{"gate_row_source", sfx::JV(a.gate)},
|
| 901 |
+
{"harvest_source", sfx::JV(replay_src)},
|
| 902 |
+
{"accuracy_before", std::round(acc_before.accuracy * 10000.0) / 10000.0},
|
| 903 |
+
{"accuracy_after", std::round(acc_after.accuracy * 10000.0) / 10000.0},
|
| 904 |
+
{"accuracy_n", static_cast<double>(acc_before.n)},
|
| 905 |
+
{"verdict", sfx::JV(rep.committed ? "pass" : "revert")},
|
| 906 |
+
{"revert_reason", sfx::JV(reason)},
|
| 907 |
+
{"note", sfx::JV(rep.committed
|
| 908 |
+
? "gate passed: no replayed decision flipped, gold accuracy held; derived lanes committed"
|
| 909 |
+
: "gate REVERTED the derivation: fabric restored bit-for-bit; model ships un-derived")}}).dump() << "\n";
|
| 910 |
+
return;
|
| 911 |
+
}
|
| 912 |
+
if (!a.examples.empty()) {
|
| 913 |
+
// dynamic harvest: replay states, let the field's own settle
|
| 914 |
+
// dynamics nominate which pairs deserve a direct lane
|
| 915 |
+
auto rows = load_jsonl(a.examples);
|
| 916 |
+
std::vector<std::vector<std::string>> replay;
|
| 917 |
+
for (const auto& ex : rows) replay.push_back(si::norm::normalize(ex.at("state").as_str()));
|
| 918 |
+
syfox::derive::HarvestConfig hc;
|
| 919 |
+
auto st = syfox::derive::harvest(eng.substrate(), replay, hc);
|
| 920 |
+
eng.save_model(a.model);
|
| 921 |
+
std::cout << sfx::JV(sfx::JVObj{
|
| 922 |
+
{"command", sfx::JV("derive")},
|
| 923 |
+
{"mode", sfx::JV("harvest")},
|
| 924 |
+
{"gated", sfx::JV(false)},
|
| 925 |
+
{"warning", sfx::JV("ungated derive can flip close-call decisions; pass --gate FILE.jsonl for the transactional no-regression gate")},
|
| 926 |
+
{"states_replayed", static_cast<double>(replay.size())},
|
| 927 |
+
{"created", static_cast<double>(st.created)},
|
| 928 |
+
{"refreshed", static_cast<double>(st.refreshed)},
|
| 929 |
+
{"dissolved", static_cast<double>(st.dissolved)},
|
| 930 |
+
{"lanes", static_cast<double>(eng.substrate().lane_count())},
|
| 931 |
+
{"note", sfx::JV("co-activation harvest: observed lanes untouched; gen-1 lanes re-verified on every run")}}).dump() << "\n";
|
| 932 |
+
} else {
|
| 933 |
+
// static compose: two-hop algebra over the fabric (sparse fabrics)
|
| 934 |
+
syfox::derive::DeriveConfig cfg;
|
| 935 |
+
syfox::derive::DeriveStats st = syfox::derive::run(eng.substrate(), cfg, 2);
|
| 936 |
+
eng.save_model(a.model);
|
| 937 |
+
std::cout << sfx::JV(sfx::JVObj{
|
| 938 |
+
{"command", sfx::JV("derive")},
|
| 939 |
+
{"mode", sfx::JV("compose")},
|
| 940 |
+
{"gated", sfx::JV(false)},
|
| 941 |
+
{"warning", sfx::JV("ungated derive can flip close-call decisions; pass --gate FILE.jsonl for the transactional no-regression gate")},
|
| 942 |
+
{"created", static_cast<double>(st.created)},
|
| 943 |
+
{"strengthened", static_cast<double>(st.strengthened)},
|
| 944 |
+
{"healed", static_cast<double>(st.healed)},
|
| 945 |
+
{"dissolved", static_cast<double>(st.dissolved)},
|
| 946 |
+
{"lanes", static_cast<double>(eng.substrate().lane_count())},
|
| 947 |
+
{"note", sfx::JV("derived lanes carry a generation; observed lanes were never weakened")}}).dump() << "\n";
|
| 948 |
+
}
|
| 949 |
+
}
|
| 950 |
+
|
| 951 |
+
void cmd_dream(const Args& a) {
|
| 952 |
+
syfox::Engine eng;
|
| 953 |
+
eng.load_model(a.model);
|
| 954 |
+
syfox::derive::DreamConfig dc;
|
| 955 |
+
auto cands = syfox::derive::dream(eng.substrate(), dc, a.seed, static_cast<int>(a.steps));
|
| 956 |
+
const std::string ledger = a.model + "/mutations.jsonl";
|
| 957 |
+
std::ofstream out(ledger, std::ios::app);
|
| 958 |
+
long written = 0;
|
| 959 |
+
for (const auto& c : cands) {
|
| 960 |
+
if (!out) { std::cerr << "syfox: cannot write " << ledger << "\n"; break; }
|
| 961 |
+
sfx::JVArr driven;
|
| 962 |
+
for (si::NodeId id : c.driven) driven.push_back(sfx::JV(eng.substrate().concept_of(id)));
|
| 963 |
+
out << sfx::JV(sfx::JVObj{
|
| 964 |
+
{"driven", sfx::JV(driven)},
|
| 965 |
+
{"emergent", sfx::JV(eng.substrate().concept_of(c.emergent))},
|
| 966 |
+
{"support", std::round(c.support * 10000.0f) / 10000.0f},
|
| 967 |
+
{"seed", static_cast<double>(a.seed)},
|
| 968 |
+
{"validated", sfx::JV(false)}}).dump() << "\n";
|
| 969 |
+
++written;
|
| 970 |
+
}
|
| 971 |
+
std::cout << sfx::JV(sfx::JVObj{
|
| 972 |
+
{"command", sfx::JV("dream")},
|
| 973 |
+
{"candidates", static_cast<double>(written)},
|
| 974 |
+
{"ledger", sfx::JV(ledger)},
|
| 975 |
+
{"substrate_modified", sfx::JV(false)},
|
| 976 |
+
{"note", sfx::JV("edit the ledger: set validated:true only on lines you vouch for, then run syfox promote")}}).dump() << "\n";
|
| 977 |
+
}
|
| 978 |
+
|
| 979 |
+
void cmd_promote(const Args& a) {
|
| 980 |
+
syfox::Engine eng;
|
| 981 |
+
eng.load_model(a.model);
|
| 982 |
+
const std::string ledger = a.model + "/mutations.jsonl";
|
| 983 |
+
auto lines = load_jsonl(ledger);
|
| 984 |
+
const float promote_gain = 6.0f;
|
| 985 |
+
long applied = 0, unvalidated = 0, already = 0;
|
| 986 |
+
sfx::JVArr updated;
|
| 987 |
+
for (auto& line : lines) {
|
| 988 |
+
if (!line.is_obj()) continue;
|
| 989 |
+
const bool validated = line.has("validated") && line.at("validated").is_bool() && line.at("validated").b;
|
| 990 |
+
const bool promoted = line.has("promoted") && line.at("promoted").is_bool() && line.at("promoted").b;
|
| 991 |
+
if (!validated) { ++unvalidated; updated.push_back(line); continue; }
|
| 992 |
+
if (promoted) { ++already; updated.push_back(line); continue; }
|
| 993 |
+
std::vector<std::string> driven;
|
| 994 |
+
if (line.at("driven").is_arr())
|
| 995 |
+
for (const auto& d : line.at("driven").arr) driven.push_back(d.as_str());
|
| 996 |
+
const std::string emergent = line.at("emergent").as_str();
|
| 997 |
+
const float support = static_cast<float>(line.at("support").as_num(0.0));
|
| 998 |
+
syfox::derive::apply_promotion(eng.substrate(), driven, emergent, support, promote_gain);
|
| 999 |
+
line.obj["promoted"] = sfx::JV(true);
|
| 1000 |
+
updated.push_back(line);
|
| 1001 |
+
++applied;
|
| 1002 |
+
}
|
| 1003 |
+
if (applied > 0) {
|
| 1004 |
+
std::ofstream out(ledger, std::ios::trunc);
|
| 1005 |
+
for (const auto& l : updated) out << l.dump() << "\n";
|
| 1006 |
+
eng.save_model(a.model);
|
| 1007 |
+
}
|
| 1008 |
+
std::cout << sfx::JV(sfx::JVObj{
|
| 1009 |
+
{"command", sfx::JV("promote")},
|
| 1010 |
+
{"applied", static_cast<double>(applied)},
|
| 1011 |
+
{"unvalidated_skipped", static_cast<double>(unvalidated)},
|
| 1012 |
+
{"already_promoted", static_cast<double>(already)},
|
| 1013 |
+
{"model_saved", sfx::JV(applied > 0)}}).dump() << "\n";
|
| 1014 |
+
}
|
| 1015 |
+
|
| 1016 |
+
void cmd_analogs(const Args& a) {
|
| 1017 |
+
syfox::Engine eng;
|
| 1018 |
+
eng.load_model(a.model);
|
| 1019 |
+
auto matches = syfox::derive::find_analogues(eng.substrate(), a.concept);
|
| 1020 |
+
sfx::JVArr arr;
|
| 1021 |
+
for (const auto& m : matches)
|
| 1022 |
+
arr.push_back(sfx::JV(sfx::JVObj{
|
| 1023 |
+
{"concept", sfx::JV(m.concept)},
|
| 1024 |
+
{"iso", std::round(m.iso * 1000.0f) / 1000.0f},
|
| 1025 |
+
{"hops", static_cast<double>(m.hops)},
|
| 1026 |
+
{"phi", std::round(m.phi * 1000.0f) / 1000.0f}}));
|
| 1027 |
+
std::cout << sfx::JV(sfx::JVObj{
|
| 1028 |
+
{"source", sfx::JV(a.concept)},
|
| 1029 |
+
{"analogs", sfx::JV(arr)},
|
| 1030 |
+
{"note", sfx::JV("high phi = structurally aligned AND fabric-distant: a transfer hypothesis, verify before use")}}).dump() << "\n";
|
| 1031 |
+
}
|
| 1032 |
+
|
| 1033 |
+
void usage_exit() {
|
| 1034 |
+
std::cerr <<
|
| 1035 |
+
"syfox " << syfox::VERSION << " — System One decision engine (SI substrate core)\n"
|
| 1036 |
+
"usage:\n"
|
| 1037 |
+
" syfox learn --model DIR --examples FILE.jsonl\n"
|
| 1038 |
+
" syfox calibrate --model DIR --examples FILE.jsonl\n"
|
| 1039 |
+
" syfox decide --model DIR --state '...' --questions '{...}'\n"
|
| 1040 |
+
" syfox demo --model DIR --domain tickets|game|guard\n"
|
| 1041 |
+
" syfox stats --model DIR\n"
|
| 1042 |
+
" syfox derive --model DIR [--gate FILE.jsonl] [--examples FILE.jsonl]\n"
|
| 1043 |
+
" syfox dream --model DIR [--steps N] [--seed S]\n"
|
| 1044 |
+
" syfox promote --model DIR\n"
|
| 1045 |
+
" syfox analogs --model DIR --concept WORD\n"
|
| 1046 |
+
" syfox bench --model DIR (--eval FILE.jsonl | --split train|heldout)\n"
|
| 1047 |
+
" [--coverage-curve] [--latency-reps N] [--replays N]\n"
|
| 1048 |
+
" (Jev-parity eval suite; the curve sweeps tau 0.0->1.0;\n"
|
| 1049 |
+
" --latency-reps/--replays size the timing/determinism\n"
|
| 1050 |
+
" passes — lower them for fast probes on large evals)\n"
|
| 1051 |
+
" syfox recall --model DIR --state '...' (--memories FILE.jsonl | --examples FILE.jsonl) [--topk N]\n"
|
| 1052 |
+
" syfox active --deferrals FILE.jsonl --out FILE.jsonl [--min-count N]\n"
|
| 1053 |
+
" syfox version\neval-split honesty (v2.1): --split heldout scores data/<domain>_heldout.jsonl\n"
|
| 1054 |
+
"(rows the fabric never learned from); the default train file is in-sample.\n"
|
| 1055 |
+
"token normalization (v2.1): data/synonyms.txt folds synonyms + Porter-stems\n"
|
| 1056 |
+
"tokens before injection (--synonyms overrides the path; deterministic).\n"
|
| 1057 |
+
"multilingual boundary (v2.2): UTF-8 codepoint tokenization for any script;\n"
|
| 1058 |
+
" --lang auto|<slug> routes each query/lesson to <model>-<script> (one SI\n"
|
| 1059 |
+
" substrate per script family: latin, bengali, devanagari, cyrillic, ...);\n"
|
| 1060 |
+
" non-Latin routed substrates enable the character trigram bridges\n"
|
| 1061 |
+
" automatically (typo routing); --ngrams on|off overrides explicitly.\n"
|
| 1062 |
+
"variant lessons (v2.2): learn --augment re-teaches paraphrase/variant rows\n"
|
| 1063 |
+
" WITHOUT mass re-deposition (lanes strengthen, acoustic mass unchanged).\n"
|
| 1064 |
+
"distinct-experience policy (v3, Milestone 2): learn --dedup skips exact\n"
|
| 1065 |
+
" duplicate lessons; learn --novelty scales each lesson's Hebbian dose by\n"
|
| 1066 |
+
" how much of its vocabulary is new (floor 0.25). Measured: distinct\n"
|
| 1067 |
+
" experience scales, repetition does not — see the dose-response table.\n"
|
| 1068 |
+
"typo robustness (v2.2): bench --typos P corrupts P% of words deterministically\n"
|
| 1069 |
+
" and reports clean vs corrupted accuracy.\n"
|
| 1070 |
+
"active learning (v2.2): decide --log-deferrals FILE records every deferral\n"
|
| 1071 |
+
" with its question schema; syfox active turns the log into a labeling\n"
|
| 1072 |
+
" worksheet; label it and re-learn. Deploy -> log -> label -> retrain.\n"
|
| 1073 |
+
"hidden-test firewall (v3): files ending _hidden.jsonl are bench-only ��\n"
|
| 1074 |
+
" learn, calibrate and derive --gate REFUSE them; _cal.jsonl fits\n"
|
| 1075 |
+
" calibration scalars only. The 70/15/15 splits live in data/big/.\n"
|
| 1076 |
+
"energy normalization (v3, Milestone 1): --energy-norm scales the\n"
|
| 1077 |
+
" decide-side injection dose by the mean sqrt(mass) of the state's\n"
|
| 1078 |
+
" known tokens — a measurement gain for big-corpus fabrics where\n"
|
| 1079 |
+
" acoustic mass would otherwise whisper below the silence floor.\n"
|
| 1080 |
+
" Off by default; seed-model numbers are unchanged.\n"
|
| 1081 |
+
"auditable evidence (v3, Milestone 3): decide --evidence prints the\n"
|
| 1082 |
+
" supporting lanes (weight, generation, support/counter events,\n"
|
| 1083 |
+
" provenance window, context) and any contradiction records for the\n"
|
| 1084 |
+
" exact state; learn writes conflicts.jsonl + lessons_index.jsonl.\n"
|
| 1085 |
+
" Contradictory lessons NEVER silently override — they surface.\n"
|
| 1086 |
+
"adversarial suite (v3, Milestone 4): bench --adversarial [--mix FILE]\n"
|
| 1087 |
+
" runs nine deterministic stress families (reorder, padding, typos,\n"
|
| 1088 |
+
" intensifiers, self-contradiction, negation, double negation, unknown\n"
|
| 1089 |
+
" concepts, near-miss / cross-domain) plus a conflicting-lessons attack\n"
|
| 1090 |
+
" on a throwaway engine copy; reports accuracy, defer rate,\n"
|
| 1091 |
+
" conf-when-wrong and false-confidence per family.\n"
|
| 1092 |
+
"multicore (v3, Milestone 5): --threads N runs the deterministic\n"
|
| 1093 |
+
" parallel settle on OMP builds (per-thread scatter buffers combined\n"
|
| 1094 |
+
" in fixed thread order — bit-identical to sequential, test-verified;\n"
|
| 1095 |
+
" N=1 forces sequential). bench --throughput N measures batched\n"
|
| 1096 |
+
" decisions/sec over N workers with private substrates — a\n"
|
| 1097 |
+
" PERFORMANCE axis, not an accuracy headline. stats prints the fabric\n"
|
| 1098 |
+
" density / mean out-degree that gate the GPU design (ARCHITECTURE\n"
|
| 1099 |
+
" S15): no GPU claims without the density gate.\n"
|
| 1100 |
+
"consolidation (v3): learn --epochs N re-teaches the same distinct\n"
|
| 1101 |
+
" lessons N times — the forgetting law (0.995x per lesson) makes a\n"
|
| 1102 |
+
" single 25k-lesson pass recency-truncated; N passes recover early\n"
|
| 1103 |
+
" knowledge deterministically.\n"
|
| 1104 |
+
"selection modes (SI-faithful, off by default, not saved into the model):\n"
|
| 1105 |
+
" --salience-gating rank settle sources by salience (motion history)\n"
|
| 1106 |
+
" instead of raw energy\n"
|
| 1107 |
+
" --miller-window live source cap drawn from [source_cap-4, source_cap]\n"
|
| 1108 |
+
" per decision (= [20,24] at the default cap 24;\n"
|
| 1109 |
+
" TSDA live_cap lineage, SI samples [5,9] at cap 9)\n";
|
| 1110 |
+
std::exit(2);
|
| 1111 |
+
}
|
| 1112 |
+
|
| 1113 |
+
} // namespace
|
| 1114 |
+
|
| 1115 |
+
int main(int argc, char** argv) {
|
| 1116 |
+
if (argc < 2) usage_exit();
|
| 1117 |
+
std::string cmd = argv[1];
|
| 1118 |
+
Args a;
|
| 1119 |
+
for (int i = 2; i < argc; ++i) {
|
| 1120 |
+
auto need = [&](std::string& dst, bool flag = false) {
|
| 1121 |
+
if (i + 1 >= argc) usage_exit();
|
| 1122 |
+
dst = argv[++i];
|
| 1123 |
+
if (flag) dst = "1";
|
| 1124 |
+
};
|
| 1125 |
+
std::string k = argv[i];
|
| 1126 |
+
if (k == "--model") need(a.model);
|
| 1127 |
+
else if (k == "--examples") need(a.examples);
|
| 1128 |
+
else if (k == "--state") need(a.state);
|
| 1129 |
+
else if (k == "--state-file") { need(a.state); a.state_file = true; }
|
| 1130 |
+
else if (k == "--questions") need(a.questions);
|
| 1131 |
+
else if (k == "--questions-file") { need(a.questions); a.questions_file = true; }
|
| 1132 |
+
else if (k == "--domain") need(a.domain);
|
| 1133 |
+
else if (k == "--concept") need(a.concept);
|
| 1134 |
+
else if (k == "--eval") need(a.eval);
|
| 1135 |
+
else if (k == "--gate") need(a.gate);
|
| 1136 |
+
else if (k == "--memories") need(a.memories);
|
| 1137 |
+
else if (k == "--split") need(a.split);
|
| 1138 |
+
else if (k == "--synonyms") need(a.synonyms);
|
| 1139 |
+
else if (k == "--lang") need(a.lang);
|
| 1140 |
+
else if (k == "--log-deferrals") need(a.deferrals);
|
| 1141 |
+
else if (k == "--deferrals") need(a.deferrals); // active-command alias
|
| 1142 |
+
else if (k == "--out") need(a.out);
|
| 1143 |
+
else if (k == "--min-count") { if (i + 1 >= argc) usage_exit(); a.min_count = std::strtol(argv[++i], nullptr, 10); }
|
| 1144 |
+
else if (k == "--typos") { if (i + 1 >= argc) usage_exit(); a.typos = std::strtof(argv[++i], nullptr); }
|
| 1145 |
+
else if (k == "--latency-reps") { if (i + 1 >= argc) usage_exit(); a.latency_reps = std::strtol(argv[++i], nullptr, 10); }
|
| 1146 |
+
else if (k == "--replays") { if (i + 1 >= argc) usage_exit(); a.replays = std::strtol(argv[++i], nullptr, 10); }
|
| 1147 |
+
else if (k == "--augment") a.augment = true;
|
| 1148 |
+
else if (k == "--dedup") a.dedup = true;
|
| 1149 |
+
else if (k == "--novelty") a.novelty = true;
|
| 1150 |
+
else if (k == "--energy-norm") a.energy_norm = true;
|
| 1151 |
+
else if (k == "--defer-margin") { if (i + 1 >= argc) usage_exit(); a.defer_margin = std::strtof(argv[++i], nullptr); if (a.defer_margin < 0) usage_exit(); }
|
| 1152 |
+
else if (k == "--evidence") a.evidence = true;
|
| 1153 |
+
else if (k == "--adversarial") a.adversarial = true;
|
| 1154 |
+
else if (k == "--mix") { if (i + 1 >= argc) usage_exit(); a.mix = argv[++i]; }
|
| 1155 |
+
else if (k == "--threads") { if (i + 1 >= argc) usage_exit(); a.threads = std::strtol(argv[++i], nullptr, 10); if (a.threads < 0) usage_exit(); }
|
| 1156 |
+
else if (k == "--throughput") { if (i + 1 >= argc) usage_exit(); a.throughput = std::strtol(argv[++i], nullptr, 10); if (a.throughput < 1) usage_exit(); }
|
| 1157 |
+
else if (k == "--epochs") { if (i + 1 >= argc) usage_exit(); a.epochs = std::strtol(argv[++i], nullptr, 10); if (a.epochs < 1) usage_exit(); }
|
| 1158 |
+
else if (k == "--novelty-floor") { if (i + 1 >= argc) usage_exit(); a.novelty_floor = std::strtof(argv[++i], nullptr); }
|
| 1159 |
+
else if (k == "--ngrams") {
|
| 1160 |
+
if (i + 1 >= argc) usage_exit();
|
| 1161 |
+
const std::string v = argv[++i];
|
| 1162 |
+
if (v == "on") a.ngrams_mode = 1;
|
| 1163 |
+
else if (v == "off") a.ngrams_mode = -1;
|
| 1164 |
+
else usage_exit();
|
| 1165 |
+
}
|
| 1166 |
+
else if (k == "--coverage-curve") a.coverage_curve = true;
|
| 1167 |
+
else if (k == "--topk") { if (i + 1 >= argc) usage_exit(); a.topk = std::strtol(argv[++i], nullptr, 10); }
|
| 1168 |
+
else if (k == "--steps") { if (i + 1 >= argc) usage_exit(); a.steps = std::strtol(argv[++i], nullptr, 10); }
|
| 1169 |
+
else if (k == "--seed") { if (i + 1 >= argc) usage_exit(); a.seed = std::strtoull(argv[++i], nullptr, 0); }
|
| 1170 |
+
else if (k == "--salience-gating") a.salience_gating = true;
|
| 1171 |
+
else if (k == "--miller-window") a.miller_window = true;
|
| 1172 |
+
else usage_exit();
|
| 1173 |
+
}
|
| 1174 |
+
// v2.1 (P4): one synonym table for the whole process. --synonyms wins;
|
| 1175 |
+
// otherwise data/synonyms.txt when present; otherwise the embedded copy
|
| 1176 |
+
// (same content) inside normalize.hpp. Loaded BEFORE any command runs so
|
| 1177 |
+
// teach and decide always share one folding table.
|
| 1178 |
+
if (!a.synonyms.empty()) {
|
| 1179 |
+
si::norm::load_synonyms(a.synonyms);
|
| 1180 |
+
} else {
|
| 1181 |
+
std::ifstream def("data/synonyms.txt");
|
| 1182 |
+
if (def) si::norm::load_synonyms("data/synonyms.txt");
|
| 1183 |
+
}
|
| 1184 |
+
if (cmd == "version") { std::cout << "syfox " << syfox::VERSION << " (core: si-substrate)\n"; return 0; }
|
| 1185 |
+
if (cmd == "learn") { if (a.examples.empty()) usage_exit(); cmd_learn(a); return 0; }
|
| 1186 |
+
if (cmd == "calibrate") { if (a.examples.empty()) usage_exit(); cmd_calibrate(a); return 0; }
|
| 1187 |
+
if (cmd == "decide") { if (a.state.empty() || a.questions.empty()) usage_exit(); cmd_decide(a); return 0; }
|
| 1188 |
+
if (cmd == "demo") { cmd_demo(a); return 0; }
|
| 1189 |
+
if (cmd == "stats") { cmd_stats(a); return 0; }
|
| 1190 |
+
if (cmd == "derive") { cmd_derive(a); return 0; }
|
| 1191 |
+
if (cmd == "dream") { cmd_dream(a); return 0; }
|
| 1192 |
+
if (cmd == "promote") { cmd_promote(a); return 0; }
|
| 1193 |
+
if (cmd == "analogs") { if (a.concept.empty()) usage_exit(); cmd_analogs(a); return 0; }
|
| 1194 |
+
if (cmd == "bench") { cmd_bench(a); return 0; }
|
| 1195 |
+
if (cmd == "recall") { cmd_recall(a); return 0; }
|
| 1196 |
+
if (cmd == "active") { cmd_active(a); return 0; }
|
| 1197 |
+
usage_exit();
|
| 1198 |
+
}
|