erayack commited on
Commit
659433c
·
verified ·
1 Parent(s): e098cdb

feat: release Tiny Codemode CNN with evaluation and inference package

Browse files
.python-version ADDED
@@ -0,0 +1 @@
 
 
1
+ 3.12
EVALUATION.md ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Checkpoint-matched evaluation
2
+
3
+ CNN checkpoint SHA-256: `a6b944d56580b64dfb526da5b3888a137b6783ea29d8a719a0fea3f4e3f7ee76`.
4
+
5
+ These are curated historical results, not a new evaluation or a claim about a later attention model. Exact counts were recovered from the checkpoint-bound historical record. Full numeric values, source-record hashes and dataset-file hashes are in [evaluation.json](evaluation.json). Original records and full banks are not included in this inference release.
6
+
7
+ | Bank | Exact supported plans | Supported rejected | Negative false accepts | Correct full decisions |
8
+ | --- | ---: | ---: | ---: | ---: |
9
+ | Fresh, same training grammar | 622/625 | 3/625 | 5/575 | 1192/1200 |
10
+ | Schema + reserved phrasing transfer | 497/612 | 115/612 | 8/588 | 1077/1200 |
11
+ | AI-authored transformed bank | 40/50 | 10/50 | 13/70 | 97/120 |
12
+
13
+ ## Definitions
14
+
15
+ - **Exact supported plans:** predicted plan equals the annotated plan; denominator is supported requests, including rejected ones.
16
+ - **Supported rejected:** genuinely supported requests producing diagnostics.
17
+ - **Negative false accepts:** unsupported/invalid requests producing plans; denominator is all annotated negatives.
18
+ - **Correct full decisions:** exact supported plans plus correctly rejected negatives, divided by all requests. This is not acceptance rate.
19
+ - Supported fake-tool execution counts equal exact-plan counts on these three banks. Fake execution is not real-workflow reliability or isolation.
20
+
21
+ ## Interpretation and comparison
22
+
23
+ The authored bank has 24 bases with five variants each, including 10 supported bases. The 40/50 exact supported cases correspond to 8/10 supported bases; two core phrasings failed in every variant. The 13/70 negative false accepts include mixed ordering, unfamiliar prohibition, unknown fields and loop/sorting contexts. Correlated variants are not independent samples.
24
+
25
+ The historical phrase-rule comparator scored 503/612 supported transfer plans and 41/50 authored supported plans, slightly above this CNN's 497/612 and 40/50. There is no demonstrated general neural advantage over strong rules or a main-model baseline.
26
+
27
+ Training, validation and evaluation inputs were synthetic/AI-authored, not human task traffic. Exact normalized-input deduplication does not establish semantic independence or representative English coverage. Synthetic labels are not independently established human intent. The banks are now exposed; do not tune on them and call them new held-out tests.
28
+
29
+ No production-safety, broad-English, demographic-fairness or worst-case latency claim is made. Publication preparation checks packaging/API compatibility, not new model capability.
LICENSE ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tiny Codemode contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
README.md ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ library_name: numpy
6
+ tags:
7
+ - semantic-parsing
8
+ - tool-calling
9
+ - numpy
10
+ - cpu
11
+ - synthetic-data
12
+ - research
13
+ ---
14
+
15
+ # Tiny Codemode CNN
16
+
17
+ **A 67,485-parameter research model for bounded English tool requests.** It maps
18
+ an instruction and an explicit tool catalog to a typed plan, then deterministically
19
+ compiles the plan into JavaScript. It does **not** execute tools and is not an
20
+ agent, general language model or reliable authorization system.
21
+
22
+ This release is the original CNN checkpoint, **not** a later attention candidate.
23
+ Unsupported instructions can be incorrectly accepted. Read the limitations before
24
+ using any generated plan.
25
+
26
+ ## Quickstart
27
+
28
+ Download this model repository, preserving its directory structure. With Python
29
+ 3.10+ and [uv](https://docs.astral.sh/uv/getting-started/installation/) 0.9+ installed,
30
+ run from the downloaded directory:
31
+
32
+ ```sh
33
+ uv sync --locked --no-dev
34
+ uv run --locked --no-dev tiny-codemode --help
35
+ uv run --locked --no-dev tiny-codemode --js < examples/request.jsonl
36
+ ```
37
+
38
+ These commands install NumPy-only inference, not Torch. `--js` returns generated
39
+ JavaScript as text; it does not execute it. Input is JSONL: one complete JSON
40
+ object per line. Output is a plan (and optional JavaScript), or a `diagnostic`.
41
+ `python -m pip install .` is also supported but is not a locked installation.
42
+
43
+ Python API, after installation:
44
+
45
+ ```python
46
+ from core import Diagnostic, compile_js
47
+ from model import Model
48
+
49
+ request = {
50
+ "instruction": 'Call list_users with team="blue"; return the last result.',
51
+ "tools": [
52
+ {
53
+ "name": "list_users",
54
+ "arguments": {"team": "string"},
55
+ "required": ["team"],
56
+ "returns": {"kind": "array", "properties": ["id", "name"]},
57
+ }
58
+ ],
59
+ }
60
+
61
+ try:
62
+ plan = Model().predict(request)
63
+ print(plan)
64
+ print(compile_js(plan, request["tools"]))
65
+ except Diagnostic as error:
66
+ print({"diagnostic": str(error)})
67
+ ```
68
+
69
+ The expected plan for this example is:
70
+
71
+ ```json
72
+ {
73
+ "mode": "single",
74
+ "calls": [{ "tool": "list_users", "args": { "team": "blue" } }],
75
+ "output": { "kind": "last" }
76
+ }
77
+ ```
78
+
79
+ This is custom NumPy inference, not a Transformers/`AutoModel` checkpoint. No
80
+ `trust_remote_code` flag, hosted inference widget or generic text-generation API
81
+ is required or promised. The bundled Python code runs locally; review it before
82
+ use. The NPZ contains numeric arrays and is loaded without pickle.
83
+
84
+ ## Scope and model details
85
+
86
+ The [contract](SPEC.md) allows 1–8 catalog tools, 1–3 calls, up to four primitive
87
+ arguments per tool and 128 input tokens. It supports single, sequential or
88
+ parallel schedules and all/last outputs. Single-array projection and prefix limits
89
+ are bounded. Dependencies, mixed schedule groups, loops, branching, nested
90
+ arguments and arbitrary JavaScript requests are outside the contract.
91
+
92
+ Architecture: 1,024 fixed hash buckets, a learned 32-channel embedding, 12
93
+ mechanical schema/primitive features, three width-5 48-channel ReLU convolutions,
94
+ and learned token-role, schedule, output and rejection heads. Catalog/literal
95
+ identities are normalized for the model; exact names and values are retained by
96
+ the deterministic frontend/compiler. No pretrained model was used.
97
+
98
+ - Parameters: **67,485**, float32 (269,940 raw parameter bytes).
99
+ - Weight file: `tiny_codemode_weights/model.npz` (253,781 bytes compressed).
100
+ - SHA-256: `a6b944d56580b64dfb526da5b3888a137b6783ea29d8a719a0fea3f4e3f7ee76`.
101
+ - Inference: Python + NumPy; CPU only is sufficient.
102
+ - License: [MIT](LICENSE), supplied with the code and checkpoint.
103
+
104
+ `SHA256SUMS` covers every exported file except itself. `release.json` identifies
105
+ the checkpoint and scope. The manifest checks integrity, not publisher authenticity.
106
+
107
+ ## Training and data
108
+
109
+ The selected CNN was randomly initialized and CPU-trained on **26,000 synthetic
110
+ requests**, with **1,600 validation requests**. Plans and token-role spans were
111
+ AI-authored/generated before rendering instructions; no real-user traffic is
112
+ represented. Synthetic schemas and phrasing are not a representative sample of
113
+ English tool use. There is no external pretrained base model or Hub dataset ID.
114
+ The full training corpus and experiment infrastructure are not part of this
115
+ inference-only upload; it is not a standalone training-reproduction package.
116
+
117
+ Seed 715, Adam learning rate 0.002, batch size 96, four CPU threads, 55 epochs.
118
+ The earliest best validation full-decision checkpoint was selected at epoch 12
119
+ (99.0625% validation full-decision accuracy). Training used 25% neutral-wrapper
120
+ hash-bucket perturbation; no runtime wrapper stripping is performed. Historical
121
+ training took 137.60 seconds for the selected run on its recorded CPU environment;
122
+ this is not a hardware-independent speed guarantee.
123
+
124
+ ## Evaluation
125
+
126
+ See [EVALUATION.md](EVALUATION.md) for counts, denominators, definitions and
127
+ limitations, and [evaluation.json](evaluation.json) for the curated numeric summary.
128
+ These are **historical results bound to the exact shipped checkpoint**, not new
129
+ benchmarks performed while packaging. They include false accepts and rejected
130
+ supported requests, not only successful examples.
131
+
132
+ The authored bank scored 40/50 supported plans, with **13/70 negative requests
133
+ falsely accepted**. Its 120 requests are transformations of only 24 AI-authored
134
+ semantic bases—not 120 independent users. All reported banks are now exposed;
135
+ they must not be relabeled as future held-out evaluation.
136
+
137
+ ## Intended use, risks and limitations
138
+
139
+ Use for research, education and constrained offline demonstrations. Do not use as
140
+ an autonomous tool executor, policy gate, authorization mechanism or production
141
+ natural-language parser. Structural validity does not establish that a plan
142
+ matches the user's intent or permission.
143
+
144
+ Known failures include unfamiliar prohibitions, mixed ordering, unknown projected
145
+ fields, loop/sorting contexts and valid unseen phrasings. The model can reject
146
+ valid requests or silently drop unsupported intent. Neither a successful plan nor
147
+ a diagnostic should be treated as a security guarantee. Independent authorization,
148
+ semantic review and appropriate execution isolation are required before real
149
+ side effects. Mock execution tests are not a security sandbox.
150
+
151
+ No broad-English, multilingual, human-population, demographic fairness, worst-case
152
+ latency or production-safety evaluation has been established. Dataset diversity
153
+ and labels are synthetic and limited. Later experimental architectures were not
154
+ promoted into this release, and their scores must not be attributed to this CNN.
SHA256SUMS ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 7b55f8e67b5623c4bef3fa691288da9437d79d3aba156de48d481db32ac7d16d .python-version
2
+ a5e56a98b004c5d564e1d18b46d0ca91977386a7bffbdd808688edfc7d25202d EVALUATION.md
3
+ 0846a890128821c8835d76e2c90fb5fc90891e2b5b6a3067e1674d0059ab1efb LICENSE
4
+ d6a1e7d27ac4a02960c1716e87059a6090b7d992bc8a518c42b835438ee400a5 README.md
5
+ e18e57a959500a63f4dbdce67a2b006881b6f54d0842ff37e175e7b305ecb4a4 SPEC.md
6
+ 9a79e7dc4dc2dc38bb94a99b957ea86bbfb66ee97bf559c4ecbce93409fd0daa core.py
7
+ 3757beb678dc7b13427720b0f5c1ec29119dbb354e954680e3fae4132606be5c evaluation.json
8
+ f99ff96f8a14e926a3d6a042177b4d62f9a1d0e5dd3299ecc56a605c07ea93f7 examples/request.json
9
+ 2559df6c3300eeba1a6c3fbef97cb8dafd661bb279f6055d73d0bc357e56c454 examples/request.jsonl
10
+ 6e1a4b175a56db39edb27d9f76691f7ed719ebaef91ce4a14f2d297b373cd626 infer.py
11
+ f6d628f718b21a4f94f714a50344cfb2480f693bb7b83954f2b80d94e3d7cc63 model.py
12
+ e48d12a082c70b95db3bc57f8a1ef631fe6b40ab7c1a379df87bbec2e84ff117 pyproject.toml
13
+ 5d8a3d32d303e76c785d42839a510c65a42d56cb7900be37d1868da9ba872a9b release.json
14
+ 25bb4454836c602444ee25ed47feb16003eecc4778cbf1ca6417a4a6694151fe requirements.txt
15
+ 7f1037bf26b31d7c50d20a263090d3664ca386d47c5a293f5841c1f886205710 tiny_codemode_weights/__init__.py
16
+ a6b944d56580b64dfb526da5b3888a137b6783ea29d8a719a0fea3f4e3f7ee76 tiny_codemode_weights/model.npz
17
+ 5a960459d51087de9f31430c73136fbdd53b687e9b0f4132aca23c68c0adedb0 uv.lock
SPEC.md ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Inference contract
2
+
3
+ This describes supported structures, not a guarantee that English intent will be
4
+ recognized correctly. Inputs outside these structures may be falsely accepted.
5
+
6
+ ## Input
7
+
8
+ Each JSONL record is an object with:
9
+
10
+ - `instruction`: an English string explicitly naming catalog tools and arguments.
11
+ - `tools`: 1–8 catalog entries, each containing exactly `name`, `arguments`,
12
+ `required`, and `returns`.
13
+
14
+ A catalog entry looks like:
15
+
16
+ ```json
17
+ {
18
+ "name": "list_users",
19
+ "arguments": { "team": "string" },
20
+ "required": ["team"],
21
+ "returns": { "kind": "array", "properties": ["id", "name"] }
22
+ }
23
+ ```
24
+
25
+ Tool names must be JavaScript identifiers. Argument schemas contain at most four
26
+ properties of type `string`, `number` or `boolean`; nested objects, arrays and
27
+ null arguments are unsupported. Required argument names must exist in the schema.
28
+ Return kinds are `text`, `object` or `array`, with declared property names where
29
+ projection is needed. Quoted values use JSON string syntax and remain opaque.
30
+ Numbers must be finite and compatible with exact JavaScript numeric handling.
31
+
32
+ The frontend diagnoses inputs over 128 tokens rather than truncating them.
33
+ The model does not discover tools or interpret free-form tool descriptions.
34
+
35
+ ## Plan
36
+
37
+ A successful response contains a `plan`, for example:
38
+
39
+ ```json
40
+ {
41
+ "mode": "single",
42
+ "calls": [{ "tool": "list_users", "args": { "team": "blue" } }],
43
+ "output": { "kind": "last" }
44
+ }
45
+ ```
46
+
47
+ Supported schedules are one call, or 2–3 independent calls sequentially or in
48
+ parallel. Repeated tools are allowed. Sequential calls do not pass earlier
49
+ results into later arguments. Dependencies, mixed serial/parallel groups,
50
+ conditions, retries, loops and arbitrary code generation are unsupported.
51
+
52
+ `output.kind` is `all` or `last`. For one array-returning call only, optional
53
+ `fields` projects 1–3 declared properties and optional `limit` takes the first
54
+ 0–100 rows. Projection precedes the limit. Filtering, sorting and aggregation
55
+ are unsupported.
56
+
57
+ Rejected requests return a `diagnostic` string instead of a plan. Diagnostics are
58
+ not evidence of reliable semantic rejection. Valid plans can be semantically
59
+ wrong even when schema checks pass.
60
+
61
+ ## Compilation, not execution
62
+
63
+ The CLI's `--js` option also returns a `js` string: an async-function body intended
64
+ for a host exposing `tools[name](args)`, top-level `await` and `return`. Nothing in
65
+ the CLI invokes these tools.
66
+
67
+ Generated code awaits every started call. Parallel mode uses `Promise.allSettled`;
68
+ serial mode catches each call's failure and continues in mention order. Results
69
+ are `{ok: true, value: ...}` or `{ok: false, error: ...}` records. `all` returns
70
+ records in call order; `last` returns the final call's record, not the last call to
71
+ finish. Single-array shaping reports invalid result shapes explicitly.
72
+
73
+ The compiler escapes names and values mechanically and validates structural
74
+ constraints. These properties do not grant permission, establish intended
75
+ semantics, or provide execution isolation. Real tool use needs independently
76
+ implemented authorization, intent review and a suitable execution environment.
core.py ADDED
@@ -0,0 +1,349 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import hashlib
2
+ import json
3
+ import os
4
+ import re
5
+
6
+ for _key in ("OMP_NUM_THREADS", "MKL_NUM_THREADS", "OPENBLAS_NUM_THREADS"):
7
+ try:
8
+ _threads = int(os.environ.get(_key, "4"))
9
+ except ValueError:
10
+ _threads = 4
11
+ os.environ[_key] = str(max(1, min(4, _threads)))
12
+ import numpy as np # noqa: E402 -- thread limits must precede NumPy initialization
13
+
14
+ ROLES = ["none", "tool", "arg", "value", "field", "limit"]
15
+ MODES = ["single", "sequential", "parallel"]
16
+ OUTPUTS = ["all", "last"]
17
+
18
+
19
+ class Diagnostic(ValueError):
20
+ pass
21
+
22
+
23
+ NUMBER = re.compile(r"-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?\Z")
24
+ TOKEN = re.compile(r'"(?:\\.|[^"\\])*"|[A-Za-z_$][\w$]*|[+-]?\d[\w.+-]*|[^\s]')
25
+
26
+
27
+ def number_ok(v):
28
+ import math
29
+
30
+ if type(v) is int:
31
+ try:
32
+ fv = float(v)
33
+ except OverflowError as error:
34
+ raise Diagnostic("number: JS overflow") from error
35
+ if not math.isfinite(fv) or int(fv) != v:
36
+ raise Diagnostic("number: integer not exactly JS-representable")
37
+ elif type(v) is float:
38
+ if not math.isfinite(v):
39
+ raise Diagnostic("number: nonfinite")
40
+ else:
41
+ raise Diagnostic("number: primitive required")
42
+
43
+
44
+ def catalog_check(tools):
45
+ if not isinstance(tools, list) or not 1 <= len(tools) <= 8:
46
+ raise Diagnostic("catalog: expected 1-8 tools")
47
+ names = set()
48
+ for t in tools:
49
+ if not isinstance(t, dict) or set(t) != {
50
+ "name",
51
+ "arguments",
52
+ "required",
53
+ "returns",
54
+ }:
55
+ raise Diagnostic("catalog: tool shape")
56
+ name = t["name"]
57
+ a = t["arguments"]
58
+ req = t["required"]
59
+ ret = t["returns"]
60
+ if (
61
+ not isinstance(name, str)
62
+ or not re.fullmatch(r"[A-Za-z_$][A-Za-z0-9_$]*", name)
63
+ or name in names
64
+ ):
65
+ raise Diagnostic("catalog: unsafe/duplicate tool")
66
+ names.add(name)
67
+ if (
68
+ not isinstance(a, dict)
69
+ or len(a) > 4
70
+ or any(
71
+ not isinstance(k, str)
72
+ or not k
73
+ or v not in ("string", "number", "boolean")
74
+ for k, v in a.items()
75
+ )
76
+ ):
77
+ raise Diagnostic("catalog: primitive argument schema")
78
+ if (
79
+ not isinstance(req, list)
80
+ or any(not isinstance(k, str) for k in req)
81
+ or len(set(req)) != len(req)
82
+ or set(req) - set(a)
83
+ ):
84
+ raise Diagnostic("catalog: required keys")
85
+ if (
86
+ not isinstance(ret, dict)
87
+ or set(ret) - {"kind", "properties"}
88
+ or ret.get("kind") not in ("text", "object", "array")
89
+ ):
90
+ raise Diagnostic("catalog: return schema")
91
+ props = ret.get("properties", [])
92
+ if (
93
+ not isinstance(props, list)
94
+ or any(not isinstance(k, str) or not k for k in props)
95
+ or len(set(props)) != len(props)
96
+ ):
97
+ raise Diagnostic("catalog: properties")
98
+ return tools
99
+
100
+
101
+ def frontend(item):
102
+ if not isinstance(item, dict) or not isinstance(item.get("instruction"), str):
103
+ raise Diagnostic("input: instruction string required")
104
+ tools = catalog_check(item.get("tools"))
105
+ s = item["instruction"]
106
+ toks = TOKEN.findall(s)
107
+ if not toks:
108
+ raise Diagnostic("input: empty instruction")
109
+ if len(toks) > 128:
110
+ raise Diagnostic("token bound")
111
+ names = {t["name"] for t in tools}
112
+ args = {a for t in tools for a in t["arguments"]}
113
+ fields = {a for t in tools for a in t["returns"].get("properties", [])}
114
+ ids = []
115
+ features = []
116
+ values = []
117
+ for x in toks:
118
+ literal = False
119
+ v = x
120
+ if x.startswith('"'):
121
+ try:
122
+ v = json.loads(x)
123
+ literal = True
124
+ except Exception as error:
125
+ raise Diagnostic("malformed literal") from error
126
+ elif x in ("true", "false"):
127
+ v = x == "true"
128
+ literal = True
129
+ elif x[0].isdigit() or (x[0] in "+-" and len(x) > 1 and x[1].isdigit()):
130
+ if not NUMBER.fullmatch(x):
131
+ raise Diagnostic("number: malformed JSON syntax")
132
+ try:
133
+ v = json.loads(x)
134
+ number_ok(v)
135
+ except (ValueError, OverflowError) as e:
136
+ raise Diagnostic(str(e)) from e
137
+ from decimal import Decimal
138
+
139
+ decimal = Decimal(x)
140
+ if v == 0 and decimal != 0:
141
+ raise Diagnostic("number: JS underflow")
142
+ if decimal == decimal.to_integral_value() and int(v) != int(decimal):
143
+ raise Diagnostic("number: integer not exactly JS-representable")
144
+ if (
145
+ type(v) is float
146
+ and v.is_integer()
147
+ and decimal != decimal.to_integral_value()
148
+ ):
149
+ raise Diagnostic("number: fractional part lost in JS")
150
+ literal = True
151
+ f = [
152
+ float(x in names and not literal),
153
+ float(x in args and not literal),
154
+ float(x in fields and not literal),
155
+ float(literal and isinstance(v, str)),
156
+ float(literal and type(v) in (int, float)),
157
+ float(literal and type(v) is bool),
158
+ ]
159
+ f += [
160
+ float(not literal and any(t["arguments"].get(x) == typ for t in tools))
161
+ for typ in ("string", "number", "boolean")
162
+ ]
163
+ f += [
164
+ float(
165
+ not literal
166
+ and any(t["name"] == x and t["returns"]["kind"] == kind for t in tools)
167
+ )
168
+ for kind in ("text", "object", "array")
169
+ ]
170
+ norm = "<schema>" if any(f[:3]) else "<literal>" if literal else x.lower()
171
+ ids.append(
172
+ int.from_bytes(hashlib.sha256(norm.encode()).digest()[:4], "little") % 1024
173
+ )
174
+ features.append(f)
175
+ values.append(v)
176
+ for i, x in enumerate(toks):
177
+ if x == "=" and (i + 1 >= len(toks) or not any(features[i + 1][3:6])):
178
+ raise Diagnostic("literal: assignment requires JSON string/number/boolean")
179
+ return (
180
+ toks,
181
+ np.array(ids, dtype=np.int64),
182
+ np.array(features, dtype=np.float32),
183
+ values,
184
+ )
185
+
186
+
187
+ def validate(plan, tools):
188
+ catalog_check(tools)
189
+ if not isinstance(plan, dict) or set(plan) != {"mode", "calls", "output"}:
190
+ raise Diagnostic("plan: shape")
191
+ catalog = {t["name"]: t for t in tools}
192
+ calls = plan["calls"]
193
+ out = plan["output"]
194
+ if not isinstance(calls, list) or not 1 <= len(calls) <= 3:
195
+ raise Diagnostic("call bound")
196
+ if (
197
+ not isinstance(plan["mode"], str)
198
+ or plan["mode"] not in MODES
199
+ or (len(calls) == 1) != (plan["mode"] == "single")
200
+ ):
201
+ raise Diagnostic("mode mismatch")
202
+ if (
203
+ not isinstance(out, dict)
204
+ or set(out) - {"kind", "fields", "limit"}
205
+ or out.get("kind") not in OUTPUTS
206
+ ):
207
+ raise Diagnostic("output kind/shape")
208
+ for c in calls:
209
+ if (
210
+ not isinstance(c, dict)
211
+ or set(c) != {"tool", "args"}
212
+ or not isinstance(c["tool"], str)
213
+ or c["tool"] not in catalog
214
+ ):
215
+ raise Diagnostic("call: unknown tool/shape")
216
+ t = catalog[c["tool"]]
217
+ a = c["args"]
218
+ if (
219
+ not isinstance(a, dict)
220
+ or len(a) > 4
221
+ or any(not isinstance(k, str) for k in a)
222
+ or set(a) - set(t["arguments"])
223
+ or set(t["required"]) - set(a)
224
+ ):
225
+ raise Diagnostic("unknown/missing arguments")
226
+ for k, v in a.items():
227
+ typ = (
228
+ "boolean"
229
+ if type(v) is bool
230
+ else "number"
231
+ if type(v) in (int, float)
232
+ else "string"
233
+ if type(v) is str
234
+ else "invalid"
235
+ )
236
+ if typ != t["arguments"][k]:
237
+ raise Diagnostic("argument type")
238
+ if typ == "number":
239
+ number_ok(v)
240
+ if "fields" in out or "limit" in out:
241
+ t = catalog[calls[0]["tool"]]
242
+ if len(calls) != 1 or t["returns"]["kind"] != "array":
243
+ raise Diagnostic("shaping scope")
244
+ if "fields" in out:
245
+ fs = out["fields"]
246
+ if (
247
+ not isinstance(fs, list)
248
+ or not 1 <= len(fs) <= 3
249
+ or any(not isinstance(k, str) for k in fs)
250
+ or len(set(fs)) != len(fs)
251
+ or set(fs) - set(t["returns"].get("properties", []))
252
+ ):
253
+ raise Diagnostic("projection fields")
254
+ if "limit" in out and (
255
+ type(out["limit"]) is not int or not 0 <= out["limit"] <= 100
256
+ ):
257
+ raise Diagnostic("limit range")
258
+ return plan
259
+
260
+
261
+ def assemble(item, roles, mode, output):
262
+ toks, _, _, vals = frontend(item)
263
+ if (
264
+ not hasattr(roles, "__len__")
265
+ or len(roles) != len(toks)
266
+ or any(
267
+ not isinstance(r, (int, np.integer))
268
+ or isinstance(r, (bool, np.bool_))
269
+ or r not in range(6)
270
+ for r in roles
271
+ )
272
+ ):
273
+ raise Diagnostic("roles: length/value mismatch")
274
+ if (
275
+ not isinstance(mode, (int, np.integer))
276
+ or not isinstance(output, (int, np.integer))
277
+ or isinstance(mode, (bool, np.bool_))
278
+ or isinstance(output, (bool, np.bool_))
279
+ or mode not in range(3)
280
+ or output not in range(2)
281
+ ):
282
+ raise Diagnostic("heads: invalid class")
283
+ calls = []
284
+ pending = None
285
+ fields = []
286
+ limit = None
287
+ for x, v, r in zip(toks, vals, roles, strict=False):
288
+ if r == 1:
289
+ if pending is not None:
290
+ raise Diagnostic("unbound argument")
291
+ calls.append({"tool": x, "args": {}})
292
+ elif r == 2:
293
+ if not calls or pending is not None:
294
+ raise Diagnostic("argument structure")
295
+ pending = x
296
+ elif r == 3:
297
+ if pending is None or pending in calls[-1]["args"]:
298
+ raise Diagnostic("value structure/duplicate")
299
+ calls[-1]["args"][pending] = v
300
+ pending = None
301
+ elif r == 4:
302
+ fields.append(x)
303
+ elif r == 5:
304
+ if limit is not None:
305
+ raise Diagnostic("multiple limits")
306
+ limit = v
307
+ if pending is not None:
308
+ raise Diagnostic("missing value")
309
+ out = {"kind": OUTPUTS[output]}
310
+ if fields:
311
+ out["fields"] = fields
312
+ if limit is not None:
313
+ out["limit"] = limit
314
+ return validate({"mode": MODES[mode], "calls": calls, "output": out}, item["tools"])
315
+
316
+
317
+ def compile_js(plan, tools):
318
+ validate(plan, tools)
319
+
320
+ def j(x):
321
+ return json.dumps(x, ensure_ascii=True, separators=(",", ":"))
322
+
323
+ inv = [
324
+ f"tools[{j(c['tool'])}](JSON.parse({j(j(c['args']))}))" for c in plan["calls"]
325
+ ]
326
+ pre = "const err=e=>String(e && e.message || e); const invoke=async f=>{try{return {ok:true,value:await f()}}catch(e){return {ok:false,error:err(e)}}};\n"
327
+ if plan["mode"] == "parallel":
328
+ pre += (
329
+ "const settled=await Promise.allSettled(["
330
+ + ",".join("invoke(()=>" + x + ")" for x in inv)
331
+ + ']); const r=settled.map(s=>s.status==="fulfilled"?s.value:{ok:false,error:err(s.reason)});\n'
332
+ )
333
+ else:
334
+ pre += "const r=[];\n" + "".join(
335
+ "r.push(await invoke(()=>" + x + "));\n" for x in inv
336
+ )
337
+ out = plan["output"]
338
+ if "fields" in out or "limit" in out:
339
+ pre += 'if(r[0].ok){try{let v=r[0].value; if(!Array.isArray(v))throw Error("result-schema: expected array");'
340
+ if "fields" in out:
341
+ pre += (
342
+ "const fields="
343
+ + j(out["fields"])
344
+ + '; v=v.map(row=>{if(row===null||typeof row!=="object"||Array.isArray(row)||fields.some(k=>!Object.hasOwn(row,k)))throw Error("result-schema: missing field"); return Object.fromEntries(fields.map(k=>[k,row[k]]));});'
345
+ )
346
+ if "limit" in out:
347
+ pre += f"v=v.slice(0,{out['limit']});"
348
+ pre += "r[0]={ok:true,value:v};}catch(e){r[0]={ok:false,error:err(e)}}}\n"
349
+ return pre + ("return r;" if out["kind"] == "all" else "return r[r.length-1];")
evaluation.json ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "authored_semantic_bases": 24,
3
+ "authored_supported_bases": 10,
4
+ "authored_supported_bases_correct": 8,
5
+ "authored_variants_per_base": 5,
6
+ "banks": {
7
+ "final_challenge": {
8
+ "bank_file_sha256": "edf44de829ea42599e70c0cd8a0a8f925c741d7106cf42539175f11c59e86883",
9
+ "full_decisions_correct": 97,
10
+ "negative": 70,
11
+ "negative_false_accepts": 13,
12
+ "rule_supported_exact": 41,
13
+ "supported": 50,
14
+ "supported_exact": 40,
15
+ "supported_execution_correct": 40,
16
+ "supported_rejected": 10,
17
+ "total": 120
18
+ },
19
+ "fresh": {
20
+ "bank_file_sha256": "3da8357ffc18e3dd836665758d747db61708314eccc63f735423bc5d7f6b8670",
21
+ "full_decisions_correct": 1192,
22
+ "negative": 575,
23
+ "negative_false_accepts": 5,
24
+ "rule_supported_exact": 555,
25
+ "supported": 625,
26
+ "supported_exact": 622,
27
+ "supported_execution_correct": 622,
28
+ "supported_rejected": 3,
29
+ "total": 1200
30
+ },
31
+ "transfer": {
32
+ "bank_file_sha256": "20b9c3c7e2f851f69de85f163e57ac2c6a564b3dfd2d8304ff3f68261cff80aa",
33
+ "full_decisions_correct": 1077,
34
+ "negative": 588,
35
+ "negative_false_accepts": 8,
36
+ "rule_supported_exact": 503,
37
+ "supported": 612,
38
+ "supported_exact": 497,
39
+ "supported_execution_correct": 497,
40
+ "supported_rejected": 115,
41
+ "total": 1200
42
+ }
43
+ },
44
+ "checkpoint_sha256": "a6b944d56580b64dfb526da5b3888a137b6783ea29d8a719a0fea3f4e3f7ee76",
45
+ "historical_evaluation_record_sha256": "c6644ab82f5d7411b92b0bcb5c387412357a0caf829c76b15fb26b90bfd57c38",
46
+ "historical_training_record_sha256": "871670888d326374c211c511cfb6816779ae899774f729cf6bc60935a6516a0a",
47
+ "limitations": [
48
+ "Synthetic/AI-authored data, not real-user or population evidence.",
49
+ "Authored variants are correlated; 120 requests are not 120 independent users.",
50
+ "All banks are exposed now; not future held-out evidence.",
51
+ "Dataset hashes identify source bytes, not proof of label correctness.",
52
+ "Compiler execution used fake tools, not a security boundary.",
53
+ "No attention-candidate results are included."
54
+ ],
55
+ "parameters": 67485,
56
+ "status": "historical_exposed_synthetic_evaluation_not_new_measurement",
57
+ "training": {
58
+ "epochs_completed": 55,
59
+ "initialization": "random",
60
+ "seed": 715,
61
+ "selected_epoch": 12,
62
+ "selected_validation_exact": 0.990625,
63
+ "training_sha256": "ed2ff9f0275c86958c475a89ec8e90664b954e0408eaefc356aa5ffb81c3b33a"
64
+ }
65
+ }
examples/request.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "instruction": "Run list_users with team=\"blue\" and list_issues with state=\"open\" concurrently; return both results.",
3
+ "tools": [
4
+ {
5
+ "name": "list_users",
6
+ "arguments": { "team": "string" },
7
+ "required": ["team"],
8
+ "returns": { "kind": "array", "properties": ["id", "name"] }
9
+ },
10
+ {
11
+ "name": "list_issues",
12
+ "arguments": { "state": "string" },
13
+ "required": ["state"],
14
+ "returns": { "kind": "array", "properties": ["id", "title"] }
15
+ }
16
+ ]
17
+ }
examples/request.jsonl ADDED
@@ -0,0 +1 @@
 
 
1
+ {"instruction":"Run list_users with team=\"blue\" and list_issues with state=\"open\" concurrently; return both results.","tools":[{"name":"list_users","arguments":{"team":"string"},"required":["team"],"returns":{"kind":"array","properties":["id","name"]}},{"name":"list_issues","arguments":{"state":"string"},"required":["state"],"returns":{"kind":"array","properties":["id","title"]}}]}
infer.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """JSONL inference CLI; compiles but never executes tools."""
2
+
3
+ import argparse
4
+ import json
5
+ import sys
6
+
7
+ from core import compile_js
8
+ from model import Model
9
+
10
+
11
+ def main():
12
+ ap = argparse.ArgumentParser(description=__doc__)
13
+ ap.add_argument(
14
+ "--checkpoint", default=None, help="NPZ weights (default: packaged CNN)"
15
+ )
16
+ ap.add_argument("--js", action="store_true")
17
+ args = ap.parse_args()
18
+ model = Model(args.checkpoint)
19
+ for line in sys.stdin:
20
+ try:
21
+ item = json.loads(line)
22
+ plan = model.predict(item)
23
+ print(
24
+ json.dumps(
25
+ {"plan": plan, "js": compile_js(plan, item["tools"])}
26
+ if args.js
27
+ else {"plan": plan}
28
+ )
29
+ )
30
+ except (ValueError, KeyError, IndexError) as e:
31
+ print(json.dumps({"diagnostic": str(e)}))
32
+
33
+
34
+ if __name__ == "__main__":
35
+ main()
model.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Numpy-only neural inference; no semantic phrase rules. Fixed feature hashing."""
2
+
3
+ from importlib.resources import files
4
+
5
+ from core import Diagnostic, assemble, compile_js, frontend
6
+
7
+ # isort: split
8
+ # core must set CPU thread limits before NumPy initializes.
9
+ import numpy as np
10
+
11
+
12
+ def default_checkpoint():
13
+ return files("tiny_codemode_weights").joinpath("model.npz")
14
+
15
+
16
+ class Model:
17
+ def __init__(self, path=None):
18
+ with np.load(path if path is not None else default_checkpoint()) as z:
19
+ self.w = {k: z[k] for k in z.files}
20
+
21
+ def logits(self, item):
22
+ _, ids, f, _ = frontend(item)
23
+ return self.forward(ids, f)
24
+
25
+ def forward(self, ids, f):
26
+ w = self.w
27
+ dims = w["convs.0.weight"].shape[1] - w["embed.weight"].shape[1]
28
+ h = np.concatenate(
29
+ [w["embed.weight"][ids % len(w["embed.weight"])], f[:, :dims]], axis=1
30
+ )
31
+ for i in range(3):
32
+ weight = w[f"convs.{i}.weight"]
33
+ bias = w[f"convs.{i}.bias"]
34
+ pad = weight.shape[2] // 2
35
+ p = np.pad(h, ((pad, pad), (0, 0)))
36
+ h = np.maximum(
37
+ sum(
38
+ p[k : k + len(h)] @ weight[:, :, k].T
39
+ for k in range(weight.shape[2])
40
+ )
41
+ + bias,
42
+ 0,
43
+ )
44
+ pooled = np.concatenate([h.mean(0), h.max(0)])
45
+ heads = (
46
+ h @ w["roles.weight"].T + w["roles.bias"],
47
+ pooled @ w["mode.weight"].T + w["mode.bias"],
48
+ pooled @ w["output.weight"].T + w["output.bias"],
49
+ )
50
+ return (
51
+ heads + (pooled @ w["reject.weight"].T + w["reject.bias"],)
52
+ if "reject.weight" in w
53
+ else heads
54
+ )
55
+
56
+ def predict(self, item):
57
+ heads = self.logits(item)
58
+ if len(heads) == 4 and int(heads[3].argmax()) == 1:
59
+ raise Diagnostic("learned rejection: unsupported/invalid request")
60
+ r, m, o = heads[:3]
61
+ return assemble(item, r.argmax(1), int(m.argmax()), int(o.argmax()))
62
+
63
+ def program(self, item):
64
+ return compile_js(self.predict(item), item["tools"])
pyproject.toml ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [build-system]
2
+ requires = ["setuptools>=77.0.3", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "tiny-codemode"
7
+ version = "0.1.0"
8
+ description = "Bounded research semantic parser and deterministic JavaScript compiler"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ dependencies = ["numpy>=1.24"]
13
+
14
+ [project.optional-dependencies]
15
+ training = ["torch>=2.0"]
16
+
17
+ [dependency-groups]
18
+ dev = ["ruff==0.16.10", "ty==0.0.10", "build>=1.2"]
19
+
20
+ [tool.uv]
21
+ required-version = ">=0.9.0"
22
+
23
+ [tool.uv.sources]
24
+ torch = [{ index = "pytorch-cpu", marker = "sys_platform == 'linux' or sys_platform == 'win32'" }]
25
+
26
+ [[tool.uv.index]]
27
+ name = "pytorch-cpu"
28
+ url = "https://download.pytorch.org/whl/cpu"
29
+ explicit = true
30
+
31
+ [project.scripts]
32
+ tiny-codemode = "infer:main"
33
+
34
+ [tool.setuptools]
35
+ py-modules = ["core", "model", "infer"]
36
+ packages = ["tiny_codemode_weights"]
37
+
38
+ [tool.setuptools.package-data]
39
+ tiny_codemode_weights = ["model.npz"]
40
+
41
+ [tool.ruff]
42
+ target-version = "py310"
43
+ extend-exclude = ["archive", "artifacts", "history", "build", "dist"]
44
+ force-exclude = true
45
+
46
+ [tool.ruff.lint]
47
+ select = ["E4", "E7", "E9", "F", "I", "UP", "B"]
48
+
49
+ [tool.ty.src]
50
+ include = ["*.py", "tests", "tools", "tiny_codemode_weights"]
51
+ exclude = ["archive", "artifacts", "history", "build", "dist"]
52
+
53
+ [tool.ty.environment]
54
+ python-version = "3.10"
release.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "checkpoint": "tiny_codemode_weights/model.npz",
3
+ "checkpoint_sha256": "a6b944d56580b64dfb526da5b3888a137b6783ea29d8a719a0fea3f4e3f7ee76",
4
+ "evaluation": "evaluation.json",
5
+ "format_version": 1,
6
+ "integrity_manifest": "SHA256SUMS",
7
+ "license": "MIT",
8
+ "model": "Tiny Codemode CNN",
9
+ "parameters": 67485,
10
+ "scope": "inference_only_custom_numpy_not_transformers"
11
+ }
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ # Legacy pip entry point. Reproducible inference: uv sync --locked --no-dev
2
+ .
tiny_codemode_weights/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ """The frozen default CNN checkpoint packaged for offline inference."""
tiny_codemode_weights/model.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a6b944d56580b64dfb526da5b3888a137b6783ea29d8a719a0fea3f4e3f7ee76
3
+ size 253781
uv.lock ADDED
The diff for this file is too large to render. See raw diff