Download example.py from TheTinyIntelLab/opal-growth: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/TheTinyIntelLab/opal-growth/resolve/main/example.py
- Command line
-
hf download hf://TheTinyIntelLab/opal-growth/example.py
-
curl -L -o example.py https://huggingface.co/TheTinyIntelLab/opal-growth/resolve/main/example.py
1.49 kB
| """Run the six stored checkpoints without training or evaluation targets.""" | |
| import argparse | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| import numpy as np | |
| from opal.trained_growth import TrainedGrowth | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--model-dir", type=Path, default=Path(__file__).resolve().parent) | |
| args = parser.parse_args() | |
| root = args.model_dir.resolve() | |
| expected = "fa8490abe83e5a5d0d0f8456639d11df16a2a6ca3ed440fb40bfd74459488e72" | |
| assert hashlib.sha256((root / "manifest.json").read_bytes()).hexdigest() == expected | |
| bundle = TrainedGrowth.load(root, expected_manifest_sha256=expected) | |
| manifest = json.loads((root / "manifest.json").read_text()) | |
| for task in manifest["tasks"]: | |
| model = bundle.model(task["task"]) | |
| genes = [str(g) for g, ok in zip(model.gene_names(), model.support()) if ok] | |
| a, b = genes[:2] | |
| result = bundle.predict(task["task"], [(a, b)], context=task["context"])[0] | |
| reverse = bundle.predict(task["task"], [(b, a)], context=task["context"])[0] | |
| assert result["status"] == "predicted" and np.isfinite(result["value"]) | |
| np.testing.assert_allclose(result["value"], reverse["value"], rtol=0, atol=1e-10) | |
| abstain = bundle.predict(task["task"], [("__unknown__", b)], context=task["context"])[0] | |
| assert abstain["status"] == "abstain" and abstain["value"] is None | |
| print(json.dumps({"task": task["task"], "genes": [a, b], "status": result["status"], "value": result["value"]})) | |