Building it
Training the Models
You don't need to train anything to use Ask Physics once weights ship with v0.4. This page is for building the models yourself. The full runbook, with timings and results, is docs/TRAINING.md.
Set up
git clone https://github.com/shankar-sachin/ask-physics.git
cd ask-physics
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
askphysics-dev validate-data
An Apple Silicon Mac (MPS) or an NVIDIA GPU (CUDA) is picked automatically; the CPU works for the tiny test model.
A one-minute smoke test
askphysics-dev model build-data --out build/smoke --examples 5000 --workers 4
askphysics-dev model train-tokenizer --data build/smoke --out build/smoke-tok.json --vocab-size 512
askphysics-dev model train --model fermi-luna-1 --data build/smoke --tokenizer build/smoke-tok.json --steps 300
The real thing, in one command each
sh scripts/corpus.sh # the prose corpus, once
sh scripts/train.sh fermi-tellus-1 # backs up, builds what's missing, trains, scores
sh scripts/train.sh fermi-solem-1 # reads the corpus first, then the tasks
train.sh keeps the computer awake, backs up the model it replaces, and finishes by comparing the new model's scores with the old one's; sh scripts/models.sh restore fermi-solem-1 puts the old one back. Add --help to any script for its options.
The real thing, step by step
- Build the data:
askphysics-dev model build-data --out build/data --examples 1000000 --workers 10. - Build the prose corpus:
python scripts/build_corpus.py. It downloads the textbooks and books (see Corpus and licenses) and takes a while; it is quiet while it downloads books, and safe to rerun. - Train the tokenizer, then tellus, solem, and celeste, with the exact commands in
docs/TRAINING.md. - Score each one:
askphysics-dev model eval --model fermi-solem-1 --examples 3000.
Trained weights land in ~/.cache/askphysics/models/<model>/, and askphysics ask uses them automatically.