Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4dae0d7bfa | ||
|
|
98e88cac04 |
No files matched your search
@@ -0,0 +1,18 @@
|
||||
# Agent instructions
|
||||
|
||||
## Git
|
||||
|
||||
- Do not add AI attribution to commits: no `Co-Authored-By:` trailers for AI tools, no "Generated with …" lines. The same goes for pull request descriptions.
|
||||
- Never commit on `main`. Do all work on a branch and merge it through a pull request.
|
||||
- Commit as `Paul Tal <[email protected]>`, which is set in the repo's local git config.
|
||||
|
||||
## Project
|
||||
|
||||
- `./run.sh` runs the whole pipeline (data → tokenizer → overfit check → train → evaluate); `./run.sh --quick` is a two-minute smoke run.
|
||||
- `uv run pytest` and `uv run ruff check .` must pass before committing.
|
||||
- `data/` and `artifacts/` are generated outputs and are not tracked.
|
||||
|
||||
## README
|
||||
|
||||
- Keep `README.md` to a short description of the project and how to run it. Do not use it as documentation: no module lists, command tables, design conventions or roadmaps.
|
||||
- Document code in docstrings and comments next to the code, and track planned work in Gitea issues.
|
||||
@@ -1,59 +1,13 @@
|
||||
# isotope-typst
|
||||
|
||||
**isotope-typst** is a Transformer model that translates math written in plain English into [Typst](https://typst.app) markup.
|
||||
isotope-typst turns math written in plain English into [Typst](https://typst.app) markup. For example, `the integral from 0 to infinity of e to the minus x squared dx` becomes `$integral_0^infinity e^(-x^2) dif x$`. It is a small encoder–decoder Transformer, built and trained from scratch in PyTorch on synthetic data.
|
||||
|
||||
For example, `the integral from 0 to infinity of e to the minus x squared dx` becomes `$integral_0^infinity e^(-x^2) dif x$`.
|
||||
## Running it
|
||||
|
||||
The current code is the **Path A proof of concept**: a small (~8M parameter) encoder–decoder Transformer trained from scratch on synthetic data, following the [build guide](https://git.paultal.online/paultal/generated-books/src/branch/main/isotope-typst-guide.pdf).
|
||||
|
||||
## Run it
|
||||
|
||||
Needs [uv](https://docs.astral.sh/uv/) and the Typst CLI (`brew install typst`).
|
||||
You need [uv](https://docs.astral.sh/uv/) and the Typst CLI (`brew install typst`).
|
||||
|
||||
```bash
|
||||
./run.sh # everything, ~20 min on an M-series Mac
|
||||
./run.sh --quick # smoke run, ~2 min, tiny model
|
||||
uv run isotope "x squared plus y squared equals r squared"
|
||||
uv run isotope # interactive prompt
|
||||
./run.sh # generate data, train, and evaluate (~20 min on an M-series Mac)
|
||||
uv run isotope "x squared plus 1" # translate a sentence
|
||||
uv run isotope # interactive prompt
|
||||
```
|
||||
|
||||
Or one stage at a time:
|
||||
|
||||
| guide | command | what it does |
|
||||
|---|---|---|
|
||||
| §4 data | `uv run isotope-gen -n 200000` | random trees → English + Typst pairs, compile-checked, into `data/` |
|
||||
| §5 tokens | `uv run isotope-tokenizer` | byte-level BPE shared by both sides → `artifacts/tokenizer.json` |
|
||||
| §7 sanity | `uv run isotope-train --overfit 100` | a tiny model must memorise 100 pairs, or the pipeline has a bug |
|
||||
| §7 training | `uv run isotope-train` | `--config tiny/small/medium`, `--steps`, Ctrl-C saves a checkpoint |
|
||||
| §8 inference | `uv run isotope "..."` | greedy decoding; `--check` compiles the output |
|
||||
| §9 evaluation | `uv run isotope-eval` | exact match and compile rate on synthetic test + `eval/hand_test.jsonl` |
|
||||
| tests | `uv run pytest` | renderer compiles, English is unambiguous, tokenizer round-trips, causal mask works |
|
||||
|
||||
`data/` and `artifacts/` are generated and not tracked in git.
|
||||
|
||||
## Code
|
||||
|
||||
```
|
||||
src/isotope_typst/
|
||||
ast.py expression nodes: Var Num Neg Add Sub Mul Pow Frac Sqrt Func Integral Sum Lim Eq
|
||||
render.py to_typst() (deterministic) and to_english() (random phrasings)
|
||||
generate.py random trees -> data/{train,valid,test}.jsonl, split by a hash of the Typst string
|
||||
validate.py `typst compile` checks
|
||||
tokenizer.py BPE tokenizer
|
||||
model.py Seq2Seq on nn.Transformer, with encode()/decode() for inference
|
||||
train.py teacher forcing, AdamW, warmup + cosine, checkpoints, train_log.csv
|
||||
translate.py greedy decoding + CLI
|
||||
evaluate.py metrics + failure dumps in artifacts/errors_*.txt
|
||||
eval/hand_test.jsonl hand-written test sentences: never generated, never trained on
|
||||
```
|
||||
|
||||
## Conventions the English follows
|
||||
|
||||
* "e to the minus x squared" means `e^(-x^2)`: a bare exponent takes everything after it (guide Appendix A, Q1).
|
||||
* Grouping is said with "( … )", "open paren … close paren", or, at the end of a phrase, "the quantity …".
|
||||
* "sine of x squared" means `sin(x^2)`; `sin(x)^2` is "sine squared of x".
|
||||
* Integrals, sums and limits appear only at the top level of an expression.
|
||||
|
||||
## Not in this PoC (yet)
|
||||
|
||||
Beam search, constrained decoding, render-match evaluation, a hand-written attention module, paraphrase augmentation, and Path B fine-tuning.
|
||||
Reference in new issue
Block a user