Files
isotope-typst/tests/test_tokenizer.py
T
paultalandClaude Opus 5.5 fa472f8abd Add clean Path A proof of concept
Spoken-English math to Typst with a small from-scratch encoder-decoder
Transformer, following the build guide: compile-checked synthetic data
generator, shared BPE tokenizer, nn.Transformer model, training loop with
an overfit sanity check, greedy decoding CLI, and evaluation on synthetic
and hand-written test sets. ./run.sh runs the whole pipeline.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-27 00:14:06 +02:00

18 lines
718 B
Python

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