Skip to main content
AbLang Perplexity
License: AbLang is open source and free for academic and commercial use under a BSD-3-Clause license. Please refer to the license for full terms.

This constraint is open source. Any third-party models, product names, or trademarks referenced are the property of their respective owners, and Proto is not affiliated with them.


Go to Tool Page
proto-bio/proto-language/proto_language/constraint/sequence_scoring/ablang_perplexity_constraint.py
View source
@article{olsen2022ablang,
  title={AbLang: an antibody language model for completing antibody sequences},
  author={Olsen, Tobias H and Moal, Iain H and Deane, Charlotte M},
  journal={Bioinformatics Advances},
  volume={2},
  number={1},
  pages={vbac046},
  year={2022},
  publisher={Oxford University Press},
  doi={10.1093/bioadv/vbac046}
}

@article{olsen2024ablang2,
  title={Addressing the antibody germline bias and its effect on language models for improved antibody design},
  author={Olsen, Tobias H and Moal, Iain H and Deane, Charlotte M},
  journal={Bioinformatics},
  volume={40},
  number={11},
  pages={btae618},
  year={2024},
  publisher={Oxford University Press},
  doi={10.1093/bioinformatics/btae618}
}
Copy citation
Forward AbLang antibody scoring via masked pseudo-log-likelihood. The returned score is raw AbLang mean negative log-likelihood by default, so lower is better and the forward score matches the loss used by ablang_perplexity_gradient_backward. Set score_mode="ppl" to return perplexity instead. Metadata always includes ablang_log_likelihood (sum of per-residue log-likelihoods), ablang_avg_log_likelihood (mean), ablang_nll, ablang_loss, and ablang_perplexity. With no slices, the whole binder is scored as a heavy-only VHH/nanobody. With heavy_slice and light_slice set, the function extracts VH and VL from a single binder Segment and scores them as a paired scFv.

API Reference

ConfigAbLangPerplexityConfig Source
Configuration for AbLang perplexity scoring (forward + gradient).
temperature
number
required
Softmax temperature for AbLang (fixed for this constraint, not varied per optimizer step).
use_ste
boolean
default:"True"
Hard one-hot forward pass with soft-probability gradients.
device
string
default:"cuda"
Device for AbLang execution, e.g. ‘cuda’ or ‘cuda:0’.
heavy_slice
array
VH region (start, end) within the binder; set with light_slice for scFv mode.
light_slice
array
VL region (start, end) within the binder; set with heavy_slice for scFv mode.
score_mode
enum
default:"nll"
Return raw mean NLL by default, or AbLang perplexity when set to ‘ppl’.Options: nll, ppl
logit_scale
number
default:"1.0"
Pre-scale raw logits before AbLang; gradients are scaled back by the same factor.
sequence_bias
SequenceLogitBiasConfig
Declarative sequence-symbol bias (canonical 20-AA protein) added before AbLang.
ReturnsConstraintOutput
Per-proposal AbLang scores with log-likelihood, NLL, loss, and perplexity metadata.

Usage

python
from proto_language.core import Constraint
from proto_language.constraint import ablang_perplexity_constraint, AbLangPerplexityConfig

constraint = Constraint(
    inputs=[segment],
    function=ablang_perplexity_constraint,
    function_config=AbLangPerplexityConfig(
        # Configure parameters here
    ),
)

scores = constraint.evaluate()

Metadata

PropertyValue
Keyablang-perplexity
Functionablang_perplexity_constraint
Categorysequence_scoring
Modedual
Uses GPUTrue
Supported Typesprotein