BioReason-Pro 2
Read our blog: Building stronger biological reasoning models
Multimodal protein function prediction. A protein's ESM3 embedding and its biological context
(organism, GO-GPT's GO term predictions, known interaction partners and, optionally, its InterPro
features) go into one language model, which reasons about the protein and answers with its function
and GO terms. BioReason-Pro 2 follows BioReason-Pro.
This repository holds the code that predicts with the models, scores them and trains them (supervised
fine-tuning, then reinforcement learning), together with GO-GPT, the GO term predictor whose output the
prompt carries. The code is under the MIT license; the model weights are under OpenMDW-1.1.
Models
Both read the protein through frozen ESM3 (layer 37, with the structure when one is given) and a GO
graph encoder, and take the same prompt with or without the InterPro feature block.
Predict new proteins
Prediction needs the inference environment (Setup), one CUDA GPU (inference fits one 80 GB
card) and the GO embeddings:
python scripts/data/download_assets.py --dest assets --skip-structures --skip-ia # GO embeddings only
python predict.py --input data/examples/proteins.tsv --output runs/example/predictions.tsv
predict.py runs three steps: optional InterPro features, GO-GPT's GO term predictions,
then generation with the RL model (--model sft for the SFT one, --checkpoint <dir or Hub id> for any
other). It builds each prompt with the same builder as the training prompts
(scripts/data/build_question.py). The checkpoint, ESM3
(esm3_sm_open_v1, fetched by the esm package), GO-GPT (wanglab/gogpt-v2)
and GO-GPT's ESM2 encoder download on first use.
Input, a tab-separated file with a header row:
| column |
required |
content |
protein_id |
required |
unique; the key of every output and cache |
organism |
required |
as in UniProt, e.g. Homo sapiens (Human); shown in the prompt |
sequence |
required |
amino acids; the model and GO-GPT read the first 2,000 residues |
taxid |
optional |
NCBI taxonomy id, which GO-GPT prefers to the organism name |
partners |
optional |
interaction partner names separated by ~ |
structure_path |
optional |
a .pdb or mmCIF file of chain A, resolved from the working directory |
The models were trained with partners withheld on 80% of samples and the structure on 50%, so leaving
either out is in distribution. A structure whose backbone does not match the sequence, or a file that
cannot be read, falls back to the sequence alone.
Options.
--gogpt_revision: GO-GPT's epoch-75 checkpoint (ep75, the default and the main of
wanglab/gogpt-v2) is the one whose predictions the models were trained and scored with; ep89 is
GO-GPT's later checkpoint, slightly better at GO on its own.
--interpro: adds the InterPro feature block from InterPro's precomputed InterProScan results, and
submits sequences InterPro has not scanned to EBI's InterProScan service, which needs a real --email
(without one, such proteins get the prompt without the block, with a warning).
--interproscan_dir <InterProScan 5> runs a local InterProScan instead (--cpu threads).
interpro_api.py converts the results into the records the model was trained on.
Those came from InterProScan 5.78-109.0; the online sources run InterPro's current release, so only a
local 5.78-109.0 matches the training release.
--batch_size (16) and --gpu_memory_utilization (0.45, vLLM's share of the GPU; ESM3 and the GO
encoder allocate outside it).
--resume: skips proteins already in the output and reuses the GO-GPT and InterPro results cached
beside it. Without it, a second run appends to the same output file.
Output: one row per protein with protein_id, organism, sequence_length, features (the
prompt's InterPro block), gogpt (the prompt's GO-GPT block), question (the full prompt) and
generated_response. Cells span several lines, so read the file with csv or pandas. GO-GPT's and
InterPro's results are cached beside it as <output>_gogpt.json and <output>_interpro.json.
Decoding is greedy, in a 16,384-token window with up to 8,000 generated tokens. The response is the
reasoning, </think>, then an answer with a summary, InterPro entries, confident and speculated GO terms
per aspect, and hypothesized interaction partners. The scorer's parser pulls out the GO ids:
from evals.cafa.cafa_evals import extract_go_terms
go_ids = extract_go_terms(response, "both") # confident and speculated terms, as the results score
Evaluate
Evaluate on the benchmark
The benchmark is the test split of the proteins_extra config of
wanglab/bioreason-pro-v2 (6,112 proteins).
Fetch it, build the prompt tables, generate and score:
python scripts/data/fetch_corpus.py # -> data/v2/proteins
python scripts/data/prepare_corpus.py --src data/v2 --out data/v2-ep75
python scripts/data/build_question.py --v2-root data/v2-ep75 --out data/sft/v2-nofeatures --no-features
python scripts/data/build_question.py --v2-root data/v2-ep75 --out data/sft/v2-features
hf download nvidia/BioReason-Pro-2-9B-RL --local-dir ckpt/rl
CKPT_DIR=ckpt/rl bash scripts/eval/eval.sh # without InterPro
CKPT_DIR=ckpt/rl EVAL_TABLE=data/sft/v2-features bash scripts/eval/eval.sh # with InterPro
fetch_corpus.py joins the dataset's proteins with their GO-GPT
predictions (a separate config). The tables built from it hold the same prompts and labels, protein for
protein, as the tables the models were scored on. scripts/eval/eval.sh runs
eval.py, one JSON per protein in results/<checkpoint> (resumable; shard with NUM_CHUNKS /
CHUNK_ID, one GPU each), then scores it with evals/cafa/cafa_evals.py.
A sharded run prints the scoring command to run after the last shard instead. The scorer's defaults are
the benchmark's (--go_track both --reasoning_mode True); it needs the CAFA 6 IA weights
(Setup) and deletes an existing --output_dir before writing.
In the published generations, 444 test proteins without a structure, batched with ones that have one,
reached ESM3 as an all-zero backbone; eval.py now encodes them from the sequence alone, as supervised
training did, and regenerating them moves the GO, residue, InterPro and span values below by at most
0.002.
The judge and grounding call an OpenAI-compatible endpoint of your own (JUDGE_BASE_URL ending in
/v1, JUDGE_API_KEY, JUDGE_MODEL); the published values used Nemotron 3.5 Super VL at reasoning
effort max.
- LLM judge (
evals/judge/, protocol in its README): exports the 1,000 proteins of
data/eval/judge_subset.txt with their annotation from data/v2/proteins,
then scores each answer 1-10 on five axes.
- Grounding (
evals/grounding/grounding.py): read has the endpoint
read which feature types each answer asserts; score then checks the answer's residues, InterPro
entries, feature presence and spans against the protein, offline. Its reference covers the benchmark's
proteins only.
Evaluate on your own labelled proteins
Generate with predict.py, then write one JSON per protein, <protein_id>_all_k00.json, into a
directory:
| key |
content |
protein_id |
the protein |
generated_response |
the predictions.tsv column |
success |
true |
go_mf, go_bp, go_cc |
the protein's GO ids per aspect (GO release 2023-01-01; an aspect with none is not scored) |
go_mf_tier2, ... |
optional, a second label tier added to the first |
scored_aspects |
optional, the aspects to score, e.g. ["MF", "BP"] |
python evals/cafa/cafa_evals.py --input_dir mine/ --ontology bioreason2/dataset/go-basic.obo \
--ia_file data/IA_CAFA6.tsv --output_dir mine-scores
Metrics
- Fmax: the F1 of predicted against true GO terms, both propagated to their ancestors, averaged over
the three aspects (
best_f.tsv, column f); every predicted term has score 1, so there is one threshold.
- IA-weighted Fmax, precision, recall: the same, each term weighted by its CAFA 6 information
accretion (
f_w, pr_w, rc_w).
- LLM judge: 1-10 for molecular function, biological process, cellular component, specificity and
reliability, against the protein's annotation.
- Cited residue accuracy: share of residues the answer names at a position that are that residue.
- InterPro precision: share of InterPro entries named that the protein has.
- Feature presence F1: whether the answer says the protein has a transmembrane helix, signal peptide
or coiled coil, against its annotation.
- Spans within 5 residues: share of claimed feature spans within 5 residues of a real feature of
their type.
Results
The benchmark, without / with the InterPro block. GO scores are means over the three aspects, on
confident plus speculated terms; the judge is Nemotron 3.5 Super VL at reasoning effort max scoring 1-10
on a fixed 1,000-protein sample. The grounding rows are pooled over the test split (5,939 proteins for
residues, presence and spans).
| metric |
SFT |
RL |
| LLM judge, mean of 5 axes |
7.24 / 7.72 |
7.74 / 8.43 |
| molecular function |
7.61 / 8.05 |
8.05 / 8.60 |
| biological process |
7.12 / 7.51 |
7.37 / 8.06 |
| cellular component |
8.13 / 8.37 |
8.39 / 8.71 |
| specificity |
9.41 / 9.62 |
9.53 / 9.82 |
| reliability |
3.92 / 5.06 |
5.34 / 6.97 |
| Fmax |
0.629 / 0.640 |
0.662 / 0.667 |
| IA-weighted Fmax |
0.551 / 0.566 |
0.590 / 0.597 |
| IA-weighted precision |
0.502 / 0.516 |
0.555 / 0.559 |
| IA-weighted recall |
0.618 / 0.633 |
0.635 / 0.645 |
| cited residue accuracy |
0.955 / 0.957 |
0.976 / 0.977 |
| InterPro precision |
0.787 / 0.945 |
0.853 / 0.984 |
| feature presence F1 |
0.857 / 0.890 |
0.856 / 0.896 |
| spans within 5 residues |
0.845 / 0.871 |
0.886 / 0.917 |
Setup
Inference and training need different environments: they pin different torch and transformers
versions. Both run on GPUs.