Downloads Β· 30 days
41
29% of all-time downloads
aaronkollasch/ablang2
ablang2 is a fill-mask model from aaronkollasch. Use it when you need the model to fill a missing word. It is set up for transformers. The card lists the license as mit.
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β¦
Downloads Β· 30 days
41
29% of all-time downloads
All-time downloads
140
Public
Repo size
179 MB
Likes
0
Public
Click a slice to open those files.
.pt179 MB Β· 100%
From the Hugging Face model README
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:
Install the required dependencies:
# Install core dependencies
pip install transformers numpy pandas rotary-embedding-torch
# Install ANARCI from bioconda (required for antibody numbering)
conda install -c bioconda anarci
Note: ANARCI is required for antibody sequence numbering and alignment features. It must be installed from the bioconda channel.
import sys
import os
from transformers import AutoModel, AutoTokenizer
from huggingface_hub import hf_hub_download
# Load model and tokenizer from Hugging Face Hub
model = AutoModel.from_pretrained("hemantn/ablang2", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("hemantn/ablang2", trust_remote_code=True)
# Download adapter and add to path
adapter_path = hf_hub_download(repo_id="hemantn/ablang2", filename="adapter.py")
cached_model_dir = os.path.dirname(adapter_path)
sys.path.insert(0, cached_model_dir)
# Import and create the adapter
from adapter import AbLang2PairedHuggingFaceAdapter
ablang = AbLang2PairedHuggingFaceAdapter(model=model, tokenizer=tokenizer)
import importlib.util
from transformers import AutoModel, AutoTokenizer
from huggingface_hub import hf_hub_download
# Load model and tokenizer
model = AutoModel.from_pretrained("hemantn/ablang2", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("hemantn/ablang2", trust_remote_code=True)
# Load adapter dynamically
adapter_path = hf_hub_download(repo_id="hemantn/ablang2", filename="adapter.py")
spec = importlib.util.spec_from_file_location("adapter", adapter_path)
adapter_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(adapter_module)
# Create the adapter
ablang = adapter_module.AbLang2PairedHuggingFaceAdapter(model=model, tokenizer=tokenizer)
Note: Model automatically use GPU when available, otherwise fall back to CPU.
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.
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:
import sys
import os
from transformers import AutoModel, AutoTokenizer
from huggingface_hub import hf_hub_download
# 1. Load model and tokenizer from Hugging Face Hub
model = AutoModel.from_pretrained("hemantn/ablang2", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("hemantn/ablang2", trust_remote_code=True)
# 2. Download adapter and add to path
adapter_path = hf_hub_download(repo_id="hemantn/ablang2", filename="adapter.py")
cached_model_dir = os.path.dirname(adapter_path)
sys.path.insert(0, cached_model_dir)
from adapter import AbLang2PairedHuggingFaceAdapter
# 3. Create adapter
ablang = AbLang2PairedHuggingFaceAdapter(model=model, tokenizer=tokenizer)
# 4. Restore masked sequences
masked_seqs = [
['EVQ***SGGEVKKPGASVKVSCRASGYTFRNYGLTWVRQAPGQGLEWMGWISAYNGNTNYAQKFQGRVTLTTDTSTSTAYMELRSLRSDDTAVYFCAR**PGHGAAFMDVWGTGTTVTVSS',
'DIQLTQSPLSLPVTLGQPASISCRSS*SLEASDTNIYLSWFQQRPGQSPRRLIYKI*NRDSGVPDRFSGSGSGTHFTLRISRVEADDVAVYYCMQGTHWPPAFGQGTKVDIK']
]
restored = ablang(masked_seqs, mode='restore')
print(f"Restored sequences: {restored}")
For comprehensive examples of all utilities (seqcoding, rescoding, likelihood, probability, pseudo_log_likelihood, confidence, and more), see:
test_ablang2_HF_implementation.ipynb - Complete notebook with all utilities and advanced usage patternsIf 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}
}