⊢ Symbolic coprocessors for LLM generation — ground model outputs in exact computation
Project description
⊢ Turnstyle
Symbolic coprocessors for LLM generation. Ground model outputs in exact computation via logit biasing.
The model handles language. Turnstyles handle facts.
from turnstyle import ArithmeticTurnstyle
t = ArithmeticTurnstyle(model, tokenizer, device)
text, proof = t.generate("What is 445 + 152?")
print(text) # "The sum of 445 and 152 is 597."
print(proof.inline()) # ⊢ 445+152=5̲97 ∎
print(proof.detail())
# ⊢ 445+152=597 1/3 corrected Δ=0.05
# d0: [6→5] logit_gap=+1.0
# trigger@step 14/19 state=DONE
How it works
A turnstyle is a LogitsProcessor that intercepts digit generation. When the model is about to output an answer, the turnstyle biases logits toward the symbolically-computed correct digits. Every intervention is audited.
Annotation marks:
5̲underline — digit corrected by coprocessor5̂circumflex — digit the model never emitted⊢turnstile — "this was derived"∎QED — "proof complete"
Turnstyles
| Turnstyle | Domain | Example |
|---|---|---|
ArithmeticTurnstyle |
+, -, *, / |
"What is 445 + 152?" |
DateTurnstyle |
Days/weeks between dates | "How many days between 2026-01-01 and 2026-03-20?" |
UnitTurnstyle |
Physical unit conversion | "How many km is 26.2 miles?" |
CurrencyTurnstyle |
Currency conversion | "How much is 100 USD in EUR?" |
PercentageTurnstyle |
Percentages, tips, discounts | "What is 15% of 230?" |
CountingTurnstyle |
Letters, vowels, words | "How many r's in 'strawberry'?" |
BaseConversionTurnstyle |
Binary, hex, octal | "What is 255 in binary?" |
SandboxTurnstyle |
Arbitrary Python via WASM | "What does `sum(range(101))` return?" |
Each turnstyle follows the same pattern: parse() computes an oracle answer, make_processor() sets up digit biasing, generate() runs the model with grounded outputs.
SandboxTurnstyle
Executes arbitrary Python in a WASM sandbox (Deno + Pyodide) and biases digit logits toward the computed result. The model writes the prose; the sandbox guarantees the number.
from turnstyle import SandboxTurnstyle, DenoPyodideBackend
backend = DenoPyodideBackend()
t = SandboxTurnstyle(model, tokenizer, device, backend=backend)
text, proof = t.generate("What does `sum(range(101))` return?")
# proof.answer == 5050
Supports fenced code blocks, inline backtick expressions, and directive prompts. See docs/sandbox.md for full details.
Requirements: Deno installed on PATH. No network access or filesystem access from sandboxed code.
Install
pip install turnstyle
Requires torch and transformers. Works with any HuggingFace causal LM.
For sandbox support, install Deno:
curl -fsSL https://deno.land/install.sh | sh
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file turnstyle-0.2.0.tar.gz.
File metadata
- Download URL: turnstyle-0.2.0.tar.gz
- Upload date:
- Size: 23.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
108dbbe8650bd2c7a4142f96d24a7dc0c178c9ce75b2c569de00ef2ac04ffe3e
|
|
| MD5 |
ba858aeee4e0e9e00ed69f924db3f5d3
|
|
| BLAKE2b-256 |
0dba60e1c263e9f2066b34d35853e769066cfef6dc09a097ca269c98b39cdbd6
|
File details
Details for the file turnstyle-0.2.0-py3-none-any.whl.
File metadata
- Download URL: turnstyle-0.2.0-py3-none-any.whl
- Upload date:
- Size: 23.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9057d7fed06fe20cf023333a5d7224044ebae766fc94da8f525f2c24fb75abeb
|
|
| MD5 |
a03c9c6bb7c1aca1389a8d057653f714
|
|
| BLAKE2b-256 |
90f6edee801df80ef19a1ebfba3c14105bbdf224ce78b66a97cda92536233400
|