This model is a fine-tuned version of ESM2-3B for paired antibody sequences (heavy and light chains).
1from transformers import EsmModel, AutoTokenizer
2import torch
3
4# Load model and tokenizer
5model = EsmModel.from_pretrained("NOC-Lab/AbCDR-ESM2")
6tokenizer = AutoTokenizer.from_pretrained("NOC-Lab/AbCDR-ESM2")
7model.eval()
1# Prepare paired sequence
2SEP_TOKEN = "-"
3heavy_chain = (
4 "EVQLVESGGGLVQPGGSLRLSCAASGFTFSSYAMSWVRQAPGKGLEWVAVISYDGSNKYYADSVKGRF"
5 "TISADTSKNTAYLQMNSLRAEDTAVYYCAREGYYGSSYWYFDYWGQGTLVTVSS"
6)
7light_chain = (
8 "DIQMTQSPSSLSASVGDRVTITCRASQSISSYLNWYQQKPGKAPKLLIYAASSLQSGVPSRFSGSGS"
9 "GTDFTLTISSLQPEDFATYYCQQSYSTPLTFGGGTKVEIK"
10)
11paired_sequence = f"{heavy_chain}{SEP_TOKEN}{light_chain}"
12
13# Tokenize
14inputs = tokenizer(paired_sequence, return_tensors="pt", add_special_tokens=True)
15
16# Extract embeddings
17with torch.no_grad():
18 outputs = model(**inputs)
19 embeddings = outputs.last_hidden_state
20
21# Mean pooling
22mask = inputs["attention_mask"].unsqueeze(-1)
23pooled = (embeddings * mask).sum(1) / mask.sum(1)
24
25print(f"Embedding shape: {pooled.shape}") # (1, 2560)
Mahtab Talaei, Kenji C. Walker, Boran Hao, Eliot Jolley, Yeping Jin, Dima Kozakov, John Misasi, Sandor Vajda, Ioannis Ch. Paschalidis, Diane Joseph-McCarthy.
1@article{Talaei2026,
2 author = {Talaei, Mahtab and Walker, Kenji C. and Hao, Boran and Jolley, Eliot and Jin, Yeping and Kozakov, Dima and Misasi, John and Vajda, Sandor and Paschalidis, Ioannis Ch. and Joseph-McCarthy, Diane},
3 title = {Preferential {CDR} masking in paired antibody language models improves binding affinity prediction},
4 journal = {Communications AI \& Computing},
5 volume = {1},
6 pages = {7},
7 year = {2026},
8 doi = {10.1038/s44488-026-00010-2}
9}
This model is released under the MIT License.
1# Option 1: CLI login
2huggingface-cli login
3
4# Option 2: Environment variable
5export HF_TOKEN="your_token_here"