This repository provides a local inference workflow for our finetuned antibody language model based on p-IgGen.
The inference script supports:
- De novo generation of full-length paired antibody sequences
- Conditional generation from a provided heavy or light chain
- Prompted generation from an initial sequence
- Optional likelihood-based filtering of outputs
- Optional separation of VH and VL chains in outputs
- Optional reverse generation
All scripts for finetune data curation, training, inference and evaluation can be found at psipred/Antibody-design/main/scripts. The diagrams below map the data flow through the fine-tuning data curation and inference/pre-evaluation pipelines, tracing how each script's inputs and outputs connect. Model training and evaluation are omitted as their workflows are comparatively straightforward
Finetune data curation
Inference and pre-evaluation

- Conda
- Git
- Internet access (for downloading model and dependencies)
conda create -n piggen_infer python=3.11 pip -y
conda activate piggen_inferpip install git+https://github.com/OliverT1/p-IgGen.gitpip install torch transformers clickconda install -n piggen_infer -c bioconda hmmer -yconda run -n piggen_infer pip install anarciNote: This inference script imports ANARCI at startup, so ANARCI must be installed even if you are not using
--separate_chains.
Download the inference script:
wget https://raw.githubusercontent.com/psipred/Antibody-design/main/operations/user_inference.py -O github_inference.pyOr with curl:
curl -o github_inference.py https://raw.githubusercontent.com/psipred/Antibody-design/main/operations/user_inference.pyGenerate sequences with a simple command:
python github_inference.py \
--n_sequences 10 \
--output_file output_unconditional.txt \
--device cpu| Flag | Description |
|---|---|
--heavy_chain_file TEXT |
File containing heavy chain sequences (one per line) |
--light_chain_file TEXT |
File containing light chain sequences (one per line) |
--initial_sequence TEXT |
Initial sequence prompt |
For p-IgGen prompted generation, prefix the prompt with 1.
Example: --initial_sequence 1QVQLVES...
| Flag | Description | Default |
|---|---|---|
--n_sequences INTEGER |
Number of sequences to generate | 1 |
--top_p FLOAT |
Top-p nucleus sampling | 0.95 |
--temp FLOAT |
Sampling temperature | 1.2 |
--bottom_n_percent INTEGER |
Percentage of lowest-likelihood sequences to discard (only used if n_sequences >= 100) |
5 |
| Flag | Description |
|---|---|
--backwards |
Generate sequences in reverse direction |
--separate_chains |
Output VH and VL separately (requires ANARCI) |
| Flag | Description |
|---|---|
--output_file TEXT |
Output file path (required) |
Notes
- The model samples next tokens probabilistically instead of always picking the single most likely token, giving diversity across outputs
- Each generation (not including prompt) can add at most 400 new tokens
bottom_n_percentonly applies whenn_sequences >= 100- Some generated samples can be dropped by post-generation validation, so written output count may be lower than
--n_sequences--heavy_chain_fileand--light_chain_fileare mutually exclusive- In prompted mode,
--initial_sequenceaccepts a single prompt string
Sequences are generated by default in the direction VH -> VL (C-term to N-term).
Alternatively, they can be generated in reverse from VL -> VH (N-term to C-term)
using the --backwards flag. This allows generation given a VH or VL sequence of
any length.
Note:
- If
--backwardsis used with--initial_sequence, the prompt should be provided in reverse, starting from the N-term of the VL chain. - If
--heavy_chain_fileor--light_chain_fileis used, this inversion is handled automatically, and the VH and VL chains should be provided in the standard direction.
Unconditional generation:
python github_inference.py \
--n_sequences 10 \
--output_file output_unconditional.txt \
--device cpuConditional generation from heavy chains (heavy -> light):
python github_inference.py \
--heavy_chain_file heavy_chains.txt \
--n_sequences 5 \
--top_p 0.95 \
--temp 1.2 \
--output_file output_from_heavy.txt \
--device cpuConditional generation from light chains (light -> heavy):
python github_inference.py \
--light_chain_file light_chains.txt \
--n_sequences 5 \
--top_p 0.95 \
--temp 1.2 \
--output_file output_from_light.txt \
--device cpuPrompted generation from an initial sequence (prefix with 1):
python github_inference.py \
--initial_sequence 1QVQLVESGGGVVQPGRSLRLSCAASGFTFSSYGMHWVRQAPGKG \
--n_sequences 20 \
--top_p 0.9 \
--temp 1.1 \
--output_file output_prompted.txt \
--device cpuDefault output:
SEQUENCE_1
SEQUENCE_2
SEQUENCE_3
Conditional generation output:
index, generated_sequence
Separate chain output:
VH_SEQUENCE, VL_SEQUENCE
python -c "import torch; import transformers; print('Core dependencies OK')"
python -c "from piggen import utils; print('p-IgGen import OK')"
python github_inference.py --helpANARCI not found
conda install -n piggen_infer -c bioconda anarci -y
# If that fails:
conda run -n piggen_infer pip install anarcihmmscan not found
conda install -n piggen_infer -c bioconda hmmer -y--separate_chains not working
Ensure both ANARCI and HMMER are installed and available in PATH.
Prompted generation returns 0 sequences
Use --initial_sequence with a leading 1 token (for example,
--initial_sequence 1QVQLVES...).
This repository provides local inference for a finetuned version of p-IgGen.
Upstream package: https://github.com/OliverT1/p-IgGen