Add clean Path A proof of concept (#1)
Spoken-English math to Typst with a small (~8M parameter) encoder-decoder Transformer trained from scratch, following the build guide (Path A only). ## What's in it - `generate.py` / `render.py` / `ast.py`: random expression trees rendered to Typst (deterministic) and English (random phrasings); every Typst string is compile-checked, split by a hash of the Typst string - `tokenizer.py`: byte-level BPE shared by both sides - `model.py`: `nn.Transformer` seq2seq with `encode()` / `decode()` for inference - `train.py`: teacher forcing, AdamW, warmup + cosine, overfit-100 sanity check, checkpoints - `translate.py`: greedy decoding CLI (`uv run isotope "..."`) - `evaluate.py`: exact match + compile rate on the synthetic test split and `eval/hand_test.jsonl` - `run.sh`: whole pipeline; `./run.sh --quick` is a 2-minute smoke run - `AGENTS.md`: commit and workflow rules for agents ## Checked - `uv run pytest` (8 tests: Typst compiles, English is unambiguous, tokenizer round-trips, causal mask) and `ruff check` pass - `./run.sh --quick` and the full `./run.sh` run end to end on an M-series Mac Reviewed-on: #1 Co-authored-by: Paul Tal <[email protected]>
This commit was merged in pull request #1.
This commit is contained in:
1 parent
5926731546
commit
98e88cac04
21 files changed
+2411
-1
No files matched your search
@@ -0,0 +1,17 @@
|
||||
import random
|
||||
|
||||
from isotope_typst.generate import TreeGen
|
||||
from isotope_typst.render import to_english, to_typst
|
||||
from isotope_typst.tokenizer import BOS, EOS, PAD, train
|
||||
|
||||
|
||||
def test_round_trip(tmp_path):
|
||||
rng = random.Random(0)
|
||||
gen = TreeGen(rng)
|
||||
trees = [gen.tree() for _ in range(2000)]
|
||||
texts = [s for t in trees for s in (to_english(t, rng), to_typst(t))]
|
||||
tok = train(texts, str(tmp_path / "tok.json"), vocab=1000)
|
||||
assert (tok.token_to_id("[PAD]"), tok.token_to_id("[BOS]"), tok.token_to_id("[EOS]")) == (PAD, BOS, EOS)
|
||||
for t in trees[:1000]: # guide §5: decode(encode(s)) == s, or nothing downstream can be right
|
||||
s = to_typst(t)
|
||||
assert tok.decode(tok.encode(s).ids) == s
|
||||
Reference in new issue
Block a user