Views
No views yet
Contrastive Learning Enables Epitope Overlap Predictions for Targeted Antibody Discovery. [bioRxiv], Clinton M. Holt, Alexis K. Janke, Parastoo Amlashi, Parker J. Jamieson, Toma M. Marinov, Ivelin S. Georgiev. 2025. https://doi.org/10.1101/2025.02.25.640114
AbLangPDB1 model uses the AbLangPaired architecture, a custom class that processes heavy and light chains of antibodies independently using the pre-trained AbLang models before fusing their embeddings together. The resulting embeddings from the two AbLang models are concatenated and passed through a custom Mixer network (6 fully connected feed forward layers) to produce a final, unified 1536-dimensional embedding for the paired antibody.1# Clone the repository to get the model script, weights, and tokenizers
2git clone https://huggingface.co/clint-holt/AbLangPDB1
3cd AbLangPDB1
4
5# Install dependencies
6pip install torch pandas "transformers>=4.30.0" safetensors1
2import torch
3import pandas as pd
4from transformers import AutoTokenizer
5
6# Import the custom model class and config from the cloned repository
7from ablangpaired_model import AbLangPaired, AbLangPairedConfig
8
9# 1. Load Model and Tokenizers
10device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
11model_dir = "." # Assumes you are running this script from the cloned directory
12
13# Configure the model to load the local weights
14# The AbLangPairedConfig specifies the base AbLang models and the local checkpoint file
15model_config = AbLangPairedConfig(checkpoint_filename=f"{model_dir}/ablangpdb_model.safetensors")
16model = AbLangPaired(model_config, device).to(device)
17model.eval()
18
19# Tokenizers are stored in subdirectories
20heavy_tokenizer = AutoTokenizer.from_pretrained(f"{model_dir}/heavy_tokenizer")
21light_tokenizer = AutoTokenizer.from_pretrained(f"{model_dir}/light_tokenizer")
22
23# 2. Prepare Antibody Sequences
24data = {
25 'HC_AA': ["EVQLVESGGGLVQPGGSLRLSCAASGFNLYYYSIHWVRQAPGKGLEWVASISPYSSSTSYADSVKGRFTISADTSKNTAYLQMNSLRAEDTAVYYCARGRWYRRALDYWGQGTLVTVSS"],
26 'LC_AA': ["DIQMTQSPSSLSASVGDRVTITCRASQSVSSAVAWYQQKPGKAPKLLIYSASSLYSGVPSRFSGSRSGTDFTLTISSLQPEDFATYYCQQYPYYSSLITFGQGTKVEIK"]
27}
28df = pd.DataFrame(data)
29
30# Pre-process sequences by adding spaces between amino acids
31df["PREPARED_HC_SEQ"] = df["HC_AA"].apply(lambda x: " ".join(list(x)))
32df["PREPARED_LC_SEQ"] = df["LC_AA"].apply(lambda x: " ".join(list(x)))
33
34# 3. Tokenize and Embed
35h_tokens = heavy_tokenizer(df["PREPARED_HC_SEQ"].tolist(), padding='longest', return_tensors="pt")
36l_tokens = light_tokenizer(df["PREPARED_LC_SEQ"].tolist(), padding='longest', return_tensors="pt")
37
38with torch.no_grad():
39 embeddings = model(
40 h_input_ids=h_tokens['input_ids'].to(device),
41 h_attention_mask=h_tokens['attention_mask'].to(device),
42 l_input_ids=l_tokens['input_ids'].to(device),
43 l_attention_mask=l_tokens['attention_mask'].to(device)
44 )
45
46print("Embedding generation complete! ✅")
47print("Shape of embeddings tensor:", embeddings.shape)
48# Expected output shape: (1, 1536)1
2@article {Holt2025.02.25.640114,
3 author = {Holt, Clinton M. and Janke, Alexis K. and Amlashi, Parastoo and Jamieson, Parker J. and Marinov, Toma M. and Georgiev, Ivelin S.},
4 title = {Contrastive Learning Enables Epitope Overlap Predictions for Targeted Antibody Discovery},
5 elocation-id = {2025.02.25.640114},
6 year = {2025},
7 doi = {10.1101/2025.02.25.640114},
8 publisher = {Cold Spring Harbor Laboratory},
9 URL = {https://www.biorxiv.org/content/early/2025/04/01/2025.02.25.640114},
10 eprint = {https://www.biorxiv.org/content/early/2025/04/01/2025.02.25.640114.full.pdf},
11 journal = {bioRxiv}
12
13}
14