🧬 AbLang2: Transformer-based Antibody Language Model
This repository provides HuggingFace-compatible 🤗 implementation of the AbLang2 language model for antibodies. The original AbLang2 model was developed by the Oxford Protein Informatics Group (OPIG) and is available at:
Note: Model automatically use GPU when available, otherwise fall back to CPU.
⚙️ Available Utilities
This wrapper translates between HuggingFace's model format and AbLang2's expected input/output structure, making it easy to use AbLang2's powerful antibody analysis tools with model loaded from HuggingFace.
seqcoding: Sequence-level representations (averaged across residues)
likelihood: Raw logits for amino acid prediction at each position
probability: Normalized probabilities for amino acid prediction
pseudo_log_likelihood: Uncertainty scoring with stepwise masking (masks each residue)
confidence: Fast uncertainty scoring (single forward pass, no masking)
restore: Restore masked residues (*) with predicted amino acids
All these utilities work seamlessly with the HuggingFace-loaded model, maintaining the same API as the original AbLang2 implementation.
The AbLang2PairedHuggingFaceAdapter class is a wrapper that lets you use AbLang2 model utilities after loading the model from HuggingFace. This class enables you to:
Access all AbLang2 utilities (seqcoding, rescoding, likelihood, probability, etc.) with the same interface as the original implementation
Work with antibody sequences (heavy and light chains) seamlessly
Maintain compatibility with the original AbLang2 API while leveraging HuggingFace's model loading and caching capabilities
💡 Examples
🔗 AbLang2 (Paired Sequences) - Restore Example
python
1import sys
2import os
3from transformers import AutoModel, AutoTokenizer
4from huggingface_hub import hf_hub_download
56# 1. Load model and tokenizer from Hugging Face Hub7model = AutoModel.from_pretrained("hemantn/ablang2", trust_remote_code=True)8tokenizer = AutoTokenizer.from_pretrained("hemantn/ablang2", trust_remote_code=True)910# 2. Download adapter and add to path11adapter_path = hf_hub_download(repo_id="hemantn/ablang2", filename="adapter.py")12cached_model_dir = os.path.dirname(adapter_path)13sys.path.insert(0, cached_model_dir)14from adapter import AbLang2PairedHuggingFaceAdapter
1516# 3. Create adapter17ablang = AbLang2PairedHuggingFaceAdapter(model=model, tokenizer=tokenizer)1819# 4. Restore masked sequences20masked_seqs =[21['EVQ***SGGEVKKPGASVKVSCRASGYTFRNYGLTWVRQAPGQGLEWMGWISAYNGNTNYAQKFQGRVTLTTDTSTSTAYMELRSLRSDDTAVYFCAR**PGHGAAFMDVWGTGTTVTVSS',22'DIQLTQSPLSLPVTLGQPASISCRSS*SLEASDTNIYLSWFQQRPGQSPRRLIYKI*NRDSGVPDRFSGSGSGTHFTLRISRVEADDVAVYYCMQGTHWPPAFGQGTKVDIK']23]24restored = ablang(masked_seqs, mode='restore')25print(f"Restored sequences: {restored}")
📚 Detailed Usage
For comprehensive examples of all utilities (seqcoding, rescoding, likelihood, probability, pseudo_log_likelihood, confidence, and more), see:
If you use these models in your research, please cite the original AbLang2 paper:
AbLang2:
@article{Olsen2024,
title={Addressing the antibody germline bias and its effect on language models for improved antibody design},
author={Tobias H. Olsen, Iain H. Moal and Charlotte M. Deane},
journal={bioRxiv},
doi={https://doi.org/10.1101/2024.02.02.578678},
year={2024}
}