What a protein language model is
A protein is a chain of amino acids, written as a string over a 20-letter alphabet. The chain folds into a shape, and the shape sets what the protein does. A protein language model treats such strings as text. It is trained on sequences alone, with no structures, to fill in residues that have been hidden; to do that across the diversity of natural proteins it has to learn which residues can sit where, and that turns out to encode much of the fold.
The page records ESM-2 35M (33,501,394 parameters counted), an encoder-only transformer, reading human ubiquitin (UniProt P0CG48): 76 residues, 78 tokens with ⟨cls⟩ and ⟨eos⟩. Its vocabulary has 33 tokens: the 20 standard amino acids, codes for rare and ambiguous residues, and special tokens. The model runs three passes, one with the sequence unmasked for contacts, and one each with residue 44 or residue 48 replaced by ⟨mask⟩.
Masked-residue prediction
ESM-2 is trained like BERT: hide about 15 % of the residues, the set , and predict each hidden one from all the others.
The Masked residue · 20 amino acids panel shows the prediction at the masked position. The last block's output goes through the LM head (LayerNorm, a dense 480 → 480 layer, GELU, LayerNorm) and is scored against the transposed token-embedding matrix plus a bias, giving 33 logits and a softmax.
At Ile 44, the centre of ubiquitin's hydrophobic patch, the model puts 66.0 % on isoleucine, 18.2 % on leucine and 9.3 % on valine. At Lys 48, the lysine that links polyubiquitin chains, it puts 53.1 % on lysine, 22.2 % on arginine and 7.8 % on glutamine. In both cases the native residue comes first, and the runners-up share its chemistry: leucine and valine are hydrophobic like isoleucine, and arginine is positively charged like lysine. The Sequence · 76 residues tiles are coloured by these classes.
ESM-2 also uses token dropout. A ⟨mask⟩ token's embedding is set to zero, and the other embeddings are scaled to make up for the masking rate seen in training. With one mask among 78 tokens the factor is 0.8914, the E · s step of the embedding:
The encoder
The model has 12 blocks of width 480, each pre-LayerNorm, with 20 attention heads of 24 dimensions and an MLP, 480 → 1920 → 480, with exact GELU. Attention is bidirectional: in the Multi-head Self Attention · bidirectional card each softmax row runs over all 78 tokens. No position embedding is added. RoPE (base 10,000) rotates queries and keys, so the score between two residues depends on their offset . ESM-2 multiplies by before the rotation, which gives the same scores as dividing afterwards:
Contacts from attention
Two residues are in contact when they sit close in the folded structure. Here that means their Cβ atoms (Cα for glycine) are less than 8 Å apart in the crystal structure 1UBQ. Rao et al. found that a protein language model's attention maps already point at contacts and that a simple regression over them reads them out. The Contact prediction · unmasked sequence row applies ESM-2's own contact head to the recorded attention.
Each of the 240 maps (12 blocks × 20 heads) has its ⟨cls⟩ and ⟨eos⟩ rows and columns dropped. It is then symmetrised and corrected by the average product correction (APC), which subtracts the part of a pair's score explained by each residue's overall attention. A logistic regression combines all the corrected maps:
The weights were fitted afterwards on contacts from known structures, with the language model frozen; the model itself never sees a structure. The fit is sparse. The Attention maps · 12 blocks × 20 heads grid shows 61 of the 240 weights nonzero, and block 12's head 14 alone carries 34 % of the contribution; its top 76 pairs touch 64.5 % of the time on their own.
Together the heads reach 65.8 % for the top 76 pairs (76 = , the sequence length) at sequence separation : 50 hits and 26 misses against the True contacts · PDB 1UBQ map. Some misses are near: the most confident pair, V5–V26, is 8.35 Å apart, just past the cut-off. For pairs at least 24 residues apart, the ones that matter most for the fold, the manifest records 44.7 % for the top and 73.3 % for the top .
Why attention learns contacts
Residues in contact constrain each other over evolution. When one mutates, the other often changes to keep the fit, so in an alignment of related sequences their columns vary together. Classical contact prediction measured that covariation across a multiple sequence alignment. APC comes from that work: Dunn, Wahl and Gloor used it to remove the background that phylogeny and entropy add to the mutual information between columns.
A masked language model trained across many protein families must model the same dependencies to predict a hidden residue. It does so from a single sequence, with no alignment, and its attention heads end up linking the residues that coevolve.
Where protein language models came from
Rives et al. trained a transformer on 250 million protein sequences (ESM-1b) and found secondary structure, contacts and mutational effects in its representations. Rao et al. then showed that attention maps alone, read by a sparse regression, beat a state-of-the-art unsupervised contact pipeline built on alignments. Vig et al. traced which heads attend to contacts and binding sites. ESM-2 (Lin et al.) moved to rotary positions and scaled the family from 8 million to 15 billion parameters; structure emerges in its representations at atomic resolution, the basis of the ESMFold predictor. This page uses the 35M model.
The objective is BERT's, as on the Encoder tab (ModernBERT); the Diffusion LM tab turns the same masked prediction into a generator.
Papers
- Evolutionary-scale prediction of atomic-level protein structure with a language model ESM-2, the model this page records, and ESMFold, which predicts structure from its representations.
- Transformer protein language models are unsupervised structure learners Contacts from attention maps with APC and a sparse logistic regression, the contact head on this page.
- Biological structure and function emerge from scaling unsupervised learning to 250 million protein sequences ESM-1b: masked language modelling on protein sequences, and what its representations learn about structure and function.
- Mutual information without the influence of phylogeny or entropy dramatically improves residue contact prediction The average product correction, from contact prediction on sequence alignments.
- BERTology Meets Biology: Interpreting Attention in Protein Language Models Which attention heads of protein language models follow contacts and binding sites, layer by layer.
- BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding The masked-language-modelling objective ESM-2 is trained with.
- RoFormer: Enhanced Transformer with Rotary Position Embedding Rotary position embeddings, which ESM-2 uses in place of ESM-1b's learned positions.