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]>
23 lines
958 B
Bash
Executable File
23 lines
958 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# The whole Path A pipeline: data -> tokenizer -> overfit check -> train -> evaluate.
|
|
# ./run.sh full run (200k pairs, small model, 8000 steps: ~20 min on an M-series Mac)
|
|
# ./run.sh --quick smoke run in ~2 min (20k pairs, tiny model, 1500 steps)
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")"
|
|
command -v typst >/dev/null || { echo "typst CLI missing: brew install typst"; exit 1; }
|
|
|
|
if [[ "${1:-}" == "--quick" ]]; then
|
|
N=20000; TRAIN=(--config tiny --steps 1500 --eval-every 500)
|
|
else
|
|
N=200000; TRAIN=()
|
|
fi
|
|
|
|
uv sync -q
|
|
echo "== 1/5 generate data"; uv run isotope-gen -n "$N"
|
|
echo "== 2/5 train tokenizer"; uv run isotope-tokenizer
|
|
echo "== 3/5 overfit 100 pairs"; uv run isotope-train --overfit 100
|
|
echo "== 4/5 train"; uv run isotope-train ${TRAIN[@]+"${TRAIN[@]}"}
|
|
echo "== 5/5 evaluate"; uv run isotope-eval
|
|
echo
|
|
echo 'Try it: uv run isotope "the integral from 0 to 1 of x squared dx"'
|