Behind the paper

H3BERTa

Reading the immune system's most creative region — one antibody loop at a time.

H3BERTa

CDR-H3 · masked language modeling

ARD RS [MASK] GGY FDY

A masked language model on antibody sequences: H3BERTa learns to predict a hidden residue from its context — and, in doing so, learns the grammar of the CDR-H3.

Patterns (Cell Press) bioRxiv DOI Zenodo DOI Hugging Face model

~18M
CDR-H3 sequences (OAS, IgG/IgA)
~86M
parameters (RoBERTa encoder)
CDR-H3 only
no framework, no full variable region

H3BERTa is a protein language model trained on one short loop: the antibody heavy-chain CDR-H3. We asked whether that single hypervariable fragment carries enough biological signal to make sense of entire immune repertoires — and found that it does, all the way down to telling healthy donors apart from people fighting HIV-1.

The question

What if one tiny loop could tell the story of an immune response?

Your body is constantly writing an enormous library of antibodies. Modern sequencing can read millions of antibody sequences from a single donor — but the overwhelming majority bind nothing useful, and the rare, valuable ones are buried in the noise. Among the rarest and most prized are broadly neutralizing antibodies (bnAbs): the antibodies that recognize conserved features across many viral strains, and that we'd love to find for pathogens like HIV-1.

Most machine-learning models read the entire variable region of an antibody. That sounds thorough, but it comes with a cost: the variable region is mostly conserved framework scaffolding, which dilutes the functional signal, demands a lot of labeled data, and burns computation learning patterns that aren't where the action is.

We took the opposite bet. What if we ignored almost everything, and looked only at the part of the antibody that actually does the improvising?

The model

A language model that reads only the CDR-H3

The heavy-chain Complementarity-Determining Region 3 (CDR-H3) is the most variable segment of an antibody — the loop that contributes most to antigen specificity and carries the fingerprints of immune selection, clonal expansion, and somatic mutation. It is, in a sense, the creative core of the antibody.

So we built H3BERTa, a transformer language model that reads only the CDR-H3 — the way an NLP model reads a sentence, but here the "sentence" is a string of amino acids:

The H3BERTa framework: pre-training on CDR-H3 loops and semi-supervised bnAb classification with GAN-H3BERTa.
The H3BERTa framework. (A) Pre-training on CDR-H3 loops from OAS via masked language modeling. (B) Semi-supervised bnAb classification with GAN-H3BERTa: a generator and discriminator are trained jointly to separate broadly neutralizing from non-neutralizing antibodies.

The evidence

Does a short loop really encode the biology? Three tests.

To find out whether CDR-H3 alone is "enough," we compared H3BERTa to AntiBERTa, a model trained on the full variable region — and probed what each had learned.

UMAP and LDA projections of H3BERTa and AntiBERTa embeddings.
H3BERTa vs. AntiBERTa embeddings. UMAP projections colored by (A) J-gene and (B) V-gene usage; (C) therapeutic antibodies by species of origin; (D) LDA separation of naive vs. memory B cells.

That last tool turned out to be the most interesting.

The signal

Telling healthy and HIV-1 repertoires apart — in the tails

We computed pseudo-perplexity across CDR-H3 repertoires from 42 healthy donors and 46 HIV-1 bnAb donors. At first glance the distributions looked almost identical. But comparing their shapes with Wasserstein (Earth Mover's) distances and hierarchical clustering revealed a systematic separation between the two groups — and the differences lived in the distributional tails, not the bulk (confirmed by KS and Mann–Whitney tests, all p < 0.001).

The tails were also biochemically interpretable: low-perplexity CDR-H3s tended to be longer and tyrosine-rich (features linked to affinity maturation), while high-perplexity loops were shorter and leucine-rich, with systematic shifts in net charge. H3BERTa, in other words, isn't just counting letters — it's picking up the biophysics of immune history.

Pseudo-perplexity landscape of antibody repertoires quantified with H3BERTa.
Pseudo-perplexity landscape. (A) Hierarchical clustering of donor repertoires by pairwise Wasserstein distance between their PPL distributions (green: healthy; blue: bnAb donors). (B, C) Amino-acid composition and CDR-H3 length across low-, central-, and high-PPL bins.

The application

From repertoires to single antibodies: finding bnAbs

Repertoire-level signal is nice, but can the embeddings flag an individual broadly neutralizing antibody? We built a balanced, deliberately hard labeled set (bnAbs from the CATNAP HIV database; non-neutralizers padded with "hard negatives" — healthy-donor loops that look deceptively bnAb-like).

Decision boundaries of SVM and GAN-H3BERTa classifiers and repertoire projection.
Finding bnAbs. Decision boundaries of SVM classifiers on (A) H3BERTa and (B) GAN-H3BERTa embeddings; (C) projection of a neutralizing donor's repertoire, split by predicted low vs. high neutralization score.

Try it

Run H3BERTa on your own CDR-H3 sequences

H3BERTa is on the Hugging Face Hub as Chrode/H3BERTa. Provide CDR-H3 loops as plain amino-acid strings (no leading C / trailing W, no separators).

Extract per-sequence embeddings (for clustering, similarity search, or a downstream classifier):

embeddings.py

from transformers import pipeline
import torch, numpy as np

feat = pipeline(
    task="feature-extraction",
    model="Chrode/H3BERTa",
    tokenizer="Chrode/H3BERTa",
    device=0 if torch.cuda.is_available() else -1,
)

seqs = ["ARMGAAREWDFQY", "ARDGLGEVAPDYRYGIDV"]

with torch.no_grad():
    outs = feat(seqs)

# Mean pooling across tokens -> per-sequence embedding
embs = [np.array(o).mean(axis=0) for o in outs]
print(len(embs), embs[0].shape)

Score mutations with masked-language modeling (pseudo-likelihood of a residue in context):

mutation_scoring.py

from transformers import pipeline, AutoTokenizer

model_id = "Chrode/H3BERTa"
tok = AutoTokenizer.from_pretrained(model_id)

mlm = pipeline(task="fill-mask", model=model_id, tokenizer=tok, device=0)

seq = "ARDRS[MASK]GGYFDY".replace("[MASK]", tok.mask_token)
for p in mlm(seq, top_k=10):
    print(p["token_str"], round(p["score"], 4))

What's next

You don't always need the whole antibody to read the immune system

H3BERTa makes a simple but useful point: a focused model on the hypervariable CDR-H3 captures germline structure, maturation state, and subtle disease-associated signatures — and stays light enough to run in data-scarce settings, where full-length sequences or abundant labels simply aren't available.

Next steps include testing H3BERTa across broader datasets and disease contexts, pushing toward direct prediction of antigen specificity and neutralization breadth from sequence, and sharpening the GAN-BERT framework to pull rare, therapeutically relevant antibodies out of large repertoires — toward a compact, practical tool for antibody discovery, vaccine design, and longitudinal immune monitoring.