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]>
This commit is contained in:
1 parent
5926731546
commit
fa472f8abd
20 files changed
+2398
-1
No files matched your search
@@ -0,0 +1,63 @@
|
||||
"""Evaluate: exact match and compile rate, on the synthetic test split and the hand-written set.
|
||||
|
||||
uv run isotope-eval
|
||||
|
||||
Failures go to artifacts/errors_<set>.txt: read them, group them, fix the generator (guide §9).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import pathlib
|
||||
import random
|
||||
|
||||
from .validate import compiles_many
|
||||
|
||||
|
||||
def read_jsonl(path: str) -> list[dict]:
|
||||
with open(path) as f:
|
||||
return [json.loads(line) for line in f if line.strip()]
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> None:
|
||||
from .translate import load_model, translate_batch
|
||||
|
||||
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
ap.add_argument("--synthetic", default="data/test.jsonl")
|
||||
ap.add_argument("--hand", default="eval/hand_test.jsonl")
|
||||
ap.add_argument("--n-synthetic", type=int, default=1000)
|
||||
ap.add_argument("--ckpt", default="artifacts/model.pt")
|
||||
ap.add_argument("--out", default="artifacts")
|
||||
args = ap.parse_args(argv)
|
||||
|
||||
model, tok = load_model(args.ckpt)
|
||||
sets = {}
|
||||
if pathlib.Path(args.synthetic).exists():
|
||||
rows = read_jsonl(args.synthetic)
|
||||
random.Random(0).shuffle(rows)
|
||||
sets["synthetic"] = rows[: args.n_synthetic]
|
||||
if pathlib.Path(args.hand).exists():
|
||||
sets["hand"] = read_jsonl(args.hand)
|
||||
|
||||
print(f"{'set':<12}{'n':>6}{'exact':>9}{'compiles':>10}")
|
||||
for name, rows in sets.items():
|
||||
preds = []
|
||||
for i in range(0, len(rows), 64):
|
||||
preds += translate_batch(model, tok, [r["en"] for r in rows[i : i + 64]])
|
||||
exact = [p == r["typ"] for p, r in zip(preds, rows)]
|
||||
comp = compiles_many(preds)
|
||||
n = len(rows)
|
||||
print(f"{name:<12}{n:>6}{sum(exact) / n:>9.1%}{sum(comp) / n:>10.1%}")
|
||||
|
||||
lines = [f"{n - sum(exact)} of {n} not exact\n"]
|
||||
for r, p, e, c in zip(rows, preds, exact, comp):
|
||||
if not e:
|
||||
lines.append(f"EN: {r['en']}\nWANT: {r['typ']}\nGOT: {p}{'' if c else ' [does not compile]'}\n")
|
||||
path = pathlib.Path(args.out) / f"errors_{name}.txt"
|
||||
path.write_text("\n".join(lines))
|
||||
print(f"\nfailures: {args.out}/errors_*.txt")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user